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
nikiv.dev
nikiv.devOP2y 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
nikiv.dev
nikiv.devOP2y ago
used raw turso queries before with sql
nikiv.dev
nikiv.devOP2y ago
nikiv.dev
nikiv.devOP2y ago
but i don't get why this complains topic is a string
nikiv.dev
nikiv.devOP2y ago
nikiv.dev
nikiv.devOP2y ago
isn't text a string
nikiv.dev
nikiv.devOP2y ago
error is hard to understand
nikiv.dev
nikiv.devOP2y 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
nikiv.dev
nikiv.devOP2y ago
nikiv.dev
nikiv.devOP2y ago
thought multiple where would work like this, why does eq say it accept 1 arg
nikiv.dev
nikiv.devOP2y ago
nikiv.dev
nikiv.devOP2y 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
nikiv.dev
nikiv.devOP2y ago
nikiv.dev
nikiv.devOP2y ago
this makes no sense though like every doc example mentions .execute
nikiv.dev
nikiv.devOP2y ago
but for me it complains
nikiv.dev
nikiv.devOP2y ago
nikiv.dev
nikiv.devOP2y ago
maybe its sqlite related you cant do execute on sqlite

Did you find this page helpful?