Drizzle Team

DT

Drizzle Team

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

Join

Neon DB pooled connection prepared statement error

When using Neon DB with pooled connection it gives the following error: ``` - error node_modules@neondatabase\serverless\index.js (1539:47) @ execute - error NeonDbError: db error: ERROR: prepared statement "s10734" does not exist ...

How to define schemas for friendship table

Just wondering whether or not i should define friendshipsRelations table. Relation: A user can have many friends ``` export const usersRelations = relations(users, ({ many }) => ({ friendships: many(friendships),...

drizzle-zod refine enum

Here's my users table and the schema generated with drizzle-zod that I want to modify. As you can see, the role column is an enum, but I want to modify the error message as I did with email and password. I've tried several solutions but nothing works, could you help me? ```ts export const roleEnum = pgEnum('role', ['USER', 'ADMIN']) export const users = pgTable('users', {...

It seems that the libsql server is outdated

I'm sporadically getting this issue whilst connecting with turso. Sometimes call is successful and sometimes I get following error. Not sure if this is drizzle or turso issue LibsqlError: SERVER_ERROR: Server returned HTTP status 404. It seems that the libsql server is outdated, please try updating the database. at mapHranaError (/Users/rob/Public/Code/api_node/node_modules/@libsql/client/lib-cjs/hrana.js:287:16) at HttpClient.execute (/Users/rob/Public/Code/api_node/node_modules/@libsql/client/lib-cjs/http.js:84:48)...

migrate function hangs without any result

I have this in my migrate.js file ``` // @ts-check ...

Select with a join that returns eagerly loaded submodels

hey all, is it possible to do a select on a model using a join and return the model with eagerly loaded fk models. Something like this where I'm joing wharehouse to location to filter on location.city but i want the location to be returned nested in wharehouse not alongside ` getWarehousesInCity: publicProcedure .input(z.string()) .query(async ({ctx, input}) => { return await ctx.db.select({...

role 'postgres' does not exist

Hi, Trying to run db:push with a postgres db, gettign this error: ```No config path provided, using default path Reading config file '/Users/johnbogart/RCOOP/com/drizzle.config.ts' error: role "postgres" does not exist...

How would I get 2 unique values?

I got my post likes table. ```ts export const postLike = sqliteTable( "post_like", {...

Infinite scroll w/ Drizzle + tRPC

Has anyone implemented infinite scrolling/pagination using Drizzle? The example in the tRPC docs uses Prisma, which has a built-in cursor parameter for pagination. What would one use for Drizzle? https://trpc.io/docs/client/react/useInfiniteQuery...

HRANA_WEBSOCKET_ERROR: Unexpected server response: 404

```ts // ./drizzle.config.ts import type { Config } from "drizzle-kit"; export default {...
No description

URL_INVALID

The env variables are defined when using bun run push but not when using npm run push or pnpm run push, resulting in LibsqlError: URL_INVALID: The URL is not in a valid format because url is undefined?authToken=undefined ```TS export default { schema: "./src/db/schema.ts",...
Solution:
bun parsed the .env file automatically but node does not. You need you use dotenv or something similar when using pnpm/npm/yarn

Custom Logging: hide notice messages ?

Hi, I'm using Drizzle ORM with Postgres SQL. Every time I start my project, it does a migration and logs things like this in my console: ```...

Specifying single schema to push

Hello: I'm hoping to push a single schema to the database after dropping the table. This way I can start over on this table but the rest of the tables are untouched. I'm trying the following in the terminal:...

`sql.join` with `ODER BY` leads to syntax error while the sql query seems correct.

I am conditionally sorting the results from a database query ```ts const sortSqlChunks: SQL[] = []; if (sorting.length > 1) { const customSort = sorting.shift();...

How to run migration script?

I am looking into this doc (https://orm.drizzle.team/kit-docs/overview#running-migrations) regarding running migrations and you provide a script that we can call. My question is how can we call this script outside our app. Maybe through the bash/terminal?

Cannot get id field in the next-auth session.

I am currently working on the drizzle nextjs project. I am using neondb postgresql as database. I am currently facing this issue where i cannot get userId in the session of getServerSession(). I have posted the code that i have worked on currently in this post. If i try to console.log(user) in session or jwt callbacks it returns a undefined value. The token doesn't have a id field. ...

How to express "children" or "parent" relation with typescript?

Let's say I have a country and region tables. A region belongs to a country, so on the regiontable, there's a foreign key country_id to the country table. The question is if it is possible to have a Country type generated like this: ```...

'token' used in key specification without a key length

Apparently I need to use token: varchar("token", { length: 255 }) because token: text("token") giving issues when pushing. Why? I'm using drizzle with planetscale....

ER_TABLE_EXISTS_ERROR

Can someone explain me what is the proper workflow? 1. change schema.ts (add another column to table) 2. generate migration 3. migrate...