(connection: knexlib.Knex | null, serializedMutation: SerializedMutation, transaction?: knexlib.Knex.Transaction, openDelimiter: string = '`')
| 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 | |
| 98 | export function buildWhereClause(engine: DatabaseEngine | SqliteEngine, dialect: KnexClientType | 'sqlite3', whereClause: Record<string, any>, columns: Column[]): WhereEntry[] { |
nothing calls this directly
no test coverage detected