help with drizzle types not inferred well

async function addTopic(topic: string, content: string, parent?: string) {
try {
let parentId: number | null = null
await db.transaction(async (tx) => {
await tx
.select({ id: topics.id })
.from(topics)
.where({ name: topic, ownerId: 1 })
.all()
})
async function addTopic(topic: string, content: string, parent?: string) {
try {
let parentId: number | null = null
await db.transaction(async (tx) => {
await tx
.select({ id: topics.id })
.from(topics)
.where({ name: topic, ownerId: 1 })
.all()
})
19 Replies
nikivi
nikiviOP2y ago
trying to rewrite this function to use drizzle orm https://github.com/learn-anything/learn-anything/blob/main/db/src/seed.ts#L6
GitHub
learn-anything/db/src/seed.ts at main · learn-anything/learn-anything
Organize world's knowledge, explore connections and curate learning paths - learn-anything/db/src/seed.ts at main · learn-anything/learn-anything
nikivi
nikiviOP2y ago
used raw turso queries before with sql
nikivi
nikiviOP2y ago
nikivi
nikiviOP2y ago
but i don't get why this complains topic is a string
nikivi
nikiviOP2y ago
nikivi
nikiviOP2y ago
isn't text a string
nikivi
nikiviOP2y ago
error is hard to understand
nikivi
nikiviOP2y ago
or wait you don't do where like this fk i wonder is there a tool that turns sql into drizzle probably hard to make
nikivi
nikiviOP2y ago
nikivi
nikiviOP2y ago
thought multiple where would work like this, why does eq say it accept 1 arg
nikivi
nikiviOP2y ago
nikivi
nikiviOP2y ago
makes no sense trying to find doc on how .where are chained
.where(
and(
like(topics.name, ctx.req.param("topic")),
eq(topics.ownerId, parseInt(ctx.req.param("id")))
)
.where(
and(
like(topics.name, ctx.req.param("topic")),
eq(topics.ownerId, parseInt(ctx.req.param("id")))
)
await tx
.select({ id: topics.id })
.from(topics)
.where(and(like(topics.name, topic), eq(topics.ownerId, 1)))
.all()
await tx
.select({ id: topics.id })
.from(topics)
.where(and(like(topics.name, topic), eq(topics.ownerId, 1)))
.all()
ok this should be it
nikivi
nikiviOP2y ago
nikivi
nikiviOP2y ago
this makes no sense though like every doc example mentions .execute
nikivi
nikiviOP2y ago
but for me it complains
nikivi
nikiviOP2y ago
nikivi
nikiviOP2y ago
maybe its sqlite related you cant do execute on sqlite
Want results from more Discord servers?
Add your server