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

Function generateSimpleInsertStatement

frontend/src/utils/v1/sql.ts:214–235  ·  view source on GitHub ↗
(
  engine: Engine,
  schema: string,
  table: string,
  columns: string[]
)

Source from the content-addressed store, hash-verified

212};
213
214export const generateSimpleInsertStatement = (
215 engine: Engine,
216 schema: string,
217 table: string,
218 columns: string[]
219) => {
220 if (engine === Engine.MONGODB) {
221 const kvPairs = columns
222 .map((column, i) => `"${column}": <value${i + 1}>`)
223 .join(", ");
224 return `db["${escapeMongoDBCollectionName(table)}"].insert({ ${kvPairs} });`;
225 }
226
227 const schemaAndTable = generateSchemaAndTableNameInSQL(engine, schema, table);
228
229 const columnNames = columns
230 .map((column) => wrapSQLIdentifier(column, engine))
231 .join(", ");
232 const placeholders = columns.map((_) => "?").join(", ");
233
234 return `INSERT INTO ${schemaAndTable} (${columnNames}) VALUES (${placeholders});`;
235};
236
237// MySQL-family engines use backtick identifiers, treat backslash as an escape
238// character inside string literals, and render booleans as 1/0.

Callers 1

useSchemaPaneContextMenuFunction · 0.90

Calls 3

wrapSQLIdentifierFunction · 0.85

Tested by

no test coverage detected