mirror of
https://github.com/dbgate/dbgate
synced 2024-11-07 20:26:23 +00:00
truncate table context menu #333
This commit is contained in:
parent
41afd177ef
commit
59efdd735c
@ -527,7 +527,7 @@ export class SqlDumper implements AlterProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
truncateTable(name: NamedObjectInfo) {
|
truncateTable(name: NamedObjectInfo) {
|
||||||
this.putCmd('^delete ^from %f', name);
|
this.putCmd('^truncate ^table %f', name);
|
||||||
}
|
}
|
||||||
|
|
||||||
dropConstraints(table: TableInfo, dropReferences = false) {
|
dropConstraints(table: TableInfo, dropReferences = false) {
|
||||||
|
1
packages/types/dumper.d.ts
vendored
1
packages/types/dumper.d.ts
vendored
@ -17,6 +17,7 @@ export interface SqlDumper extends AlterProcessor {
|
|||||||
|
|
||||||
endCommand();
|
endCommand();
|
||||||
allowIdentityInsert(table: NamedObjectInfo, allow: boolean);
|
allowIdentityInsert(table: NamedObjectInfo, allow: boolean);
|
||||||
|
truncateTable(table: NamedObjectInfo);
|
||||||
beginTransaction();
|
beginTransaction();
|
||||||
commitTransaction();
|
commitTransaction();
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,14 @@
|
|||||||
<script lang="ts" context="module">
|
<script lang="ts" context="module">
|
||||||
export const extractKey = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName);
|
export const extractKey = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName);
|
||||||
export const createMatcher = ({ schemaName, pureName, columns }) => filter =>
|
export const createMatcher =
|
||||||
filterName(filter, pureName, schemaName, ...(columns?.map(({ columnName }) => ({ childName: columnName })) || []));
|
({ schemaName, pureName, columns }) =>
|
||||||
|
filter =>
|
||||||
|
filterName(
|
||||||
|
filter,
|
||||||
|
pureName,
|
||||||
|
schemaName,
|
||||||
|
...(columns?.map(({ columnName }) => ({ childName: columnName })) || [])
|
||||||
|
);
|
||||||
export const createTitle = ({ pureName }) => pureName;
|
export const createTitle = ({ pureName }) => pureName;
|
||||||
|
|
||||||
export const databaseObjectIcons = {
|
export const databaseObjectIcons = {
|
||||||
@ -63,6 +70,11 @@
|
|||||||
isRename: true,
|
isRename: true,
|
||||||
requiresWriteAccess: true,
|
requiresWriteAccess: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
label: 'Truncate table',
|
||||||
|
isTruncate: true,
|
||||||
|
requiresWriteAccess: true,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
label: 'Create table backup',
|
label: 'Create table backup',
|
||||||
isDuplicateTable: true,
|
isDuplicateTable: true,
|
||||||
@ -473,6 +485,21 @@
|
|||||||
x => x.schemaName == data.schemaName && x.pureName == data.pureName
|
x => x.schemaName == data.schemaName && x.pureName == data.pureName
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
} else if (menu.isTruncate) {
|
||||||
|
const { conid, database } = data;
|
||||||
|
const driver = await getDriver();
|
||||||
|
const dmp = driver.createDumper();
|
||||||
|
dmp.truncateTable(data);
|
||||||
|
|
||||||
|
const sql = dmp.s;
|
||||||
|
|
||||||
|
showModal(ConfirmSqlModal, {
|
||||||
|
sql,
|
||||||
|
onConfirm: async () => {
|
||||||
|
saveScriptToDatabase({ conid, database }, sql);
|
||||||
|
},
|
||||||
|
engine: driver.engine,
|
||||||
|
});
|
||||||
} else if (menu.isRename) {
|
} else if (menu.isRename) {
|
||||||
const { conid, database } = data;
|
const { conid, database } = data;
|
||||||
renameDatabaseObjectDialog(conid, database, data.pureName, (db, newName) => {
|
renameDatabaseObjectDialog(conid, database, data.pureName, (db, newName) => {
|
||||||
|
@ -12,6 +12,10 @@ class Dumper extends SqlDumper {
|
|||||||
putByteArrayValue(value) {
|
putByteArrayValue(value) {
|
||||||
this.putRaw(`x'${arrayToHexString(value)}'`);
|
this.putRaw(`x'${arrayToHexString(value)}'`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
truncateTable(name) {
|
||||||
|
this.putCmd('^delete ^from %f', name);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = Dumper;
|
module.exports = Dumper;
|
||||||
|
Loading…
Reference in New Issue
Block a user