MCPcopy Create free account
hub / github.com/damms005/devdb-vscode / commitChange

Function commitChange

src/services/sql.ts:69–95  ·  view source on GitHub ↗
(connection: knexlib.Knex | null, serializedMutation: SerializedMutation, transaction?: knexlib.Knex.Transaction, openDelimiter: string = '`')

Source from the content-addressed store, hash-verified

67 },
68
69 async commitChange(connection: knexlib.Knex | null, serializedMutation: SerializedMutation, transaction?: knexlib.Knex.Transaction, openDelimiter: string = '`'): Promise<void> {
70 if (!connection) return;
71
72 const { table, primaryKey, primaryKeyColumn } = serializedMutation;
73 let query = '';
74 let replacements: Record<string, any> = { primaryKey };
75 const closeDelimiter = openDelimiter === '[' ? ']' : openDelimiter;
76
77 const safeTable = sanitizeIdentifier(table, openDelimiter, closeDelimiter);
78 const safePkCol = sanitizeIdentifier(primaryKeyColumn, openDelimiter, closeDelimiter);
79
80 if (serializedMutation.type === 'cell-update') {
81 const { column, newValue } = serializedMutation;
82 const safeColName = sanitizeIdentifier(column.name, openDelimiter, closeDelimiter);
83 query = `UPDATE ${safeTable} SET ${safeColName} = :newValue WHERE ${safePkCol} = :primaryKey`;
84 replacements = { ...replacements, newValue };
85 } else if (serializedMutation.type === 'row-delete') {
86 query = `DELETE FROM ${safeTable} WHERE ${safePkCol} = :primaryKey`;
87 }
88
89 if (transaction) {
90 await transaction.raw(query, replacements);
91 await transaction.commit()
92 } else {
93 await (connection).raw(query, replacements);
94 }
95 }
96}
97
98export function buildWhereClause(engine: DatabaseEngine | SqliteEngine, dialect: KnexClientType | 'sqlite3', whereClause: Record<string, any>, columns: Column[]): WhereEntry[] {

Callers

nothing calls this directly

Calls 3

sanitizeIdentifierFunction · 0.85
rawMethod · 0.80
commitMethod · 0.80

Tested by

no test coverage detected