Drizzle Team

DT

Drizzle Team

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

Join

mysql2 many-to-many

Is there an example of a mysql many-to-many relationship? I haven't been able to find one and I'm getting a foreign key constraint db error similar to this post https://planetscale.com/blog/working-with-related-data-using-drizzle-and-planetscale. I've created a join table with foreign keys and relations in line with the example here https://orm.drizzle.team/docs/rqb#many-to-many. Many thanks!...

Dynamic Drizzle Relational Queries

Hi everybody, hope all is well. I was wondering if there is a way to build dynamic queries when using drizzle (relational) queries. I read the section on dynamic query building but it doesn't cover relational queries. I'm building a rest API and I want users to be able to pass filters via query params....

migrate isn't applying the latest migration sql file

Hi, I made some changes to one of our schemas and I ran drizzle-kit generate to create the new migration sql file. However, when I ran the migrate script, it doesn't seem to be applying the migration. Any ideas what could be wrong? Our migrate file looks like this ``` async function run() {...
No description

ER_WRONG_AUTO_KEY - Drizzle Kit not detecting primary keys

Having trouble with the latest release of drizzle. Seems like drizzle is not detecting primary keys so every time I make a change to the schema and run drizzle-kit push:mysql with planetscale, it says the given error no matter what I change. I’m using the latest version of drizzle-kit and drizzle-orm. It’s fixed by downgrading to the previous major release. This is the thread most similar to the issue https://github.com/drizzle-team/drizzle-orm/issues/1428

Update number column with it's current value and new number

I need to convert this RAW sql query into a query in drizzle, but I can't find a way. Anyone done something similar?
UPDATE products
SET quantity = quantity + 15
WHERE id = <my-id>;
UPDATE products
SET quantity = quantity + 15
WHERE id = <my-id>;
...

How to use inner join with rqb?

Hello there! Having the following schema ```ts...

Using 'where' inside 'with'

Hello! I'm using schema like this: ` export const user = pgTable('user', { id: serial('id').primaryKey(), username: text('username').notNull(),...

json column type mismatch when using db.query

Hey all i have a schema with a json column, when I import the table records the type is inferred as 'unknown'. Any ideas on how to get this working, or do I have to infer the types manually? Thank you!...
No description

I swear this infer was working... am I crazy?

``` export type User = typeof user.$inferSelect; export const user = pgTable('user', { id: bigint('id', { mode: 'bigint' }).primaryKey(),...

optional join

it would be nice if we could do something similar to the where function, where if we return undefined, nothing happens, to do optional joins.

How to create a transaction outside of callback function?

Specifically for postgres Example Usage: ``` const tx = db.transaction()...

Access relation

if i use this example from docs ...should i be able to do both user.profileInfo and profileInfo.user? I want to query with WITH but somehow it works only one way.(i get type never)
No description

DB type error

I have looked at other help questions for this, but they don't really help me understanding the issues I have. I can do something like: ```javascript...

Generate drizzle migrations and push with drizzle kit with github actions for preview environments

Hello, so I am trying to deploy a preview environment with vercel and neon. Using this tutorial: https://www.youtube.com/watch?v=jjRasfbeYHk (related repo: https://github.com/neondatabase/preview-branches-with-vercel/blob/main/.github/workflows/deploy-preview.yml) . I have managed to make my workflow execute when I create a pull request, however I am running into issues when attempting to migrate and push those migrations to a generated neon branch. The repo above is using prisma, which is why I am having trouble using drizzle for this workflow instead. ...
No description

VSCode - how force auto-imports from 'drizzle-orm/pg-core' instead of 'drizzle-orm/mysql-core'

Hey, I'm using drizzle ORM with Visual Studio Code and it always auto-completes the 'drizzle-orm/mysql-core' package even when I'm already importing other stuff from 'drizzle-orm/pg-core' in the same file. It's not a big deal, you can just scroll to 'drizzle-orm/pg-core' but it's annoying. I've so far tried, but with no luck: - Setting autoImportFileExcludePatterns: ```...

Incorrect typing with joins on CRUD and RQB API

I'm losing typing whenever I'm using joins on CRUD api, getting [x: string]: never whereas it's typed when I'm not using joins. Same with the RQB API, joining something such as User with Posts returns User as the type... For both cases, the correct data returns in the route; since I'm using OpenAPI & RPC I'm trying to figure out how to type this correctly.....

Newline causing SQL error when migrating

If I run a migration that contains many SQL statements, it fails. If I generate the migration SQL one table at a time, the migration will succeed when being executed... Conclusion is that the newline character between statements is causing issues... breakpoints is true in drizzle.config.ts but that doesn't seem to be working at all, not breakpoints are added. ...

How to get the return Type of a query with relations?

- Imagine having 2 tables: Posts and Users - there is a relation between Posts and users, since 1 user can write several posts. So we define this relation. - now I write a query to retrieve the user and all his/her posts with the syntax: ``` const user = await db.query.findFirst({...
No description

Drizzle as SQL query generator

Hey everyone, is it possible to use drizzle to generate SQL queries as a string? I'm planning to use Drizzle in a desktop app and I have to use different tooling to connect to the database. However, it would be amazing to generate plain queries 🤔...