Drizzle Team

DT

Drizzle Team

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

Join

branches with neon

I was wondering if anyone is using Neon with drizzle in a production setup. I've got things setup nicely for development using a branch called "dev". What I'm wondering is what is the procedure now that I want to start getting my "main" branch ready. How do I do my migration into this branch given I have a number of migration files that have come along with my development process. I've been looking for some good documentation of going from development to production but I haven't found anything.
I am using Next 13 and deploy to vercel....

exclude models from bundle

Hello! I have a monorepo (turborepo + pnpm workspaces) with packages database, schemas & contracts and apps web(nextjs 13 app) & api(nestjs app). Database package hold all the tables, enums & relations definitions using drizzle-orm. Schemas is using the drizzle-zod to create needed body/query schemas. Contracts are ts-rest contracts shared between FE and BE....
No description

between operator

Hello i have a table where i have 2 columns where i save timestamps (epoch time) as integer. when i try to query it with the between operator i get no response. .where(between(1697013797353, table.startDate, table.endDate))...

Joining multiple instances of same table?

Suppose I have an items table where each item can have up to 3 tags. This is hardcoded - the items table has columns tag1id tag2id and tag3id. I want to find all items that have a given tag. The code below seems to select the proper items but I do not get the tag2 or tag3 properties on the result. Is there something I'm doing wrong, and more generally, is there a better way to achieve this? ```js let t1 = alias(tags, 't1'); let t2 = alias(tags, 't2');...

Cannot join tables where the columns name are the same.

If you do then the join table will overwrite the from table. it is really frustrating

Is the blob type supported for MySQL?

Hi, I'm wondering if the blob type for MySQL is currently supported in drizzle? If not, I was wondering if there are plans to support or if there are workarounds. Thanks.

Pg: Inserting new data with auto increment column

I am getting error while inserting data to postgres from nextjs api. Error: detail: 'Key (id)=(21) already exists.', I have table with three columns and the API is submitting values as name and status. I am guessing postgres would take care of auto increment. what is the issue here ? ``` id: serial('id').primaryKey(), name: varchar('name', { length: 256 }).notNull(),...

Is ilike vulnerable to SQL injections?

Modified from the post: https://orm.drizzle.team/docs/operators#ilike See code below: ```ts import { ilike } from "drizzle-orm";...

Optional fk

Hello, I have an optional fk and I'd like to db.update it to be null (point to nothing). I'm receiving an error while trying to set it to undefined: No values to set . What's the intended way to do it?...

Psql Array of text and `createSelectSchema`, `createInsertSchema`

It seems that drizzle-zod - createInsertSchema and createSelectSchema cannot infer correctly an array of text. My column; ``` colName: text('col_name').array()...

Migration struggled at some snapshot (existed table), Can I skip it?

As my understanding, Drizzle generate each database changes as snapshot. In my case migrate function was struggled at some snapshot with error like TABLE EXISTS cause I manually create/modify that table myself or it was an existed table before I'm using Drizzle. Now any new schemas can't migrate to database due to it's struggled at that snapshot. Can I skip it or anyway to solve this?
No description

`db:push` with `customType` causes data loss

Running db:push consecutively without changing the schema causes alterations and truncation, only for customType columns: You're about to change dollars column type from numeric(16, 2) to numeric(16,2) with 50 items...

Query depth issue Cloudflare D1

I am encountering Expression tree is too large (maximum depth 20) issue mostly with relation queries while using Cloudflare D1. As explained in this issue https://github.com/cloudflare/workers-sdk/issues/4094, this issue is because of the query depth limit set by them which they are considering increasing. My question is, if for now, I were to refactor this query, what would be the most performant way? 1. Using batch 2. Using multiple queries with Promise.all ```...

update incrementing value (postgres)

So, i have a table: ```javascript export const VisitorCount = pgTable('visitor-count', { id: bigserial('id', { mode: 'number' }).primaryKey(), experimentId: bigint('experiment_id', { mode: 'number' }),...

Null fields not working as expected

Hi all, I am using Drizzle ORM with Zod validation for useForm, and I am running into issues with fields that are allowed to be undefined / null, but I get Zod errors stating that the value of the optional fields (when left empty) are invalid_type and in required. I was able to fix this by refining the field as follows: ...

Type Generated from $inferInsert does not change after column type update

I have a table called identities in a schema called identity. When I changed the phone_country_code column type from text to numeric, the sql generated from drizzle-kit was correct, but the type generated from inferInsert still has the old string type. (see attached image). ```typescript // Table definition phoneCountryCode: numeric('phone_country_code').notNull(), ...
No description

Is it possible to use INSERT statements inside a CTE (WITH query) +++ another question?

In PostgreSQL, you're allowed to use other DML statements (e.g., insert, update, delete) inside a CTE. Something like: ```sql WITH moved_rows AS ( DELETE FROM products...

SQL_PARSE_ERROR with Turso + Drizzle

getting
SQL string could not be parsed: near MINUS, "None"
SQL string could not be parsed: near MINUS, "None"
when running a push in development with this schema: ```js import { sqliteTable, text, numeric, uniqueIndex, integer } from 'drizzle-orm/sqlite-core'; import { sql } from 'drizzle-orm';...

onConflictDoNothing is not returning values

Hey, Given the following query: ```javascript...

push:sqlite cannot find module 'better-sqlite3'

im trying to hook up turso wind drizzle, and encounter thi error,
No description