MCPcopy Index your code
hub / github.com/simstudioai/sim / executeInsert

Function executeInsert

apps/sim/app/api/tools/postgresql/utils.ts:135–154  ·  view source on GitHub ↗
(
  sql: any,
  table: string,
  data: Record<string, unknown>
)

Source from the content-addressed store, hash-verified

133}
134
135export async function executeInsert(
136 sql: any,
137 table: string,
138 data: Record<string, unknown>
139): Promise<{ rows: unknown[]; rowCount: number }> {
140 const sanitizedTable = sanitizeIdentifier(table)
141 const columns = Object.keys(data)
142 const sanitizedColumns = columns.map((col) => sanitizeIdentifier(col))
143 const placeholders = columns.map((_, index) => `$${index + 1}`)
144 const values = columns.map((col) => data[col])
145
146 const query = `INSERT INTO ${sanitizedTable} (${sanitizedColumns.join(', ')}) VALUES (${placeholders.join(', ')}) RETURNING *`
147 const result = await sql.unsafe(query, values)
148
149 const rowCount = result.count ?? result.length ?? 0
150 return {
151 rows: Array.isArray(result) ? result : [result],
152 rowCount,
153 }
154}
155
156export async function executeUpdate(
157 sql: any,

Callers 1

route.tsFile · 0.90

Calls 3

joinMethod · 0.80
sanitizeIdentifierFunction · 0.70
unsafeMethod · 0.65

Tested by

no test coverage detected