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 query from a many to many relationship?

Hi all, I am trying to get all the posts by a user. My schema has a many-to-many relationship set up for posts and users. ...

Correct way to deal with MySqlRawQueryResult

What is best practice to check if the data was created and how to get the newly added data? ``` db.insert(user).values({ firstname: data.data.firstname, lastname: data.data.lastname,...

Unknown option schemaFilter for drizzle-kit introspect

The documentation https://orm.drizzle.team/kit-docs/commands#introspect--pull states that there is a schemaFilter option to specify the database schema parameter. I have installed the newest drizzle-kit: ```...

How are you all seeding your database?

I see a question from back in March (5 months ago -- https://discord.com/channels/1043890932593987624/1088404663344316476 -- ) answered that it 's planned for in-code custom migrations. IMO seeding from within migrations isn't great, and is actually warned against in some other stacks (eg: Rails). I've fiddled around a bit this morning, trying to get a basic "hello world" ts-node script to run and load my ''src/lib/db" to get connection and schema, but had no luck. It seems like this should be an easy thing, to simply have a stand-alone script that could load up the drizzle-orm connection and schema, and use them to insert some data. Can I get a pointer in the right direction? Thanks!!...

Why it's not possible to use `where` here?

I'm trying to make a PoC for drizzle and I'm converting some sequelize to Drizzle, but I don't really have experience with databases to be honest with you. I can't understand, why using where is not possible in this case. Seems like I don't quite understand how to describe BelongsTo with Drizzle and that might be a problem. Can you guys help? Thanks...
No description

optional parent child relationship on same table

Hi all I have a table called 'comments' Some comments will have a parent comment, while others will not....

Converting drizzle custom type to Postgres composite type fails for arrays

I have a postgres composite type in my database consisting of three fields, accountNumber, beneficiaryName, bankId. I have overridden the toDriver implementation to try and handle insertion of this custom type as follows: ``` type BeneficiaryAccountSqlValue = [ account_number: string,...

Cannot drop primary key

I needed to change a table from a single field PK to a composite PK, using the following syntax ``` , (table) => { return {...

InferSelectModel vs. InferInsertModel

I couldn’t find any documentation on what the differences are. My best guess is maybe the insert type might not require auto incremented primary keys and other generated fields since you don’t have them on insert?

parameterized insert and update

How does one do parameterized inserts and updates? When I try and do something like this: ``` const preparedUpdate = db...

Conditional Relational Queries

I have these tables Simplified Version ```typescript export const ingredientTypeEnum = pgEnum('ingredientType', ['ITEM', 'FOOD']); ...

drizzle-zod doesn't work with Array in pg

I'm using drizzle-orm, drizzle-kit & drizzle-zod in my application. One of my schema looks like following: ```ts export const committee = pgTable("committee", { id: text("id").primaryKey().notNull(),...

Error when inferring type from db.query

When I try to use type foo = ReturnType<typeof myQuery> I get the following error Type 'MySql2PreparedQuery<PreparedQueryConfig & { execute: { [x: string]: any; matchPlayers: { [x: string]: any; playerName: { [x: string]: any; } | { [x: string]: any; }[]; } | { [x: string]: any; playerName: { ...; } | { ...; }[]; }[]; matchTeams: { ...; } | { ...; }[]; homeTeam: { ...; } | { ...; }[]; awayTeam: { ...; ...' does not satisfy the constraint '(...args: any) => any'. Type 'MySql2PreparedQuery<PreparedQueryConfig & { execute: { [x: string]: any; matchPlayers: { [x: string]: any; playerName: { [x: string]: any; } | { [x: string]: any; }[]; } | { [x: string]: any; playerName: { ...; } | { ...; }[]; }[]; matchTeams: { ...; } | { ...; }[]; homeTeam: { ...; } | { ...; }[]; awayTeam: { ...; ...' provides no match for the signature '(...args: any): any' ...

Sub-field Filtering example

In the 0.28.0 update that removed relation filters, the changelog suggests: https://github.com/drizzle-team/drizzle-orm/releases/tag/0.28.0
If you have used those fields in the where callback before, there are several workarounds:...

It is possible to stop notice logs from appearing?

Hi there. So I'm using postgres and I run execute with table truncate. No matter what I try I always get some stuff spammed into the console. Same applies for migration scripts. Overriding logger or writer doesn't help in this case....

Drizzle-zod createInsertSchema types

if I have a schema : ```export const listings = pgTable("listings", { id: serial("id").primaryKey(), ... squareFeet: integer("sq_ft").notNull(),...

cannot find package '@opentelemetry/api' in 0.28.4

I just upgraded to 0.28.4 and after I made the necessary changes for my types, I started the dev server and got this error. I'm using planetscale driver. ``` Error: Cannot find package '@opentelemetry/api' imported from qaimni\nodemodules.pnpm\[email protected]@[email protected]\node_modules\drizzle-orm\planetscale-serverless\index.mjs...

adding default to array of text creates invalid migrations

values: text('values').array().notNull().default(['a', 'b']) generates: ALTER TABLE "test" ALTER COLUMN "values" SET DEFAULT a,b; ...

Missing @opentelemetry/api module at runtime when upgrading to 0.28.4

Just upgraded drizzle-orm to 0.28.4, and running my project (after a successful typecheck) I get the error Cannot find module '@opentelemetry/api'. Here is the full stack trace: ``` Require stack: - C:\Users...\node_modules.pnpm\[email protected][email protected]\node_modules\drizzle-orm\index-b1dbb7ec.cjs...

Invalid default value for 'updatedAt'

Running into this issue, oddly enough this once worked and now breaks. ``` Error: target: americana-db.-.primary: vttablet: rpc error: code = InvalidArgument desc = Invalid default value for 'updatedAt' (errno 1067) (sqlstate 42000) (CallerID: planetscale-admin): Sql: "alter table InventoryItem modify column createdAt datetime(3) not null default (current_timestamp(3))", BindVars: {REDACTED} at PromiseConnection.query (/Users/robmartin/Projects/americana-neue/node_modules/.pnpm/[email protected]/node_modules/drizzle-kit/index.cjs:34122:26)...