Same, I use Kysely for building complex query and raw SQL if it’s very simple operations
Same, I use Kysely for building complex query and raw SQL if it’s very simple operations
createDB() function?createDB function messing up something.
env across Worker requests, which is why you receive it in every request.
D1_ERROR: D1 DB is overloaded. Requests queued for too long., stack: Error: D1_ERROR: D1 DB is overloaded. Requests queued for too long.ive seen other people having the same issue on the forum aswell but there seems to be no responsesIt's mentioned many times in the group actually why that is.
INDEXED BY while i read through the sqlite docs to determine what the correct course of action is.ANALYZE and am wondering whether D1 periodically runs PRAGMA optimize. if not, is this something that should be done by us (the users of D1) periodically or after running migrations that would update tables and add/remove indexes?

createDB()createDBenvD1_ERROR: D1 DB is overloaded. Requests queued for too long., stack: Error: D1_ERROR: D1 DB is overloaded. Requests queued for too long.INDEXED BYANALYZEPRAGMA optimizeCREATE TRIGGER deduct_coins_on_consumable
BEFORE INSERT ON ActiveConsumables
BEGIN
UPDATE accounts
SET pseudoCoins = pseudoCoins - (SELECT cost FROM Consumables WHERE id = NEW.consumableId)
WHERE
id = NEW.accountId
AND
pseudoCoins >= (SELECT cost FROM Consumables WHERE id = NEW.consumableId);
SELECT RAISE(ROLLBACK, 'Insufficient coins') WHERE changes() = 0;
ENDexport class Auth {
static initialized = false;
private static instance: ReturnType<typeof betterAuth>;
static async init(c: Context<Env>) {
if (Auth.instance) {
await Auth.getSession(c);
Auth.initialized = true;
return Object.freeze(Auth.instance);
}
Auth.instance = betterAuth({
database: drizzleAdapter(
{
dialect: new D1Dialect({
database: c.env.DB,
}),
},
),
});
Auth.initialized = true;
await Auth.getSession(c);
return Object.freeze(Auth.instance);
}
static async getSession(c: Context) {
const session = await Auth.instance.api.getSession({
headers: c.req.raw.headers,
});
c.set("user", session?.user ?? null);
c.set("session", session?.session ?? null);
return session;
}
static getInstance() {
if (!Auth.instance) {
throw new Error("Auth instance not initialized");
}
return Object.freeze(Auth.instance);
}
}const app = new Hono<Env>();
app.use("*", async (c, next) => {
if (Auth.initialized) return next();
await Auth.init(c);
return next();
});
app.all("/api/**", (c) => Auth.getInstance().handler(c.req.raw));
export default app;
export type ApiRoutes = typeof apiRoutes;