Drizzle Team

DT

Drizzle Team

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

Join

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 ...

groupby multiple things

the SQL query I want to convert ends with:
GROUP BY
u.user_id,
e.ExerciseID;
GROUP BY
u.user_id,
e.ExerciseID;
I see no where in the docs for multiple groupBy however would expect this would work: ``` .groupBy([ users.user_id, exercises.ExerciseID...

Unwrap the return type of a Subquery, native jsonAgg support or RQ Join Names?

Hi There, I am currently investigating Drizzle ORM and seeing if I can bend it to do everything I need 😅 I quickly got into making queries that both return nested JSON properties (User Including Posts Including Comments etc) but also wanting to use the power of SQL to do some summations / transform values etc. ...

Unform methods for result access

Is there a set of uniform methods for accessing the results of a query? Could be good to have something like the ones available in sqlite adapters - .get() to get the first result Promise<T | null> - .all() to get Promise<Array<T>> - .iter() - can have a default implementation based on iterating over an array of all the elements, but could also support a memory-saving AsyncIterable for adapters that can do streaming...

Cannot query DB table get `COALESCE types smallint and text cannot be matched`

When i run the following query ```javascript let tc = await db.query.ATable.findFirst({ where: and(...

Cannot Access Primary Key on Table

Hello, I am trying to access the primary key named id on the following table: ```ts export const invites = mysqlTable( "invites",...