From 2751a6d6df124a9c3e973c2196d0eeefadef1bcf Mon Sep 17 00:00:00 2001 From: 1ilit Date: Wed, 24 Apr 2024 11:49:00 +0300 Subject: [PATCH] Take in functions as defaults --- src/utils/issues.js | 4 +++- src/utils/toSQL.js | 4 ++-- src/utils/utils.js | 4 ++++ 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/utils/issues.js b/src/utils/issues.js index 56f3c19..6a7dbcf 100644 --- a/src/utils/issues.js +++ b/src/utils/issues.js @@ -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": diff --git a/src/utils/toSQL.js b/src/utils/toSQL.js index 28bb4db..bd2904f 100644 --- a/src/utils/toSQL.js +++ b/src/utils/toSQL.js @@ -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; } diff --git a/src/utils/utils.js b/src/utils/utils.js index 53226a6..cafca7c 100644 --- a/src/utils/utils.js +++ b/src/utils/utils.js @@ -24,3 +24,7 @@ export function strHasQuotes(str) { (str[0] === str[str.length - 1] && str[0] === "`") ); } + +export function isFunction(str) { + return /\w+\([^)]*\)$/.test(str); +}