Drizzle Team

DT

Drizzle Team

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

Join

[drizzle-zod] How to make all fields of a schema derived from a table required ?

I just tried the plugin and I'm happy to move from manually creating zod schemas. However, I came into a use case where a schema must have all nullable fields in the table required. Assume we have these in users table: ```typescript...

Is there a way to declare a custom SQL index?

I'm trying to create an index on the lowercase value of a column using Postgres. I tried
unique().on(sql`lower(${table.username}::text)`)
unique().on(sql`lower(${table.username}::text)`)
but "on" only accepts columns...

sqlite code first with in-memory db

Hey, I thought it'd be rather easy to create a schema from scratch without running a "migration" (from nothing to v1 is a migration?), but apparently I was wrong. I'm using bun:sqlite and would prefer to not create some migration files or whatever. Shouldn't db.run(table.getSql()) work? Is there even an option to bootstrap a schema without creating additional files?...

Drizzle-Kit: incorrect schema.ts being used

I have some schema files in a subfolder. I have referenced the path in the drizzle.config.ts, but instead drizzle just creates a schema file in the drizzle directory next to migration files. What gives?...

Group by Multiple columns with drizzle

I have a schema that looks rougly like this:
date | location | name | quantity
date | location | name | quantity
I want to groupBy multiple columns(date,location), but I'm not sure if there is a drizzle-way to do it, or should I do a raw query? ...

[Fixed] is not assignable to parameter type Record<string, PgColumnBuilder>

Hi, Trying to install Drizzle, using the basic example from the docs. Getting the following error:
Argument type {phone: PgVarcharBuilder<{name: "phone", dataType: "string", columnType: "PgVarchar", data: [string, ...string[]][number], driverParam: string, enumValues: [string, ...string[]]}>, fullName: PgTextBuilder<{name: "full_name", dataType: "string", columnType: "PgText", data: [string, ...string[]][number], enumValues: [string, ...string[]], driverParam: string}>, id: PgSerialBuilder & {_: {notNull: true}}} is not assignable to parameter type Record<string, PgColumnBuilder>
Argument type {phone: PgVarcharBuilder<{name: "phone", dataType: "string", columnType: "PgVarchar", data: [string, ...string[]][number], driverParam: string, enumValues: [string, ...string[]]}>, fullName: PgTextBuilder<{name: "full_name", dataType: "string", columnType: "PgText", data: [string, ...string[]][number], enumValues: [string, ...string[]], driverParam: string}>, id: PgSerialBuilder & {_: {notNull: true}}} is not assignable to parameter type Record<string, PgColumnBuilder>
...
No description

What is the Drizzle convention for storing the `db` object?

In the "Quick Start" guide, it showcases connecting to the database at the root of a module. However, in real code, this would likely be in a file called "db.ts", and it would not be at the root of the module, since the connection string would not yet be available. This is my naïve attempt to show what a more real-life code would look like: ```ts export let db: PostgresJsDatabase;...

Default value for Array creates an incorrect SQL migration

I'm currently adding a new field roles to my PG table, users, such as: ```typescript export const users = pgTable( 'users', {...

Bug: drizzle-kit generate:pg didn't see the changes in the schema

On my uniqueIndex i added a where clause to not check the soft delete records. When running generate, the drizzle-kit didn't generate any migration since it thinks i haven't modified the schema.
No description

update multiple fields

Hi is there a other way to update multiple fields currently i do it like this ```js const updatePollOption = (option: PollOptionsSchema) => {...

Need help implementing one to many relations for a table on itself

```typescript const comments = pgTable("comments", { id: text("id").notNull().primaryKey(), parentCommentId: text("parent_comment_id").references(...

How to dynamically select columns in relation query with proper type inference ?

```ts const result = await db.query.products.findMany({ columns: { id: true, title: true,...

Authjs extending user model for Role based auth trouble.

Recently started to use the new drizzle-adapter for Authjs. And I am having trouble extending the user-model for role based auth. I am not interested in getting the role from my provider (Discord) I want to manage the role in my own DB. Currently when I try to apply the role as shown in the docs (https://authjs.dev/guides/basics/role-based-access-control) TypeScript says that there are no "role"-property on the AdapterUser. How do I override the AdapterUser to include my role-property, so TypeScript isn't mad at me. 🙂...

Nested one to one relation shows [x:string]: never

I tried using the relational query similar to the example ``` const users = await db.query.users.findMany({ with: {...

table not being camelcased when using joins?

For some reason when I use the following query: ```TypeScript const getProductByIdResult = await db .select() .from(product)...

Invalid serialization of JSON blobs

Has anyone gotten default values of JSON blobs to work with SQLite? When I try using an empty array, the SQL migration does not have a default value (despite having the DEFAULT keyword). ```ts...

Is drizzle edge compatible (noobie question)?

Hi, I'm new to drizzle. I tried to set up a drizzle client with turso in cloudflare workers and I get these errors: ```[ERROR] Could not resolve "node:buffer" ../../node_modules/@libsql/client/lib-esm/sqlite3.js:2:23: 2 │ import { Buffer } from "node:buffer";...

Query where clause with array.

How can I get something like this to work? ``` const products = ["subscription", "insurance"] ...

What's the best way to deploy migrations on production database?

I'm confused as to what is the best way to deploy migration on the production database. Locally when I test on my local database instance, I use the commands manually to generate and push the migrations But I want to automate this. Say, I'm using Vercel and I want to push the migration on every commit. In prisma to deploy the generated migrations I use the command prisma migrate deploy, I add this command to the build command like this: prisma generate && prisma migrate deploy && next build...