danfascia
danfascia
DTDrizzle Team
Created by danfascia on 5/22/2024 in #help
Help with conditional parameters in a .where () statement please
Thank you, I ended up with this which is remarkably similar except I use ternaries. Yours is a bit terser
question = await db.select().from(Question)
.where(
and(
(category ? eq(Question.category, category) : undefined),
(difficulty ? eq(Question.difficulty, difficulty) : undefined),
(notUid ? ne(Question.uid, notUid) : undefined)
)
)
.orderBy(sql`RANDOM()`)
.limit(1)
.get()
question = await db.select().from(Question)
.where(
and(
(category ? eq(Question.category, category) : undefined),
(difficulty ? eq(Question.difficulty, difficulty) : undefined),
(notUid ? ne(Question.uid, notUid) : undefined)
)
)
.orderBy(sql`RANDOM()`)
.limit(1)
.get()
4 replies
DTDrizzle Team
Created by danfascia on 5/22/2024 in #help
Help with conditional parameters in a .where () statement please
I think I worked it out, but would appreciate confirmation. I think it needs ternaries with undefined as the null option
4 replies
DTDrizzle Team
Created by danfascia on 5/21/2024 in #help
Selecting a random record (libSQL SQLite)
Great tip
4 replies
DTDrizzle Team
Created by danfascia on 5/21/2024 in #help
Selecting a random record (libSQL SQLite)
Thank you that's perfect and it works!
4 replies