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) {
|
||||
this.putCmd('^delete ^from %f', name);
|
||||
this.putCmd('^truncate ^table %f', name);
|
||||
}
|
||||
|
||||
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();
|
||||
allowIdentityInsert(table: NamedObjectInfo, allow: boolean);
|
||||
truncateTable(table: NamedObjectInfo);
|
||||
beginTransaction();
|
||||
commitTransaction();
|
||||
}
|
||||
|
@ -1,7 +1,14 @@
|
||||
<script lang="ts" context="module">
|
||||
export const extractKey = ({ schemaName, pureName }) => (schemaName ? `${schemaName}.${pureName}` : pureName);
|
||||
export const createMatcher = ({ schemaName, pureName, columns }) => filter =>
|
||||
filterName(filter, pureName, schemaName, ...(columns?.map(({ columnName }) => ({ childName: columnName })) || []));
|
||||
export const createMatcher =
|
||||
({ schemaName, pureName, columns }) =>
|
||||
filter =>
|
||||
filterName(
|
||||
filter,
|
||||
pureName,
|
||||
schemaName,
|
||||
...(columns?.map(({ columnName }) => ({ childName: columnName })) || [])
|
||||
);
|
||||
export const createTitle = ({ pureName }) => pureName;
|
||||
|
||||
export const databaseObjectIcons = {
|
||||
@ -63,6 +70,11 @@
|
||||
isRename: true,
|
||||
requiresWriteAccess: true,
|
||||
},
|
||||
{
|
||||
label: 'Truncate table',
|
||||
isTruncate: true,
|
||||
requiresWriteAccess: true,
|
||||
},
|
||||
{
|
||||
label: 'Create table backup',
|
||||
isDuplicateTable: true,
|
||||
@ -473,6 +485,21 @@
|
||||
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) {
|
||||
const { conid, database } = data;
|
||||
renameDatabaseObjectDialog(conid, database, data.pureName, (db, newName) => {
|
||||
|
@ -12,6 +12,10 @@ class Dumper extends SqlDumper {
|
||||
putByteArrayValue(value) {
|
||||
this.putRaw(`x'${arrayToHexString(value)}'`);
|
||||
}
|
||||
|
||||
truncateTable(name) {
|
||||
this.putCmd('^delete ^from %f', name);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Dumper;
|
||||
|
Loading…
Reference in New Issue
Block a user