mirror of
https://github.com/t8y2/dbx.git
synced 2026-10-29 08:11:06 +00:00
feat: add execute_batch command for executing multiple SQL statements in a single call
This commit is contained in:
@@ -353,10 +353,12 @@ function deleteSelectedRow() {
|
||||
}
|
||||
|
||||
function escapeVal(v: CellValue): string {
|
||||
if (v === null) return "NULL";
|
||||
if (v === null || v === undefined) return "NULL";
|
||||
if (typeof v === "boolean") return v ? "TRUE" : "FALSE";
|
||||
if (typeof v === "number") return String(v);
|
||||
return `'${String(v).replace(/'/g, "''")}'`;
|
||||
if (typeof v === "number" && Number.isFinite(v)) return String(v);
|
||||
const s = String(v);
|
||||
if (s === "") return "''";
|
||||
return `'${s.replace(/\\/g, "\\\\").replace(/'/g, "''")}'`;
|
||||
}
|
||||
|
||||
function qualifiedTableName(): string {
|
||||
@@ -407,7 +409,15 @@ async function saveChanges() {
|
||||
const stmts = generateSaveStatements();
|
||||
if (stmts.length === 0) return;
|
||||
saveError.value = "";
|
||||
if (props.onExecuteSql) {
|
||||
|
||||
if (props.connectionId && props.database) {
|
||||
try {
|
||||
await api.executeBatch(props.connectionId, props.database, stmts);
|
||||
} catch (e: any) {
|
||||
saveError.value = String(e.message || e);
|
||||
return;
|
||||
}
|
||||
} else if (props.onExecuteSql) {
|
||||
try {
|
||||
for (const sql of stmts) {
|
||||
await props.onExecuteSql(sql);
|
||||
|
||||
@@ -73,6 +73,10 @@ export async function executeQuery(connectionId: string, database: string, sql:
|
||||
return invoke("execute_query", { connectionId, database, sql });
|
||||
}
|
||||
|
||||
export async function executeBatch(connectionId: string, database: string, statements: string[]): Promise<QueryResult> {
|
||||
return invoke("execute_batch", { connectionId, database, statements });
|
||||
}
|
||||
|
||||
export async function listIndexes(connectionId: string, database: string, schema: string, table: string): Promise<IndexInfo[]> {
|
||||
return invoke("list_indexes", { connectionId, database, schema, table });
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user