Drizzle Team

DT

Drizzle Team

The official Discord for all Drizzle related projects, such as Drizzle ORM, Drizzle Kit, Drizzle Studio and more!

Join

schema unique case insensitive

Suppose I have a table Clients and I want the name to be unique. But, I want it to be case insensivive, normally I would use COLLATE NOCASE, but I couldn't find how to do that in drizzle. Would love some help please. Using sqlite....

Vercel error when using both PlanetScale and Postgres in the same Next app

I'm using two separate databases for my app. The PlanetScale one is the "main" database, and the Postgres is a self-hosted database. I have separate Drizzle instances and schemas for both. PlanetScale: ```ts // @/lib/server/db/index.ts...

Error when running Migrate on inngest function

await migrate(db, {
migrationsFolder: "./src/db/migrations",
});
await migrate(db, {
migrationsFolder: "./src/db/migrations",
});
...
No description

Drizzle Studio with Safari:

I started up Drizzle Studio and followed the instructions in the right-hand column: ``` brew install mkcert brew install nss mkcert -install...

How to filter null values from json_arrayagg

Hey sry if this is a stupid question, I am still kinda new to more complex sql queries. The problem here is that pictures returns an array of objects that have all properties null. As far as I know this is a correct behaviour for the left join. I just wanted to know how I could filter the null values in a good way. ```tsx ctx.db...

Properly define Created at and updated at columns

How to properly define each of these columns. default now seems to be triggered during insert and update

Dynamic where clause

Hello, I'm attempting to following the documentation here https://orm.drizzle.team/docs/dynamic-query-building to build a dynamic query but I'm getting the following error: Generic type 'PgSelect<TTableName, TSelection, TSelectMode, TNullabilityMap>' requires between 3 and 4 type arguments. My code is: ```...
No description

varchar but cast to typescript enum?

I have the following table: ```ts export const Table = pgTable('table', { ... status: varchar('status', { length: 32 }).notNull(),...

how to use ilike securely?

ilike(table, sql%${userQuery}%) produces the wrong SQL code by adding quotes around the userQuery text. however we can't use sql.raw as it would make this suceptible to sql injection. how can we interpolate user provided for ilike ? Thx

SQLite - one to many relationship, join only returning first match

Hi everyone 🙂 I'm having an issue with my select query using Drizzle + SQLite3. In my DB, a content item can have many content parts. Here's my simplified schema in src/db/schema.ts:...

Explaining the differences between .references() and relations function

Hi I'm a bit unclear in the example why the comments table in this example does not use the .references() function on the author id field. Is this because the .relations() method and relations({one}) are achieveing the same thing but two different approaches? https://orm.drizzle.team/docs/rqb#one-to-many ```...

"table name specified more than once error in relational query

I am facing "table name 'Doctors_Chambers_ChamberAvailabilities_ChamberAvailabilityTimef' specified more than once" error when I add with: { AppointmentBookContactNumbers: true }
No description

Unable to generate migration for sqlite

Hello! After upgrading to drizzle-kit 0.20.2 from 0.19.13 I can't generate migrations anymore. I'm using libsql and the error when running ``` drizzle-kit generate:sqlite --schema=./src/schema/main.ts --out ./drizzle/migrations...

Using cloudflare pages postgres and lucia

Hey all im running into so many issues trying to get this setup, has anyone done this before, i have tried to use createClient, sql and createPool from @vercel/postgres but i cant get it working, does anyone have an example of how do this? i want to use a direct connection to my postgres db...

Is drizzle safe to use in production?

I would like to use drizzle(orm and kit) on new projects. I get confronted with arguments like, is it battle tested, or drizzle is still in beta, or it's new and there might be some hidden bugs that would lead to data loss, like accidentally dropping some columns, tables, etc... I think that time will battle test drizzle,...

Chaining/combining $dynamic query functions

Hi everyone - I'm trying to take advantage of the new dynamic query building feature to simplify the way I query my db for displaying data in a table. I've already implemented a nice helper function to add ORDER BY to a query, e.g: `const result = await withOrderBy(qb, {...

Mapping/Renaming column names for MariaDB when using RETURNING *

I know that RETURNING is not supported for MySQL but MariaDB supports it, so I have tried to "hack" it somehow using custom raw query. I would like to ask: 1) Is it possible to use internal mapper for column names from the schema definition, in order to avoid manually "renaming" them? 2) Is there a better way to write this? My code looks like this:...

Timestamp error when pushing Postgress change with drizzle-kit

Hey, I am always getting the message to truncate databse table timestamp() is used (see CLI screenshot). This is quite bad as the dev database s always getting reset. Migrations work fine thought. Any ides why it is always messing up the timestamp?
No description

db.update fails with undefined 'relation.referencedTable'

Running into a strange undefined error when running db.update on the lone table in my SQLite database. ```javascript app.put("/todos/:id", async (c) => { const { id } = c.req.param();...
No description

Help with query, how to use parent value in where condition ?

Hey everyone, is there any way to pass a value from the parent, which is widgets in this example to a where condition in a left join ? ```ts await db.query.widgets.findFirst({ where: eq(widgets.code, 'widget1'),...