Skip to content

Free, simple, and intuitive online database diagram editor and SQL generator.

Remove quotes for defaults that are keywords

1ilit583138949bc5
diff --git a/src/utils/toSQL.js b/src/utils/toSQL.js
index bd2904f9..40577ce7 100644
--- a/src/utils/toSQL.js
+++ b/src/utils/toSQL.js
@@ -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) {
diff --git a/src/utils/utils.js b/src/utils/utils.js
index cafca7cf..a51919f2 100644
--- a/src/utils/utils.js
+++ b/src/utils/utils.js
@@ -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);
}