mirror of
https://github.com/drawdb-io/drawdb.git
synced 2026-02-11 02:00:37 +08:00
Handle check expressions
This commit is contained in:
@@ -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,
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user