Simple utilities to define a drizzle-orm condition, without having to import the individual comparator functions. Instead use a single function with logical comparison operators to define the condition.
Warning
This library is a work in progress, and is not yet ready for production use.
Install the package from npm:
npm install drizzle-condition
import { integer, sqliteTable } from "drizzle-orm/sqlite-core";
import { condition } from "drizzle-condition";
const myTable = sqliteTable("my_table", {
id: integer("id"),
});
const myQuery = await myDatabaseConnection.query.myTable.findMany({
// where: and(eq(myTable.id, 1), eq(myTable.name, "John")), <-- drizzle-orm implementation eq, gt, lt, etc
where: condition(myTable.id, "==", 1).and(condition(myTable.name, "==", "John")), // <-- drizzle-condition implementation
});
I enjoy using the mathmatical operator syntax when building queries, much like firebase and other ORMs, and found myself writing helpers in all my projects to write the queries in this format.
Hopefully this library will make it easier for you to write queries this way too.
drizzle-orm | drizzle-condition |
---|---|
eq | condition(table.column, "==", value) |
ne | ⏱️ todo |
gt | ⏱️ todo |
lt | ⏱️ todo |
gte | ⏱️ todo |
lte | ⏱️ todo |
in | ⏱️ todo |
isNull | ⏱️ todo |
isNotNull | ⏱️ todo |
inArray | ⏱️ todo |
notInArray | ⏱️ todo |
exists | ⏱️ todo |
notExists | ⏱️ todo |
between | ⏱️ todo |
notBetween | ⏱️ todo |
like | ⏱️ todo |
notLike | ⏱️ todo |
ilike | ⏱️ todo |
notIlike | ⏱️ todo |
not | ⏱️ todo |
and | condition(table.column, "==", value).and(condition(table.column, "==", value)) |
or | condition(table.column, "==", value).or(condition(table.column, "==", value)) |
arrayContains | ⏱️ todo |
arrayContainedIn | ⏱️ todo |
arrayOverlaps | ⏱️ todo |
Contributions are welcome!
Package manager: bun Test runner: vitest Linter: biome
- Fork the repository
- Install dependencies:
bun install
- Check the project is working:
bun run all
- This runs type checking, building, linting and testing. See the
package.json
for more details.
- This runs type checking, building, linting and testing. See the
Create a pull request to the main
branch from your forked repository.
Thanks goes to these wonderful people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!