Skip to content

Commit

Permalink
Merge pull request #281 from Bit0r/main
Browse files Browse the repository at this point in the history
Refactor date parsing logic and add Vector datatype
  • Loading branch information
1ilit authored Nov 3, 2024
2 parents 317c3cc + 60a9c0d commit 9a9df56
Showing 1 changed file with 68 additions and 12 deletions.
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

0 comments on commit 9a9df56

Please sign in to comment.