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>;