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 in Turborepo

How can I add drizzle to a existing turborepo?

SQLite auto-update timestamp

I'm trying to auto-update timestamp when using SQLite. This is my try, but it doesn't work: ```...

prepare() on update statement?

How can I make a prepared update statement? I'm using sqlite. 1. Do I only make the where clause prepared, or I need to make the set part as well? 2. Can a prepared statement do returning? ...

database useMigrations gives only query: "ROLLBACK" at the end.

and doesn't result in success or error. is there a way to reset the db? app is already in the test-teams hands and I need to reset it for each client-app. emptying db is ok. I tried doing "npx drizzle-kit drop" to drop each migration and generate new one. but I get this query "rollback" at the end. I see there is drizzle-seed but does it even work with expo and sqlite?...

Referencing Column at runtime

This could be a Typescript question, but there may also be a better way to achieve my goal with Drizzle. ```typescript const search = [ {...
No description

How to type a table with common column names ?

Hey, I have a couple tables that have some common column names, ex. ``` export const appointments = coreSchema.table( "appointments", {...

Connection terminated error

I dont know why im getting this error
No description

How to get schema name from table name?

I use the table as input for a function, and we can get the table name with getTableName which is no issue. However for using db.query.<schema name> we need the schema name (i.e. the js variable name), not the table name, but the table itself doesn't know it's variable name. Is there an easy way to retrieve it? Context:...

error: multiple primary keys for table "event_item_price" are not allowed

When wanting to create a composite primary key in my PG table i get an error when doing a drizzle kit push: ```js import { text, integer, timestamp, pgTable, primaryKey } from "drizzle-orm/pg-core";...

Getting type from a CTE

I've got the following function: ```ts import { eq, sql } from "drizzle-orm"; import { db } from "@/db"; import { permissionTable, userTable } from "@/db/schema";...

Type errors with database connection

If I follow the exact example from the docs either: ``` import { drizzle } from "drizzle-orm/node-postgres" ...

cannort generate migration

I cannot generate migration when I do npx drizzle-kit generate this is the stack trace ```No config path provided, using default 'drizzle.config.ts'...

"count.map is not a function" when attempting to seed database

Hello, I have set up the below seed.ts file in attempt to seed my database by adding fictitious users and scores for a web game I have created (code attached below). However, upon running the script I get the following error: ```TypeError: count.map is not a function     at GenerateWeightedCount.init (/Users/myname/Documents/GitHub/game-racer/node_modules/src/services/Generators.ts:143:52)     at SeedService.getWeightedWithCount (/Users/myname/Documents/GitHub/game-racer/node_modules/src/services/SeedService.ts:493:7)...

Weird typescript error in a monorepo (pnpm with turborepo)

Argument of type 'PgTableWithColumns<{ name: "users"; schema: undefined; columns: { id: PgColumn<{ name: string; tableName: "users"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; ... 6 more ...; generated: undefined; }, {}, {}>; ... 8 more ...; accessCodeSentTo: PgColumn...' is not assignable to parameter of type 'SQL<unknown> | Subquery<string, Record<string, unknown>> | PgViewBase<string, boolean, ColumnsSelection> | PgTable<TableConfig>'. Type 'PgTableWithColumns<{ name: "users"; schema: undefined; columns: { id: PgColumn<{ name: string; tableName: "users"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; ... 6 more ...; generated: undefined; }, {}, {}>; ... 8 more ...; accessCodeSentTo: PgColumn...' is not assignable to type 'PgTable<TableConfig>'. The types of '_.config.columns' are incompatible between these types. Type '{ id: PgColumn<{ name: string; tableName: "users"; dataType: "string"; columnType: "PgUUID"; data: string; driverParam: string; notNull: true; hasDefault: true; isPrimaryKey: true; isAutoincrement: false; ... 4 more ...; generated: undefined; }, {}, {}>; ... 8 more ...; accessCodeSentTo: PgColumn<...>; }' is not assignable to type 'Record<string, PgColumn<ColumnBaseConfig<ColumnDataType, string>, {}, {}>>'. Property 'id' is incompatible with index signature....

Drizzle-kit generate is failing when package.json is "type": "module".

Hi' I have drizzle set up in a monorepo and the package.json has "type": "module", so the imports looks like ".../../some-file.js". And the generate command fails 😦
cd packages/databases && pnpm generate
...

Specifying Postgres table as T prop?

Hello, I am trying to implement a reusable data fetching function. I need to specify a table in the function parameters. How can I specify the table type on T? I currently have PgTable, but it seems to throw a ts error: ```ts...

How do I inset into a binary/varbinary column? (mysql2)

Hi all, I've really tried searching but cannot find the answer. I want to insert into a binary/varbinary column, but not really sure what drizzle is expecting. It expects a string, but what kind of string? Does it want it in hex, a byte string, base64? I'm constantly getting error Data too long for column. I've tried all of the above and no dice....

Why Partial<typeof x.$inferInsert> is required for Partial Updates

Is it necessary to always use Partial when performing a partial update on a table using db.update(...).set(...) or am I missing something? I'm using drizzle 0.42.0 For example, I've this schema ```...

Using different schema than public in pg

In my company, we need to use another schema than "public". So we need all our DB to be created in this other pre-existing schema. I was trying to find the easiest way to do that, I saw you can specify at the config level for each table but isn't there an easier way like a simple setting in the drizzle config to just change public to something else ?...

Drizzle-seed and sequential dates

Say I have a schema with two DateTime fields, started_at and ended_at How would I use drizzle-seed and its refine function to seed my database with these values differening not more than say, 5 days? Aka if started_at seeds on 01-05-2025 then the minimum should be the same and the maximum for ended_at should be 05-05-2025...