Handle check expressions

This commit is contained in:
1ilit
2023-09-19 15:51:25 +03:00
parent 028e80a487
commit 69aabaefa9
3 changed files with 118 additions and 67 deletions

View File

@@ -99,7 +99,11 @@ function jsonToSQL(obj) {
: `${field.default}`
}`
: ""
}${field.check === "" ? "" : ` CHECK (${field.check})`}`
}${
field.check === "" || !hasCheck(field.type)
? ""
: ` CHECK(${field.check})`
}`
)
.join(",\n")}${
table.fields.filter((f) => f.primary).length > 0
@@ -149,6 +153,21 @@ function hasPrecision(type) {
return ["DOUBLE", "NUMERIC", "DECIMAL"].includes(type);
}
function hasCheck(type) {
return [
"INT",
"SMALLINT",
"BIGINT",
"CHAR",
"VARCHAR",
"FLOAT",
"DECIMAL",
"DOUBLE",
"NUMERIC",
"REAL",
].includes(type);
}
function getSize(type) {
switch (type) {
case "CHAR":
@@ -371,4 +390,5 @@ export {
getSize,
hasPrecision,
validateDateStr,
hasCheck,
};