drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
23.17k stars 564 forks source link

[BUG]:isNotNull doesn't work with and statement that searches for a varchar with - #2790

Open yyaskriloff opened 1 month ago

yyaskriloff commented 1 month ago

What version of drizzle-orm are you using?

0.33.0

What version of drizzle-kit are you using?

0.5.1

Describe the Bug

I'm having this issue when I try to make a query that uses an and statement with eq and isNotNull that when the string I'm using in eq includes - it will return as undefined

export const events = pgTable('events', {
  url: varchar('url', { length: 64 }).primaryKey(),
  activated: date('activated', { mode: 'date' }),
  archiving: boolean('archiving').default(false).notNull(),
})

  const event = await db.query.events.findFirst({
    where: (table, { eq, and, isNotNull }) =>
      and(eq(table.url, eventUrl), isNotNull(table.activated), eq(table.archiving, false)),
  })

when the event url contains - (for example hello-world) event would be undefined but when I go into the db and change the same record and remove the - (to helloworld) and make the the query it would return the event.

to clearify when the url was hello-world eventUrl = "hello-world" and when url was helloworld, eventUrl = "helloworld" so it wasn't that the query just didn't match up. i found when I removed the isNotNull check it would work fine in both situations

Expected behavior

No response

Environment & setup

I'm using the neon driver (@neondatabase/serverless 0.9.4) and nextjs (14.2.4) on a 2019 macbook air

yyaskriloff commented 1 month ago
const queryWithDash = {
  sql: 'select ... from "events" where ("events"."url" = $1 and "events"."activated" is not null and "events"."archiving" = $2) limit $3',
  params: [ 'my-wedding', false, 1 ],
}

const queryWithoutDash = {
  sql: 'select ... from "events" where ("events"."url" = $1 and "events"."activated" is not null and "events"."archiving" = $2) limit $3',
  params: [ 'mywedding', false, 1 ],
}