Database query fails over proxy

Hey, first of all, I know this is neither the right channel nor server for this but I am unable to get this fixed and I know there are a lot of competent developers here so I thought I might try my luck here. I am currently trying to use drizzle on durable objects via the drizzle sqlite-proxy adapter. I am running the sql queries on durable object sqlite storage and then returning the rows to drizzle, but I am always running into issues when trying to use json columns. Drizzle will just error out with this:
TypeError: value is not iterable (cannot read property undefined)
at SQLiteBlobJson.mapFromDriverValue (C:/Users/finni/Documents/GitHub/odysseus/workers/odysseus/node_modules/.vite/deps_odysseus/chunk-2PKXMLJU.js:307:30)
TypeError: value is not iterable (cannot read property undefined)
at SQLiteBlobJson.mapFromDriverValue (C:/Users/finni/Documents/GitHub/odysseus/workers/odysseus/node_modules/.vite/deps_odysseus/chunk-2PKXMLJU.js:307:30)
I am returning the data correctly but it just fails parsing any and all json columns. This is my query method:
async query(sqlBody: string, params: any[] = [], method: 'all' | 'first' | 'run' | 'values' | 'get' = 'all') {
console.log('Query method:', method, 'SQL:', sqlBody);

try {
const cursor = this.sql.exec(sqlBody, ...params);
let rows: any[];

if (method === 'first' || method === 'get') {
const row = cursor.one();
rows = row ? [row] : [];
} else {
rows = cursor.toArray();
}

console.log('Query result rows:', rows);

// Debug each row's field values
rows.forEach((row, index) => {
console.log(`Row ${index}:`, row);
Object.entries(row).forEach(([key, value]) => {
console.log(` ${key}: ${value} (type: ${typeof value})`);
});
});

return rows;
} catch (error) {
console.error('Query error:', error);
throw error;
}
async query(sqlBody: string, params: any[] = [], method: 'all' | 'first' | 'run' | 'values' | 'get' = 'all') {
console.log('Query method:', method, 'SQL:', sqlBody);

try {
const cursor = this.sql.exec(sqlBody, ...params);
let rows: any[];

if (method === 'first' || method === 'get') {
const row = cursor.one();
rows = row ? [row] : [];
} else {
rows = cursor.toArray();
}

console.log('Query result rows:', rows);

// Debug each row's field values
rows.forEach((row, index) => {
console.log(`Row ${index}:`, row);
Object.entries(row).forEach(([key, value]) => {
console.log(` ${key}: ${value} (type: ${typeof value})`);
});
});

return rows;
} catch (error) {
console.error('Query error:', error);
throw error;
}
2 Replies
Zetax
ZetaxOP2w ago
and this is my drizzle instance code:
export const getDB = (identifier: string) => {
const db = drizzle(async (sql, params, method) => {
const doId = env.DATABASE_DO.idFromName("test");
const durableObject = env.DATABASE_DO.get(doId);
const rows = await durableObject.query(sql, params, method);
// @ts-ignore
return { rows };
});

return db;
};
export const getDB = (identifier: string) => {
const db = drizzle(async (sql, params, method) => {
const doId = env.DATABASE_DO.idFromName("test");
const durableObject = env.DATABASE_DO.get(doId);
const rows = await durableObject.query(sql, params, method);
// @ts-ignore
return { rows };
});

return db;
};
James
James2w ago
drizzle has bugs, this is not the only one, if it is one i opted to use drizzle just for migrations, raw sql for SCRUD, then manually type cast results using the schema types. Easier than banging my head against the wall with random crap like this

Did you find this page helpful?