Drizzle Team

DT

Drizzle Team

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

Join

Unchanged schema, `db:push:pg` generates faulty `ALTER` statements

Schema: ``` CREATE TABLE IF NOT EXISTS "private"."users" ( "created_at" timestamp NOT NULL, "updated_at" timestamp NOT NULL,...

Get `id` of inserted row

Is this the right way to get the id of an insert? It feels incredibly cumbersome for such a common pattern, so feel like I'm doing something wrong:
const { resultId } = (await Database.insert(UsersTable).values(userInsert).returning({resultId: UsersTable.id}))[0]
const { resultId } = (await Database.insert(UsersTable).values(userInsert).returning({resultId: UsersTable.id}))[0]
...

Column primary key not working

What am I doing wrong when defining my primary key here? column: ``` const customPrimaryKey = customType<{ data: number;...

Drizzle kit SQL error

Hi all, I'm getting this weird error when I try to push my schema changes using drizzle-kit push and I have no idea where to begin to solve it: ```bash...

Migrating prisma schema to drizzle

Hey you all, I'm currently migrating my prisma schema to drizzle. I'm using sqlite and checked out how the types of prisma transfer to sqlites types. However drizzle doesn't support numeric and decimal and I wondered which datatype I would use instead. Also what is the best way to implement prisma features like cuid() Using a library and then doing string("id").default(cuid())...

How to make an unsigned bigint column in MySQL

Hiya folks, I am trying to use lucia auth with drizzle, and it requires me to make a table with unsigned bigint, however I can't seem to find that option anywhere in the documentation or google. Can someone help me with that. Thanks a ton

Is there any way to specify onDeletes and onUpdates with drizzleORM?

I can't find anything in the docs that specifies these options for a mysql connection.

Does changing the name of a relationship have any consequence aside from having to fix any queries?

We want to change the name of a relationship and I was curious if this would cause any issues? Let’s say person had a cat relationship and I wanted to name it cats, would this be okay?...

First parameter has member 'readable' that is not a ReadableStream.

Hi, I'm trying to use Vercel (lambdas not edge) and Planetscale. On localhost it works fine, but when deploy I'm getting error. It happens with every query. Any ideas? ```Unhandled Promise Rejection {"errorType":"Runtime.UnhandledPromiseRejection","errorMessage":"TypeError: First parameter has member 'readable' that is not a ReadableStream.","reason":{"errorType":"TypeError","errorMessage":"First parameter has member 'readable' that is not a ReadableStream.","stack":["TypeError: First parameter has member 'readable' that is not a ReadableStream."," at assertReadableStream (/var/task/node_modules/web-streams-polyfill/dist/ponyfill.js:362:19)"," at convertReadableWritablePair (/var/task/node_modules/web-streams-polyfill/dist/ponyfill.js:3524:9)"," at ReadableStream.pipeThrough (/var/task/node_modules/web-streams-polyfill/dist/ponyfill.js:3608:29)"," at fetchFinale (node:internal/deps/undici/undici:10965:56)"," at mainFetch (node:internal/deps/undici/undici:10857:9)"," at processTicksAndRejections (node:internal/process/task_queues:95:5)"]},"promise":{},"stack":["Runtime.UnhandledPromiseRejection: TypeError: First parameter has member 'readable' that is not a ReadableStream."," at process.<anonymous> (file:///var/runtime/index.mjs:1186:17)"," at process.emit (node:events:525:35)"," at process.emit (/var/task/node_modules/source-map-support/source-map-support.js:516:21)"," at emit (node:internal/process/promises:149:20)"," at processPromiseRejections (node:internal/process/promises:283:27)"," at processTicksAndRejections (node:internal/process/task_queues:96:32)"]}...

onDuplicateKeyUpdate ???

i don't suppose anyone knows how to actually use this method? zero documentation on it and the planetscale dbClient only recognises this method after the values function. There is no "onConflictDoUpdate" or "onConflictDoNothing"....i just want it so if there is an item with the same slug, ignore the query... ```ts export async function seed(client: DbClient) { await client...

data migration on a D1 database

hello. i need to do a data migration in a D1 database and need to update the data in primary keys. what approach would you recommend? thanks in advance.

Drizzle + Astro => ETIMEDOUT

I have been running Astro with Drizzle for a period of time now, in one project. The project used to use Prisma, but i wanted to try out Drizzle When i develop on the project, i run the astro with npm run dev. I connect to Drizzle with this piece of code: ```...

Implementation of Drizzle and tsoa

Hello, I am trying implementing Drizzle but I also want to implement tsoa for auto generating documentation. Do you guys have any idea how to make the model schema with tsoa annotations? https://tsoa-community.github.io/docs/descriptions.html...

Query a table based on related table

How do I go about querying a table of let’s say visits that each have a date and have a relation to a table called jobs where one job could have many visits, how would I go about getting visits based on a date range that only belong to a job with a given “company id” I know how to get them in the date range but I’m not sure how to go about having a date range and() related jobs company Id without also storing the company id in each visit...

Is there a way to easily convert existing schema's to different DB type?

I have a mySQL schema currently, but wanted to try out libSQL via Turso, but didn't want to have go through my entire schema and queries and change them all manually. Is there some easier way to do this?

Mocking Drizzle instance

Hey there, I am currently trying to find a good way to mock our drizzle instance for our unit test suite, but the nature of the usage of it makes it kinda hard. Is there somebody who is running a code base with a mocked drizzle?

How to run a Cleanup Script

I saw someone provide a nice script to empty the database, here's a version of it: ```typescript async function emptyDBTables(db: PlanetScaleDatabase<typeof schema>) { console.log("🗑️ Emptying the entire database");...

Add conditions on relationships

Is it possible to add conditions when declaring relationships? In my example, I have books that have many resources. And one of those resources might be marked as the 'cover' of the book. I already have resources defined as a many relationship, but I want to add an additional one relationship for the cover resource, with an extra condition of isCover:true. e.g. something like this:...

how is remove nested relation name "collection". Used many-to-many relationship.

request: await db.query.products.findMany({ with: { collections: {...

I tried date format in the where clause it showing me an error.

this is the query im converting SELECT , (SELECT COUNT() from daily_check WHERE (daily_checks.qid = question.id) AND (daily_check.is_completed = 1) AND (DATE_FORMAT(CONVERT_TZ(FROM_UNIXTIME(daily_check.date),'+00:00','+5:30'), '%d-%m-%Y') = '30-07-2023')) AS is_checked FROM question WHERE (restaurant_id=1) AND (status=1) AND (trash=0) AND (category=1) HAVING is_checked = 0 ...