Drizzle Team

DT

Drizzle Team

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

Join

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

How do you use 128-bit values with varbinary and what is the fastest way to search for rows?

I have been researching the fastest way to insert data into SQL tables, & I'm having a hard time using Drizzle with PlanetScale because PS doesn't support foreign keys; which means that PS is auto-sharded & the autoincrement primary keys are not going to be the same. You don't want to use UUID because 1.) it exposes your MAC address & 2.) the values don't always increase, i.e. non-monotonic. The current industry choice is ULID, which uses a 128-bit pattern where you take the JS new Date().getTime() & shift the lower 48-bits into the MSB & the lower 80 bits are a cryptographically-secure random number. (CSRN) generated at runtime. I don't like the idea of having to pay to generate random numbers at runtime so I created an npm package called linearid (LID) that uses a 128-bit value where the LSB is a 64-bit CSRN created upon server initialization, & the MSB is a 42-bit millisecond timestamp followed by a 22-bit spin ticker that gets reset every millisecond & incremented each time you call LIDNext(). If you call LIDNext() more than 2^22 (4,194,304) times in one millisecond it will spin wait until the next millisecond. This gives you a 128-bit monotonically increasing unique ID that you can use to look up data in SQL tables. Then to search for the SQL row, you extract the seconds timestamp from the LID, & search for the row by date range using the filesystems timestamps so you don't have to do a full table scan. Instead you search through all of the SQL rows created starting at the millisecond the LID was generated to something like three seconds after, which is much faster for searching for iNodes on disk....
No description

What would be a good way to have RLS with drizzle?

In a multitenancy app, is there any equivalent for lets say prismas client extensions? Or should we just use WHERE on each query? https://www.prisma.io/docs/concepts/components/prisma-client/client-extensions/query...

`returning` does not allow arguments according to typescript

Hi everyone, I'm seeing a weird typescript error while using the returning function on an insert query. I have the following code: ```typescript public async create(user: NewUser): Promise<User> { const [createdUser] = await this.client...
No description

how to disambiguate query relations

Hi everyone, I'm currently facing an issue with the Query API where I don't understand how to disambiguate a foreign key. I have the following schema: ```typescript const baseFields = { id: uuid('id').primaryKey().defaultRandom(),...

Alerting if there is conflict

I'm doing an insert and wanted to ask whether there is a specific error type that is returned when there is a conflict. Pseudo-code of what I would want ```ts await db.insert(guild).values({ id: interaction.guildId })...

Error starting Drizzle Studio.

Hi, I am new to drizzle, and rand into some issues starting drizzle studio, mentioned below. ``ules/drizzle-orm/index-1899b9ae.cjs:4180 throw new Error(There is not enough information to infer relation "${sourceTableTsName}.${relation.fieldName}"`); ^ ...
No description

Is it possible to use the "unaccent" extension with drizzle?

hello, I wanted to make an ilike comparison in my query for the letter %á%, but it does not match for %Á%, because afaik, they are regarded as two different letters by postgres. I asked chatgpt, who told me to use the "unaccent" extension to remove the accents before the comparison to get good results. Is this really the way to go? If yes, how could I integrate it with drizzle? I just want to query usernames without worrying about casing :DD

Insert Schemas with onConflictDoUpdate

I'm trying to leverage the onConflictDoUpdate method to update a record if it already exists. The problem is that I create an insert schema with drizzle-zod that enforces the non nullable fields are set. In the case where the record already exists, it is valid to pass in partial data to my function, but that then fails the insert schema validation. Is there any way to parse the insert schema only if there is no conflict? My current workaround is to separate the insert and update logic....

[Error] Using Drizzle with Neon DB

Is drizzle compatible with neon pooled connections? Neon pooled connections don't support prepared statements, and it seems like drizzle uses prepared statements internally for all requests, but I'm not sure. https://github.com/drizzle-team/drizzle-orm/blob/main/drizzle-orm/src/pg-core/query-builders/select.ts#L537 https://neon.tech/docs/connect/connection-pooling...

Migrations folder location?

Should the migrations folder be location somewhere in the src directory? Right now I’m experiencing errors with the migrate function trying to use the migrations folder in the root directory,. Copying the folder into src works (though i am now experiencing an unrelated error)

connection error, fetch failed

not sure if this issue comes from drizzle or planetscale but I'm getting this error while trying to do any queries from my db while on local dev ``` { e: TypeError: fetch failed at Object.fetch (node:internal/deps/undici/undici:11576:11)...

Creating a Case-Insensitive Unique Index

I want to be able to select a user by their username but have usernames be case insensitive: ```ts const user = await db.select() .from(users)...

Drizzle update enum

Hi everyone I am currently playing with drizzle and enum with postgres. However it doesn't seems to allow update ? For example with this code: ```ts export const updateExerciseTag = (tags: Exercise["tags"]) => { console.log(tags); // ['chest','legs']...
No description

many to many relation with uuid's

i'm trying to create a many to many relation with uuids. if i try to push the changes to the database (pg) i got the following error: ``` error: column "userId" cannot be cast automatically to type uuid { length: 179,...

GIN index

index('content_json_index').on(content).using('gin'), how do i do gin index on jsonB? postgres....