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

Method commitChange

src/database-engines/sqlite-engine.ts:368–419  ·  view source on GitHub ↗
(mutation: SerializedMutation, transaction: SQLiteTransaction)

Source from the content-addressed store, hash-verified

366 }
367
368 async commitChange(mutation: SerializedMutation, transaction: SQLiteTransaction): Promise<void> {
369 try {
370 let db: Database;
371
372 db = transaction.getConnection();
373
374 return new Promise<void>((resolve, reject) => {
375 const { type, table, primaryKeyColumn, primaryKey } = mutation;
376
377 if (type === 'cell-update') {
378 const setClauses: string[] = [];
379 const params: any[] = [];
380
381 setClauses.push(`${this.escapeIdentifier(mutation.column.name)} = ?`);
382 params.push(this.transformValueForSqlite(mutation.newValue));
383
384 // Add primary key value to params
385 params.push(this.transformValueForSqlite(primaryKey));
386
387 const query = `UPDATE ${this.escapeIdentifier(table)}
388 SET ${setClauses.join(', ')}
389 WHERE ${this.escapeIdentifier(primaryKeyColumn)} = ?`;
390
391 db.run(query, params, function (err) {
392 if (err) {
393 reportError(`SQLite update error: ${err}`);
394 reject(err);
395 return;
396 }
397 resolve();
398 });
399 } else if (type === 'row-delete') {
400 const query = `DELETE FROM ${this.escapeIdentifier(table)}
401 WHERE ${this.escapeIdentifier(primaryKeyColumn)} = ?`;
402
403 db.run(query, [this.transformValueForSqlite(primaryKey)], function (err) {
404 if (err) {
405 reportError(`SQLite delete error: ${err}`);
406 reject(err);
407 return;
408 }
409 resolve();
410 });
411 } else {
412 reject(new Error(`Unsupported mutation type: ${type}`));
413 }
414 });
415 } catch (err) {
416 reportError(`SQLite commit change error: ${err}`);
417 throw err;
418 }
419 }
420
421 async raw(code: string): Promise<any> {
422 return this.rawQuery(code)

Callers

nothing calls this directly

Calls 4

escapeIdentifierMethod · 0.95
reportErrorFunction · 0.90
getConnectionMethod · 0.65

Tested by

no test coverage detected