Sylphritz
Sylphritz
Explore posts from servers
DTDrizzle Team
Created by Sylphritz on 9/29/2023 in #help
SQLite query returns an incorrect row count in extras
The query below doesn't seem to return the correct count for the number of Posts under a Category. It just counts the whole Posts table instead for some reason.
db.query.categories.findMany({
offset,
limit: perPage,
where: eq(categories.userId, userId),
extras: (category, { sql }) => {
return {
postCount:
sql`(SELECT count(*) from posts WHERE category_id = ${category.id})`.as(
'post_count'
),
}
},
})
db.query.categories.findMany({
offset,
limit: perPage,
where: eq(categories.userId, userId),
extras: (category, { sql }) => {
return {
postCount:
sql`(SELECT count(*) from posts WHERE category_id = ${category.id})`.as(
'post_count'
),
}
},
})
I have 1 post in a category but the count returned from this query is the number of total rows in the Posts table instead and not the count filtered by a category ID.
3 replies
CDCloudflare Developers
Created by Sylphritz on 9/19/2023 in #pages-help
Is there a way to connect to D1 locally in, say, a Nuxt.js app in dev mode?
I tried running wrangler pages dev --proxy [nuxt dev server port] -- pnpm dev but the context.cloudflare and process.env.[DB_BINDING] don't seem to exist when I try to access them in defineEventHandler(). I read the documentation but I'm still not clear on how exactly to approach this. Any guidance or examples would be appreciated. My wrangler.toml has [[d1_databases]] and everything and I'm logged in.
27 replies