Drizzle Team

DT

Drizzle Team

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

Join

Help querying D1 with Drizzle

I was able to run migrations with this drizzle.config.ts: ``` import { defineConfig } from "drizzle-kit" ...

Passing column values through custom TypeScript functions ...

I am attempting to do this: ```ts const hz = db.$with('sq').as( db...

Calling a stored procedure with an array parameter

I'm trying to call a stored procedure from drizzle which is roughly defined as:
CREATE FUNCTION demo( param1 uuid[], param2 uuid...

Large inserts throw `RangeError: Maximum call stack size exceeded`

In several cases I've noticed that with inserts of ~4k rows I get this RangeError: Maximum call stack size exceeded error. Note that I am using .onDuplicateKeyUpdate (i.e. they are upserts). By breaking my inserted data into chunks of ~2k rows each, I can do inserts without this bug. This suggests to me that my application code is not at fault. I'm using Planetscale/MySQL, but I don't think it has to do with the database connection - even using const query = db.insert(...).values(...) and then console.log(query.toSQL()), which normally works, gives the same error when there are this many rows. My guess is that the SQL builder is the culprit (maybe some O(n^2) recursion somewhere)....

[AWS Data API] The result contains the unsupported data type CHAR.

I've got an issue with the AWS Data API returning an error when joining on a table when there are no related records in the joined table (I think). The attached bug report should be more helpful than that description! I've figured out that I can narrow down my SELECT fields and avoid the issue, and I realize this isn't really a drizzle issue so much as an AWS issue, but wondered if there was a workaround at the drizzle-orm level (or if you could help educate me).

Not possible to add a new column to schema with drizzle migrate push (pg)

I'm adding a new column to my schema and running drizzle-kit push connecting to a postgres db It never adds the new column. However if the new column contains a foreign key constraint it will attempt to add that, but will of course fail because the column hasn't been created. This has never worked in the few months I've been using drizzle kit, perhaps I'm missunderstanding the purpose of push? Does it not handle column level modificatons only new tables?...

Support for NodeNext

Hello, DrizzleStudio and migrations dont work for me because i use "moduleResolution": "NodeNext" in my tsconfig.json. I use this because of monorepo and building packages with tsc. This module resolution requires importing ts files as .js. The error it throws is this Error: Cannot find module './schema.js' ...

Nested Where Clause in Many-to-Many relation using Query

Hello, I have a many-to-many relationship between my events categories table.' As of now, I am trying to filter this data by joining my events table with the junction table (eventToCategories) and then the junction table with categories table. When attempting to use the where clause in the categories table so I could filter by certain events, typescript told me that the where clause was not allowed to be used here. I am not fully sure why this is the case, but I was wondering if anyone had a sol...
No description

error: type "userrole[]" does not exist

So when I'm running db:push I'm getting an error that the enum userrole doesnt exist. I have the enum here and it shows in the supabase enums list as well. This is the code ``` enum...
No description

weird error in production (TypeError: Right side of assignment cannot be destructured)

I just checked the logs from my production server and saw this error, several times and can't understand why they may be happening: I can't seem to reproduce it manually. Here's the code "causing" it: Any insights would be welcome....
No description

drizzle kit not migrating to turso properly

I have this little app with this schema https://github.com/nevthereal/codoodle/blob/main/src/lib/server/db/schema.ts And if I generate an sql file it will output something different, meaning not in the same order. First the posts table, then sessions and on the bottom users. I don't know if the order actually affects the migration, but i think it does. When I run the migration I always get some libsql error with the code 500. Important to note: my db on turso was created with --type schema if this has any importance. but anyways. Always when I want to run the migration, I get this 500 error code: ```...

Error handling

Should execute be used to correctly throw errors, or is it the same in this case? ```ts const result = await context.db .delete(user) .where(and(eq(user.role, 'student'), eq(user.id, userId)))...

The result after join (table alias)

How to configure alias here? The result of the join return the original table name (library_level), but I expect libraryLevel, which is defined at the application level. ```ts export const libraryLevel = sqliteTable('library_level', { id: integer('id').notNull().primaryKey(), name: text('name', { mode: 'text', length: 255 }).notNull().unique(),...

unable to run drizzle studio

im uitlizing drizzle orm in next.js however when i run the drizzle studio using drizzle kit it seems to be stuck here is my drizzle.config.ts file: *import { defineConfig } from "drizzle-kit";...
No description

using drizzle with .env.local instead of .env

I am using Drizzle with Next.js, can I use .env.local file instead of .env or It will throw an error.
Solution:
If /src/db/db.ts is only used from within the Next app, it should just be: ```ts import { drizzle } from "drizzle-orm/neon-http"; import { neon } from "@neondatabase/serverless"; ...
No description

Best way to get all unique strings from string[] column

I have a column listings.tags which is a postgres string array. I want a query to find all unique strings that match a query. Is there a better or even more drizzle-y way to do this vs. my current code: ``ts const tagsSubquery = db .select({ tag: sql<string>UNNEST(${listings.tags})`.as('tag')...

drizzle + turso config

im not able to migrate my schema using drizzle + turso drizzle.config.ts ```ts import type { Config } from "drizzle-kit";...
No description

not able to run drizzle-kit

I am getting this error
$ drizzle-kit introspect
bash: drizzle-kit: command not found
$ drizzle-kit introspect
bash: drizzle-kit: command not found
I have drizzle-kit in my package.json...
No description

weirdness with sql`CURRENT

Here's my simple schema ``` export const sageTransactions = sqliteTable('sageTransactions', { id: integer('id', { mode: 'number' }).primaryKey({ autoIncrement: true }),...
No description

returning() doesnt work with onConflictDoNothing

Asking for drizzle sqlite. in an insert many scenario, returns an empty array on conflict if that is intended, what is the best way to get return previously inserted ids & information, with/without conflict?...