Drizzle Team

DT

Drizzle Team

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

Join

[How To?] Generate uuids properly on cloudflare d1 sqlite...

I am running an app with Drizzle, TRPC, and Cloudflare D1 sqlite database: My initial project databasse schema looks like: ``` export const CarTable = sqliteTable('Car', {...

Dropping primary keys every time

so latest drizzle-kit fixed a bunch of issues with dropping indexes and preserving pk order but it's still dropping and recreating PKs every time `` ALTER TABLE account` DROP PRIMARY KEY;...

need help abstracting a function

This may be an easy answer but how can I implement the following type? ```typescript export const getUserWithEmail = (email: string, withConfig: any) => { return db.query.usersTable.findFirst({...

Does drizzle support `disconnect` relations ?

Does drizzle support disconnect feature on relations during update query similar to prisma ?

binary columns in drizzle studio

I have implemented the following custom type for storing blockchain addresses: ```typescript const address = customType<{ data: string; driverData: Buffer }>({ dataType: () => 'BINARY(20)', fromDriver(value) {...
No description

Access values in "where" query

Hey, so I wan't to do some calculations, specifically geo radius. How can I access the data while doing the query? ```ts const res = await db.query.apartments.findMany({ where: (apartment, { lte }) => { const long = apartment.long...

Unable to delete from many to many relationship due to FK constraint

I have the following schema, Users <> Teams - many to many usersOnTeams - table to hold this relationship ...

PostgresError: Relation X does not exist - After reorganizing schema

Hi guys, I have two tables (team and team_members) , which have a relation. All my schema was in one file and I decided to split it into multiple to make it cleaner. ...

how to do the opposite of inArray()?

i'm getting all collections (music single, ep, or album) that contain a certain tag. currently i'm doing this:```js const chosenTagCollectionIDs = tagMap.get(tag); const collections = await getCollections({ where: inArray(collectionsTable.id, chosenTagCollectionIDs),...

How to use drizzle-zod generated schemas in Next.JS frontend?

I'm currently using the pages dir in Next.JS and I have a function making an API call. I want to pass the returned body into the generated zod schema using zod and drizzle-zod. The problem is, when I import any created schema, I receive this error: ``` ⨯ ../../node_modules/.pnpm/[email protected]/node_modules/postgres/cjs/src/connection.js:1:0 Module not found: Can't resolve 'net'...

TypeError: client.unsafe is not a function with neon

i get this error only when using the neon driver. with normal postgres, it works normally.

Getting "never" type from querying a relation

When I use query function with "with" on a one to many relation it returns the type "never". What am I doing wrong?
No description

mapWith, any special things to make it work ?

I can't seem to have mapWith() work - I am logging inside the function and it nvever gets called. I am doing some sql-fu and want to return a collection that is declared in drizzle, and would like to have it mapped to my js object. I tryed on sql``.mapWith(), sql.join().mapWith() without any success....

Why truncate??

Updating some schemas. All 48 records in the item table have cmsSlug and cmsId. All 48 records have a 36 character cmsId. So my question is, why are the only options to truncate or cancel? Output:...

error on push on local libsql

I'm trying to use libsql locally, so i configure my drizzle.config.ts and when i try to run the push command i receive this error ```cmd Error: Could not locate the bindings file. Tried: → .../node_modules/better-sqlite3/build/better_sqlite3.node...

Drizzle kit migration doesn't reflect schema's relations

I have two schemas in my application, one for parent courses and another one for child courses; they have a one-to-many relation between each other (one parent course can have multiple child courses). When I run npx drizzle-kit generate:pg I see the output in the CLI stating that non of them have foreign keys and when I check the snapshot I verified that no foreign key is present. My config looks like this:...

SQL string does not contain any statement

I currently have 1 sqliteTable on my schema and 1 migration, so I wan't to create a new table and migration. When I run the drizzle-kit generate:sqlite command, all works well, but when I run the migrate... one error heppens: LibsqlError: SQL_NO_STATEMENT: SQL string does not contain any statement this is my migrate.ts file ```ts...

Cannot read properties of undefined (reading 'referencedTable')

i'm just playing around with queries and i can't get this to work:```js const liked = await db.query.collectionsTable.findMany({ with: { likedCollectionsTable: true }...

Key columns "user_id" and "id" are of incompatible types: text and bigint.

I'm getting the error in the title ^ but they're the same type. ```js export const usersTable = pgTable('users', { id: text('id').primaryKey()...

Migration Failed LibsqlError

I had migrated prior, done a lot of schema work, and then did a drizzle-generate, worked fine and I migrated, but got the following error. ```bash Migration failed LibsqlError: SQL_NO_STATEMENT: SQL string does not contain any statement ......