Single Selects don't work with JSON fields

Running: - [email protected] (using bun:sqlite) - [email protected] It seems like tables with a text("name", { mode: "json" }) column can only be selected if more than one entry get's selected (e.g. DB.query.Table.findMany().sync() or DB.select().from(Table).all()) If i use .get() or .findFirst() it gives me a error containing this
291 | } else if (is(field, SQL)) {
292 | decoder = field.decoder;
293 | } else {
294 | decoder = field.sql.decoder;
295 | }
296 | result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
^
SyntaxError: JSON Parse error: Unexpected identifier "undefined"
at mapRelationalRow (/Users/xxx/Documents/Privat/tests/drizzle/api/node_modules/drizzle-orm/relations.js:296:61)
at map (:1:21)
at /Users/xxx/Documents/Privat/tests/drizzle/api/node_modules/drizzle-orm/sqlite-core/query-builders/query.js:100:22
at /Users/xxx/Documents/Privat/tests/drizzle/api/src/index.ts:22:9
291 | } else if (is(field, SQL)) {
292 | decoder = field.decoder;
293 | } else {
294 | decoder = field.sql.decoder;
295 | }
296 | result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
^
SyntaxError: JSON Parse error: Unexpected identifier "undefined"
at mapRelationalRow (/Users/xxx/Documents/Privat/tests/drizzle/api/node_modules/drizzle-orm/relations.js:296:61)
at map (:1:21)
at /Users/xxx/Documents/Privat/tests/drizzle/api/node_modules/drizzle-orm/sqlite-core/query-builders/query.js:100:22
at /Users/xxx/Documents/Privat/tests/drizzle/api/src/index.ts:22:9
It looks like this originated from the utils.js file line 28 or relations.js line 296 (basically everytime it hits mapFromDriverValue) This is because for example the code in utils.js
const rawValue = row[columnIndex];
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
const rawValue = row[columnIndex];
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
Results in rawValue being undefined because row is something like
{
"count(*)": 8
}
{
"count(*)": 8
}
Or any other object containing id and other key value columns and the code tries to index this object
3 Replies
deadlinecode
deadlinecodeOP12mo ago
I was able to temporary fix it by doing following: utils.js
const rawValue = row[columnIndex] || Object.values(row)[columnIndex];
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
const rawValue = row[columnIndex] || Object.values(row)[columnIndex];
const value = node[pathChunk] = rawValue === null ? null : decoder.mapFromDriverValue(rawValue);
relations.js
const value = mapColumnValue(row[selectionItemIndex] || Object.values(row)[selectionItemIndex]);
const field = selectionItem.field;
let decoder;
if (is(field, Column)) {
decoder = field;
} else if (is(field, SQL)) {
decoder = field.decoder;
} else {
decoder = field.sql.decoder;
}
result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
const value = mapColumnValue(row[selectionItemIndex] || Object.values(row)[selectionItemIndex]);
const field = selectionItem.field;
let decoder;
if (is(field, Column)) {
decoder = field;
} else if (is(field, SQL)) {
decoder = field.decoder;
} else {
decoder = field.sql.decoder;
}
result[selectionItem.tsKey] = value === null ? null : decoder.mapFromDriverValue(value);
I basically saw that the code tried to index the values so i just converted the single objects to its values so it could get indexed properly
deadlinecode
deadlinecodeOP12mo ago
GitHub
[BUG]: Single Selects don't work with JSON fields with bun:sqlite ·...
What version of drizzle-orm are you using? 0.29.3 What version of drizzle-kit are you using? 0.20.12 Describe the Bug It seems like tables with a text("name", { mode: "json" }) ...
Emerson
Emerson9mo ago
@Andrew Sherman can u help here? I've the same error using [email protected] and [email protected]
Want results from more Discord servers?
Add your server