drawDB/src/utils/exportSQL/shared.js

29 lines
637 B
JavaScript
Raw Normal View History

2024-08-03 19:22:56 +08:00
import { isFunction, isKeyword, strHasQuotes } from "../utils";
2024-06-10 20:23:57 +08:00
import { DB } from "../../data/constants";
import { dbToTypes } from "../../data/datatypes";
export function parseDefault(field, database = DB.GENERIC) {
if (
strHasQuotes(field.default) ||
isFunction(field.default) ||
isKeyword(field.default) ||
!dbToTypes[database][field.type].hasQuotes
) {
return field.default;
}
return `'${field.default}'`;
}
2024-08-03 19:22:56 +08:00
export function exportFieldComment(comment) {
if (comment === "") {
return "";
}
return comment
.split("\n")
.map((commentLine) => `\t-- ${commentLine}\n`)
.join("");
}