Take in functions as defaults
This commit is contained in:
parent
ca8ee61ee9
commit
2751a6d6df
@ -1,4 +1,4 @@
|
||||
import { strHasQuotes } from "./utils";
|
||||
import { isFunction, strHasQuotes } from "./utils";
|
||||
|
||||
function validateDateStr(str) {
|
||||
return /^(?!0000)(?!00)(?:(?!0000)[0-9]{4}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9]|3[01])|(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-8])|(?:0[13-9]|1[0-2])-(?:29|30)|(?:0[13578]|1[02])-31))$/.test(
|
||||
@ -9,6 +9,8 @@ function validateDateStr(str) {
|
||||
function checkDefault(field) {
|
||||
if (field.default === "") return true;
|
||||
|
||||
if (isFunction(field.default)) return true;
|
||||
|
||||
switch (field.type) {
|
||||
case "INT":
|
||||
case "BIGINT":
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { sqlDataTypes } from "../data/constants";
|
||||
import { strHasQuotes } from "./utils";
|
||||
import { isFunction, strHasQuotes } from "./utils";
|
||||
|
||||
export function getJsonType(f) {
|
||||
if (!sqlDataTypes.includes(f.type)) {
|
||||
@ -144,7 +144,7 @@ export function hasQuotes(type) {
|
||||
}
|
||||
|
||||
export function parseDefault(field) {
|
||||
if (strHasQuotes(field.default)) {
|
||||
if (strHasQuotes(field.default) || isFunction(field.default)) {
|
||||
return field.default;
|
||||
}
|
||||
|
||||
|
@ -24,3 +24,7 @@ export function strHasQuotes(str) {
|
||||
(str[0] === str[str.length - 1] && str[0] === "`")
|
||||
);
|
||||
}
|
||||
|
||||
export function isFunction(str) {
|
||||
return /\w+\([^)]*\)$/.test(str);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user