MCPcopy Create free account
hub / github.com/electric-sql/electric / applyTableChange

Function applyTableChange

examples/linearlite/server.ts:74–102  ·  view source on GitHub ↗
(
  tableName: `issue` | `comment`,
  change: IssueChange | CommentChange,
  sql: postgres.TransactionSql
)

Source from the content-addressed store, hash-verified

72}
73
74async function applyTableChange(
75 tableName: `issue` | `comment`,
76 change: IssueChange | CommentChange,
77 sql: postgres.TransactionSql
78): Promise<void> {
79 const {
80 id,
81 modified_columns: modified_columns_raw,
82 new: isNew,
83 deleted,
84 } = change
85 const modified_columns = modified_columns_raw as (keyof typeof change)[]
86
87 if (deleted) {
88 await sql`
89 DELETE FROM ${sql(tableName)} WHERE id = ${id}
90 `
91 } else if (isNew) {
92 await sql`
93 INSERT INTO ${sql(tableName)} ${sql(change, `id`, ...modified_columns)}
94 `
95 } else {
96 await sql`
97 UPDATE ${sql(tableName)}
98 SET ${sql(change, ...modified_columns)}
99 WHERE id = ${id}
100 `
101 }
102}

Callers 1

applyChangesFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected