Skip to content

Commit 1cf6d2e

Browse files
committed
DATE and DATETIME are string
1 parent 5d56bed commit 1cf6d2e

File tree

1 file changed

+15
-20
lines changed

1 file changed

+15
-20
lines changed

src/sqlite.js

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,13 @@ export class SQLiteDatabaseClient {
5151
if (!rows.length) throw new Error(`table not found: ${table}`);
5252
return {
5353
type: "object",
54-
properties: Object.fromEntries(rows.map(r => [r.name, sqliteType(r)]))
54+
properties: Object.fromEntries(rows.map(({name, type, notnull}) => {
55+
const t = sqliteType(type);
56+
return [name, {
57+
type: notnull || t === "null" ? t : [t, "null"],
58+
databaseType: type
59+
}];
60+
}))
5561
};
5662
}
5763
}
@@ -65,11 +71,10 @@ Object.defineProperty(SQLiteDatabaseClient.prototype, "dialect", {
6571
});
6672

6773
// https://www.sqlite.org/datatype3.html
68-
function sqliteType({type, notnull}) {
69-
let t;
74+
function sqliteType(type) {
7075
switch (type) {
7176
case "NULL":
72-
return {type: "null"};
77+
return "null";
7378
case "INT":
7479
case "INTEGER":
7580
case "TINYINT":
@@ -79,36 +84,26 @@ function sqliteType({type, notnull}) {
7984
case "UNSIGNED BIG INT":
8085
case "INT2":
8186
case "INT8":
82-
t = "integer";
83-
break;
87+
return "integer";
8488
case "TEXT":
8589
case "CLOB":
86-
t = "string";
87-
break;
90+
return "string";
8891
case "REAL":
8992
case "DOUBLE":
9093
case "DOUBLE PRECISION":
9194
case "FLOAT":
9295
case "NUMERIC":
93-
t = "number";
94-
break;
96+
return "number";
9597
case "BLOB":
96-
t = "buffer";
97-
break;
98+
return "buffer";
9899
case "DATE":
99100
case "DATETIME":
100-
t = "date";
101-
break;
101+
return "string"; // TODO convert strings to Date instances
102102
default:
103-
t = /^(?:(?:(?:VARYING|NATIVE) )?CHARACTER|(?:N|VAR|NVAR)CHAR)\(/.test(type) ? "string"
103+
return /^(?:(?:(?:VARYING|NATIVE) )?CHARACTER|(?:N|VAR|NVAR)CHAR)\(/.test(type) ? "string"
104104
: /^(?:DECIMAL|NUMERIC)\(/.test(type) ? "number"
105105
: "other";
106-
break;
107106
}
108-
return {
109-
type: notnull ? t : [t, "null"],
110-
databaseType: type
111-
};
112107
}
113108

114109
function load(source) {

0 commit comments

Comments
 (0)