truncate table context menu #333

This commit is contained in:
Jan Prochazka 2022-09-22 16:01:52 +02:00
parent 41afd177ef
commit 59efdd735c
4 changed files with 35 additions and 3 deletions

View File

@ -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) {

View File

@ -17,6 +17,7 @@ export interface SqlDumper extends AlterProcessor {
endCommand();
allowIdentityInsert(table: NamedObjectInfo, allow: boolean);
truncateTable(table: NamedObjectInfo);
beginTransaction();
commitTransaction();
}

View File

@ -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) => {

View File

@ -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;