Is LIMIT 0 possible?
In drizzle it seems that
limit: 0
is the same as excluding the limit. However, in SQL it normally is supposed to return an empty set.
I had tried this, but it returned all the logs regardless of includeLogs
:
I ended up writing the query like this:
6 Replies
Is this a bug?
Yeah, looks like it's a bug.
https://github.com/drizzle-team/drizzle-orm/blob/ab1cfdf33f27e1df6e2b24b72496cd006daf0def/drizzle-orm/src/pg-core/dialect.ts#L345
It is checking that it's truthy and 0 is not.
GitHub
drizzle-orm/drizzle-orm/src/pg-core/dialect.ts at ab1cfdf33f27e1df6...
Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅 - drizzle-team/drizzle-orm
It's probably not a bug because I would think the recommended way to do this is with a conditional field instead of limit 0.
Like in this example: https://orm.drizzle.team/docs/select#conditional-select
(sorry about the formatting, I'm sure prettier will fix that)
Drizzle ORM - Select
Drizzle ORM is a lightweight and performant TypeScript ORM with developer experience in mind.
That sort of works, but makes a complete mess of the return type.
Or... they could support valid PG SQL syntax
This kind of fixes it, but now I'm resorting to type assertions and giving up type safety.
GitHub
[FEATURE]: Add support for
LIMIT 0
· Issue #2011 · drizzle-team/d...Describe what you want I have a query that will conditionally exclude the relational data by setting the limit to 0. Drizzle treats this as omitting the limit, however in PostgreSQL this should ret...