MCPcopy Create free account
hub / github.com/bytebase/bytebase / generateInsertStatementFromRows

Function generateInsertStatementFromRows

frontend/src/utils/v1/sql.ts:324–347  ·  view source on GitHub ↗
(params: {
  engine: Engine;
  schema: string | undefined;
  table: string;
  columns: string[];
  rows: RowValue[][];
})

Source from the content-addressed store, hash-verified

322// the given rows. Each `rows[i]` is the cell array of one result row, aligned
323// with `columns`.
324export const generateInsertStatementFromRows = (params: {
325 engine: Engine;
326 schema: string | undefined;
327 table: string;
328 columns: string[];
329 rows: RowValue[][];
330}): string => {
331 const { engine, schema, table, columns, rows } = params;
332 const schemaAndTable = generateSchemaAndTableNameInSQL(
333 engine,
334 schema ?? "",
335 table
336 );
337 const columnNames = columns
338 .map((column) => wrapSQLIdentifier(column, engine))
339 .join(", ");
340 const valueLines = rows
341 .map(
342 (row) =>
343 ` (${row.map((cell) => rowValueToSQLLiteral(cell, engine)).join(", ")})`
344 )
345 .join(",\n");
346 return `INSERT INTO ${schemaAndTable} (${columnNames}) VALUES\n${valueLines};`;
347};
348
349export const generateSimpleUpdateStatement = (
350 engine: Engine,

Callers 2

formatAsSQLFunction · 0.90
sql.test.tsFile · 0.90

Calls 3

wrapSQLIdentifierFunction · 0.85
rowValueToSQLLiteralFunction · 0.85

Tested by

no test coverage detected