MCPcopy
hub / github.com/drawdb-io/drawdb / jsonToSQLite

Function jsonToSQLite

src/utils/exportSQL/generic.js:402–441  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

400}
401
402export function jsonToSQLite(obj) {
403 return obj.tables
404 .map((table) => {
405 const inlineFK = getInlineFK(table, obj);
406 return `${
407 table.comment === "" ? "" : `/* ${table.comment} */\n`
408 }CREATE TABLE IF NOT EXISTS "${table.name}" (\n${table.fields
409 .map(
410 (field) =>
411 `${field.comment === "" ? "" : `\t-- ${field.comment}\n`}\t"${
412 field.name
413 }" ${getSQLiteType(field)}${field.notNull ? " NOT NULL" : ""}${
414 field.unique ? " UNIQUE" : ""
415 }${field.default !== "" ? ` DEFAULT ${parseDefault(field, obj.database)}` : ""}${
416 field.check === "" ||
417 !dbToTypes[obj.database][field.type].hasCheck
418 ? ""
419 : ` CHECK(${field.check})`
420 }`,
421 )
422 .join(",\n")}${
423 table.fields.filter((f) => f.primary).length > 0
424 ? `,\n\tPRIMARY KEY(${table.fields
425 .filter((f) => f.primary)
426 .map((f) => `"${f.name}"`)
427 .join(", ")})${inlineFK !== "" ? ",\n" : ""}`
428 : ""
429 }${inlineFK}${uniqueConstraintClause(table, (s) => `"${s}"`)}\n);\n${table.indices
430 .map(
431 (i) =>
432 `\nCREATE ${i.unique ? "UNIQUE " : ""}INDEX IF NOT EXISTS "${
433 i.name
434 }"\nON "${table.name}" (${i.fields
435 .map((f) => `"${f}"`)
436 .join(", ")});`,
437 )
438 .join("\n")}`;
439 })
440 .join("\n");
441}
442
443export function jsonToMariaDB(obj) {
444 return `${obj.tables

Callers 1

ControlPanelFunction · 0.90

Calls 4

getInlineFKFunction · 0.90
parseDefaultFunction · 0.90
uniqueConstraintClauseFunction · 0.90
getSQLiteTypeFunction · 0.85

Tested by

no test coverage detected