Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor date parsing logic and add Vector datatype #281

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 68 additions & 12 deletions src/data/datatypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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())
);
},
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
Loading