returning insert values undefined with drizzle http sqlite proxy
Hey, I just ran into an issue while using
This is what my db client looks like: `
And this is what my durable object method looks like:
What am I doing wrong here? The ID field of the "returning" insert query is undefined for some reason even though my durable object method returns it correctly
drizzle-orm/sqlite-proxydrizzle-orm/sqlite-proxy when used with the returning() statement. This is what my db client looks like: `
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 result = await durableObject.query(sql, params, method);
console.log(result);
return { rows: result.rows };
});
return new Proxy(db, {
get(target, prop, receiver) {
const original = Reflect.get(target, prop, receiver);
if (typeof original !== 'function') {
return original;
}
return (...args: any[]) => {
const result = original.apply(target, args);
if (result && typeof result.catch === 'function') {
return result.catch((err: Error) => {
throw new DatabaseError(err.message);
});
}
return result;
};
},
});
};
export type DB = ReturnType<typeof getDB>;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 result = await durableObject.query(sql, params, method);
console.log(result);
return { rows: result.rows };
});
return new Proxy(db, {
get(target, prop, receiver) {
const original = Reflect.get(target, prop, receiver);
if (typeof original !== 'function') {
return original;
}
return (...args: any[]) => {
const result = original.apply(target, args);
if (result && typeof result.catch === 'function') {
return result.catch((err: Error) => {
throw new DatabaseError(err.message);
});
}
return result;
};
},
});
};
export type DB = ReturnType<typeof getDB>;And this is what my durable object method looks like:
async query(sqlBody: string, params: any[] = [], method: 'all' | 'first' | 'run' | 'values' | 'get' = 'all') {
const cursor = this.sql.exec(sqlBody, ...params);
if (method === 'all' || method === 'run' || method === 'values') {
const rows = cursor.toArray();
return { rows };
} else {
const row = cursor.one();
return { rows: row ? [row] : [] };
}
} async query(sqlBody: string, params: any[] = [], method: 'all' | 'first' | 'run' | 'values' | 'get' = 'all') {
const cursor = this.sql.exec(sqlBody, ...params);
if (method === 'all' || method === 'run' || method === 'values') {
const rows = cursor.toArray();
return { rows };
} else {
const row = cursor.one();
return { rows: row ? [row] : [] };
}
}What am I doing wrong here? The ID field of the "returning" insert query is undefined for some reason even though my durable object method returns it correctly