deadlinecode
deadlinecode
Explore posts from servers
DTDrizzle Team
Created by deadlinecode on 1/16/2024 in #help
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
5 replies