Skip to content

Commit 9a9df56

Browse files
authored
Merge pull request #281 from Bit0r/main
Refactor date parsing logic and add Vector datatype
2 parents 317c3cc + 60a9c0d commit 9a9df56

File tree

1 file changed

+68
-12
lines changed

1 file changed

+68
-12
lines changed

src/data/datatypes.js

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ const defaultTypesBase = {
140140
}
141141
const content = field.default.split(" ");
142142
const date = content[0].split("-");
143-
return parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038;
143+
return Number.parseInt(date[0]) >= 1970 && Number.parseInt(date[0]) <= 2038;
144144
},
145145
hasCheck: false,
146146
isSized: false,
@@ -168,7 +168,7 @@ const defaultTypesBase = {
168168
}
169169
const c = field.default.split(" ");
170170
const d = c[0].split("-");
171-
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
171+
return Number.parseInt(d[0]) >= 1000 && Number.parseInt(d[0]) <= 9999;
172172
},
173173
hasCheck: false,
174174
isSized: false,
@@ -405,7 +405,7 @@ const mysqlTypesBase = {
405405
}
406406
const content = field.default.split(" ");
407407
const date = content[0].split("-");
408-
return parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038;
408+
return Number.parseInt(date[0]) >= 1970 && Number.parseInt(date[0]) <= 2038;
409409
},
410410
hasCheck: false,
411411
isSized: false,
@@ -433,7 +433,7 @@ const mysqlTypesBase = {
433433
}
434434
const c = field.default.split(" ");
435435
const d = c[0].split("-");
436-
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
436+
return Number.parseInt(d[0]) >= 1000 && Number.parseInt(d[0]) <= 9999;
437437
},
438438
hasCheck: false,
439439
isSized: false,
@@ -939,7 +939,7 @@ const postgresTypesBase = {
939939
];
940940
return (
941941
/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}$/.test(field.default) ||
942-
(parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038) ||
942+
(Number.parseInt(date[0]) >= 1970 && Number.parseInt(date[0]) <= 2038) ||
943943
specialValues.includes(field.default.toLowerCase())
944944
);
945945
},
@@ -1108,6 +1108,62 @@ const postgresTypesBase = {
11081108
defaultSize: 1,
11091109
hasQuotes: false,
11101110
},
1111+
VECTOR: {
1112+
type: "VECTOR",
1113+
checkDefault: (field) => {
1114+
let elements;
1115+
let elementsStr = field.default;
1116+
try {
1117+
if (strHasQuotes(field.default)) {
1118+
elementsStr = field.default.slice(1, -1);
1119+
}
1120+
elements = JSON.parse(elementsStr);
1121+
return Array.isArray(elements) && elements.length === field.size && elements.every(Number.isFinite);
1122+
} catch (e) {
1123+
return false;
1124+
}
1125+
},
1126+
hasCheck: true,
1127+
isSized: true,
1128+
hasPrecision: false,
1129+
hasQuotes: true,
1130+
},
1131+
HALFVEC:{
1132+
type: "HALFVEC",
1133+
checkDefault: (field) => {
1134+
let elements;
1135+
let elementsStr = field.default;
1136+
try {
1137+
if (strHasQuotes(field.default)) {
1138+
elementsStr = field.default.slice(1, -1);
1139+
}
1140+
elements = JSON.parse(elementsStr);
1141+
return Array.isArray(elements) && elements.length === field.size && elements.every(Number.isFinite);
1142+
} catch (e) {
1143+
return false;
1144+
}
1145+
},
1146+
hasCheck: true,
1147+
isSized: true,
1148+
hasPrecision: false,
1149+
hasQuotes: true,
1150+
},
1151+
SPARSEVEC: {
1152+
type: "SPARSEVEC",
1153+
checkDefault: (field) => {
1154+
let elementsStr = field.default;
1155+
if (strHasQuotes(field.default)) {
1156+
elementsStr = field.default.slice(1, -1);
1157+
}
1158+
const lengthStr = elementsStr.split('/')[1]
1159+
const length = Number.parseInt(lengthStr)
1160+
return length === field.size
1161+
},
1162+
hasCheck: true,
1163+
isSized: true,
1164+
hasPrecision: false,
1165+
hasQuotes: true,
1166+
},
11111167
TSVECTOR: {
11121168
type: "TSVECTOR",
11131169
checkDefault: (field) => /^[A-Za-z0-9: ]*$/.test(field.default),
@@ -1264,7 +1320,7 @@ const sqliteTypesBase = {
12641320
}
12651321
const content = field.default.split(" ");
12661322
const date = content[0].split("-");
1267-
return parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038;
1323+
return Number.parseInt(date[0]) >= 1970 && Number.parseInt(date[0]) <= 2038;
12681324
},
12691325
hasCheck: false,
12701326
isSized: false,
@@ -1292,7 +1348,7 @@ const sqliteTypesBase = {
12921348
}
12931349
const c = field.default.split(" ");
12941350
const d = c[0].split("-");
1295-
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
1351+
return Number.parseInt(d[0]) >= 1000 && Number.parseInt(d[0]) <= 9999;
12961352
},
12971353
hasCheck: false,
12981354
isSized: false,
@@ -1439,7 +1495,7 @@ const mssqlTypesBase = {
14391495
}
14401496
const c = field.default.split(" ");
14411497
const d = c[0].split("-");
1442-
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
1498+
return Number.parseInt(d[0]) >= 1000 && Number.parseInt(d[0]) <= 9999;
14431499
},
14441500
hasCheck: false,
14451501
isSized: false,
@@ -1457,7 +1513,7 @@ const mssqlTypesBase = {
14571513
}
14581514
const c = field.default.split(" ");
14591515
const d = c[0].split("-");
1460-
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
1516+
return Number.parseInt(d[0]) >= 1000 && Number.parseInt(d[0]) <= 9999;
14611517
},
14621518
hasCheck: false,
14631519
isSized: false,
@@ -1479,7 +1535,7 @@ const mssqlTypesBase = {
14791535
}
14801536
const c = field.default.split(" ");
14811537
const d = c[0].split("-");
1482-
return parseInt(d[0]) >= 1000 && parseInt(d[0]) <= 9999;
1538+
return Number.parseInt(d[0]) >= 1000 && Number.parseInt(d[0]) <= 9999;
14831539
},
14841540
hasCheck: false,
14851541
isSized: false,
@@ -1497,7 +1553,7 @@ const mssqlTypesBase = {
14971553
}
14981554
const c = field.default.split(" ");
14991555
const d = c[0].split("-");
1500-
return parseInt(d[0]) >= 1900 && parseInt(d[0]) <= 2079;
1556+
return Number.parseInt(d[0]) >= 1900 && Number.parseInt(d[0]) <= 2079;
15011557
},
15021558
hasCheck: false,
15031559
isSized: false,
@@ -1525,7 +1581,7 @@ const mssqlTypesBase = {
15251581
}
15261582
const content = field.default.split(" ");
15271583
const date = content[0].split("-");
1528-
return parseInt(date[0]) >= 1970 && parseInt(date[0]) <= 2038;
1584+
return Number.parseInt(date[0]) >= 1970 && Number.parseInt(date[0]) <= 2038;
15291585
},
15301586
hasCheck: false,
15311587
isSized: false,

0 commit comments

Comments
 (0)