Merge pull request #281 from Bit0r/main
Refactor date parsing logic and add Vector datatype
This commit is contained in:
commit
9a9df56867
@ -140,7 +140,7 @@ const defaultTypesBase = {
|
||||
}
|
||||
const content = field.default.split(" ");
|
||||
const date = content[0].split("-");
|
||||
return parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038;
|
||||
return Number.parseInt(date[0]) >= 1970 && Number.parseInt(date[0]) <= 2038;
|
||||
},
|
||||
hasCheck: false,
|
||||
isSized: false,
|
||||
@ -168,7 +168,7 @@ const defaultTypesBase = {
|
||||
}
|
||||
const c = field.default.split(" ");
|
||||
const d = c[0].split("-");
|
||||
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
|
||||
return Number.parseInt(d[0]) >= 1000 && Number.parseInt(d[0]) <= 9999;
|
||||
},
|
||||
hasCheck: false,
|
||||
isSized: false,
|
||||
@ -405,7 +405,7 @@ const mysqlTypesBase = {
|
||||
}
|
||||
const content = field.default.split(" ");
|
||||
const date = content[0].split("-");
|
||||
return parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038;
|
||||
return Number.parseInt(date[0]) >= 1970 && Number.parseInt(date[0]) <= 2038;
|
||||
},
|
||||
hasCheck: false,
|
||||
isSized: false,
|
||||
@ -433,7 +433,7 @@ const mysqlTypesBase = {
|
||||
}
|
||||
const c = field.default.split(" ");
|
||||
const d = c[0].split("-");
|
||||
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
|
||||
return Number.parseInt(d[0]) >= 1000 && Number.parseInt(d[0]) <= 9999;
|
||||
},
|
||||
hasCheck: false,
|
||||
isSized: false,
|
||||
@ -939,7 +939,7 @@ const postgresTypesBase = {
|
||||
];
|
||||
return (
|
||||
/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(field.default) ||
|
||||
(parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038) ||
|
||||
(Number.parseInt(date[0]) >= 1970 && Number.parseInt(date[0]) <= 2038) ||
|
||||
specialValues.includes(field.default.toLowerCase())
|
||||
);
|
||||
},
|
||||
@ -1108,6 +1108,62 @@ const postgresTypesBase = {
|
||||
defaultSize: 1,
|
||||
hasQuotes: false,
|
||||
},
|
||||
VECTOR: {
|
||||
type: "VECTOR",
|
||||
checkDefault: (field) => {
|
||||
let elements;
|
||||
let elementsStr = field.default;
|
||||
try {
|
||||
if (strHasQuotes(field.default)) {
|
||||
elementsStr = field.default.slice(1, -1);
|
||||
}
|
||||
elements = JSON.parse(elementsStr);
|
||||
return Array.isArray(elements) && elements.length === field.size && elements.every(Number.isFinite);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
hasCheck: true,
|
||||
isSized: true,
|
||||
hasPrecision: false,
|
||||
hasQuotes: true,
|
||||
},
|
||||
HALFVEC:{
|
||||
type: "HALFVEC",
|
||||
checkDefault: (field) => {
|
||||
let elements;
|
||||
let elementsStr = field.default;
|
||||
try {
|
||||
if (strHasQuotes(field.default)) {
|
||||
elementsStr = field.default.slice(1, -1);
|
||||
}
|
||||
elements = JSON.parse(elementsStr);
|
||||
return Array.isArray(elements) && elements.length === field.size && elements.every(Number.isFinite);
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
},
|
||||
hasCheck: true,
|
||||
isSized: true,
|
||||
hasPrecision: false,
|
||||
hasQuotes: true,
|
||||
},
|
||||
SPARSEVEC: {
|
||||
type: "SPARSEVEC",
|
||||
checkDefault: (field) => {
|
||||
let elementsStr = field.default;
|
||||
if (strHasQuotes(field.default)) {
|
||||
elementsStr = field.default.slice(1, -1);
|
||||
}
|
||||
const lengthStr = elementsStr.split('/')[1]
|
||||
const length = Number.parseInt(lengthStr)
|
||||
return length === field.size
|
||||
},
|
||||
hasCheck: true,
|
||||
isSized: true,
|
||||
hasPrecision: false,
|
||||
hasQuotes: true,
|
||||
},
|
||||
TSVECTOR: {
|
||||
type: "TSVECTOR",
|
||||
checkDefault: (field) => /^[A-Za-z0-9: ]*$/.test(field.default),
|
||||
@ -1264,7 +1320,7 @@ const sqliteTypesBase = {
|
||||
}
|
||||
const content = field.default.split(" ");
|
||||
const date = content[0].split("-");
|
||||
return parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038;
|
||||
return Number.parseInt(date[0]) >= 1970 && Number.parseInt(date[0]) <= 2038;
|
||||
},
|
||||
hasCheck: false,
|
||||
isSized: false,
|
||||
@ -1292,7 +1348,7 @@ const sqliteTypesBase = {
|
||||
}
|
||||
const c = field.default.split(" ");
|
||||
const d = c[0].split("-");
|
||||
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
|
||||
return Number.parseInt(d[0]) >= 1000 && Number.parseInt(d[0]) <= 9999;
|
||||
},
|
||||
hasCheck: false,
|
||||
isSized: false,
|
||||
@ -1439,7 +1495,7 @@ const mssqlTypesBase = {
|
||||
}
|
||||
const c = field.default.split(" ");
|
||||
const d = c[0].split("-");
|
||||
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
|
||||
return Number.parseInt(d[0]) >= 1000 && Number.parseInt(d[0]) <= 9999;
|
||||
},
|
||||
hasCheck: false,
|
||||
isSized: false,
|
||||
@ -1457,7 +1513,7 @@ const mssqlTypesBase = {
|
||||
}
|
||||
const c = field.default.split(" ");
|
||||
const d = c[0].split("-");
|
||||
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
|
||||
return Number.parseInt(d[0]) >= 1000 && Number.parseInt(d[0]) <= 9999;
|
||||
},
|
||||
hasCheck: false,
|
||||
isSized: false,
|
||||
@ -1479,7 +1535,7 @@ const mssqlTypesBase = {
|
||||
}
|
||||
const c = field.default.split(" ");
|
||||
const d = c[0].split("-");
|
||||
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
|
||||
return Number.parseInt(d[0]) >= 1000 && Number.parseInt(d[0]) <= 9999;
|
||||
},
|
||||
hasCheck: false,
|
||||
isSized: false,
|
||||
@ -1497,7 +1553,7 @@ const mssqlTypesBase = {
|
||||
}
|
||||
const c = field.default.split(" ");
|
||||
const d = c[0].split("-");
|
||||
return parseInt(d[0]) >= 1900 && parseInt(d[0]) <= 2079;
|
||||
return Number.parseInt(d[0]) >= 1900 && Number.parseInt(d[0]) <= 2079;
|
||||
},
|
||||
hasCheck: false,
|
||||
isSized: false,
|
||||
@ -1525,7 +1581,7 @@ const mssqlTypesBase = {
|
||||
}
|
||||
const content = field.default.split(" ");
|
||||
const date = content[0].split("-");
|
||||
return parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038;
|
||||
return Number.parseInt(date[0]) >= 1970 && Number.parseInt(date[0]) <= 2038;
|
||||
},
|
||||
hasCheck: false,
|
||||
isSized: false,
|
||||
|
Loading…
Reference in New Issue
Block a user