Remove quotes for defaults that are keywords
This commit is contained in:
parent
2751a6d6df
commit
583138949b
@ -1,5 +1,5 @@
|
||||
import { sqlDataTypes } from "../data/constants";
|
||||
import { isFunction, strHasQuotes } from "./utils";
|
||||
import { isFunction, isKeyword, strHasQuotes } from "./utils";
|
||||
|
||||
export function getJsonType(f) {
|
||||
if (!sqlDataTypes.includes(f.type)) {
|
||||
@ -144,13 +144,16 @@ export function hasQuotes(type) {
|
||||
}
|
||||
|
||||
export function parseDefault(field) {
|
||||
if (strHasQuotes(field.default) || isFunction(field.default)) {
|
||||
if (
|
||||
strHasQuotes(field.default) ||
|
||||
isFunction(field.default) ||
|
||||
isKeyword(field.default) ||
|
||||
!hasQuotes(field.type)
|
||||
) {
|
||||
return field.default;
|
||||
}
|
||||
|
||||
return hasQuotes(field.type) && field.default.toLowerCase() !== "null"
|
||||
? `'${field.default}'`
|
||||
: `${field.default}`;
|
||||
return `'${field.default}'`;
|
||||
}
|
||||
|
||||
export function jsonToMySQL(obj) {
|
||||
|
@ -25,6 +25,12 @@ export function strHasQuotes(str) {
|
||||
);
|
||||
}
|
||||
|
||||
const keywords = ["CURRENT_TIMESTAMP", "NULL"];
|
||||
|
||||
export function isKeyword(str) {
|
||||
return keywords.includes(str.toUpperCase());
|
||||
}
|
||||
|
||||
export function isFunction(str) {
|
||||
return /\w+\([^)]*\)$/.test(str);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user