Drizzle Team

DT

Drizzle Team

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

Join

Sveltekit Failed to resolve import "cloudflare:sockets"

I was trying to use drizzle orm in a sveltekit project with postgres run in a docker container, but i'm having the following error ```sh [plugin:vite:import-analysis] Failed to resolve import "cloudflare:sockets" from "node_modules.vite\deps\chunk-JJ5CRB2A.js?v=dcae3c33". Does the file exist? F:/Python/jira-clon-2/node_modules/.vite/deps/chunk-JJ5CRB2A.js:2908:44...

Unable to insert rows when using libsql

hey, i am using libsql on my local environment with drizzle but i am unable to insert anything in the database. the promises seem to be broken. i am on the latest drizzle orm and kit version. here is the code to reproduce:...

generate:pg - 0 Tables pnpm Monorepo

Seems to be related to this issue - https://github.com/drizzle-team/drizzle-kit-mirror/issues/24 I only have drizzle-orm/drizzle-kit installed in a single package in my repo. ```...

Bulk update in Postgres w/ Drizzle ?

I'm using PSQL and would really like if Drizzle supported bulk updates out-of-the-box. I've looked at the docs - but the only option I've seen is an UPSERT (ie. insert w/ onConflictDoUpdate) statement which I'm not fan of for this use case. I'd really like to be able to do a .update(table).set(arrayOfObjects) ! But it looks like it's not supported....

Problem when inserting new record

Hello guys, when I'm trying to insert new record, I'm getting this PG error null value in column "id" of relation "MagicLinks" violates not-null constraint and in my schema, I have id: uuid('id').primaryKey().defaultRandom()...

BUG: Prepared statements with placeholder values .execute() not working on postgres

I'm trying to execute a prepared statement with placeholder() values ```ts export const articlePreparedQueryNodePg = dbNodePg .select()...

Nullable self-reference table relation

``` typescript: No overload matches this call. Overload 1 of 2, '(left: Aliased<null>, right: AnyColumn | Placeholder<string, any> | SQLWrapper | null): SQL<unknown>', gave the following error. Argument of type 'MySqlInt<{ tableName: "cuentas"; name: "padre_id"; data: number; driverParam: string | number; notNull: false; hasDefault: false; }>' is not assignable to parameter of type 'Aliased<null>'. Type 'MySqlInt<{ tableName: "cuentas"; name: "padre_id"; data: number; driverParam: string | number; notNull: false; hasDefault: false; }>' is missing the following properties from type 'Aliased<null>': sql, fieldAlias, getSQL...

Support for relational queries with views

Hello! I was wondering if there are plans to add support for relational queries with views? I am not presently able to define relations on a view as it is expecting a table as the first argument. Thanks!...

Many to many relationship between one type

I'm making an application where I have users who are able to follow other users. This means that I need a many-to-many relationship, but both sides are the same type (a user). I'm not sure how to express this with drizzle's relations, as I'm not sure how to specify both sides of the relationship For example... ```ts export const Users = pgTable("users", {...

How can I order and/or limit rows from leftJoin?

I have two tables, groups and exams, exam must have only group, group can have many exams. I'm selecting from groups and I want to select the latest exam with it (order by timestamp column). But I can't find anything like it in the drizzle orm docs, is is possible?

Can someone help me understand these 2 examples using pool and client?

I'm reading through the docs and see that in the 2 Neon examples, they use a pool and client. From what I understand, pools support multiple requests and a client doesn't. The 2 questions I have are: - When would I want to close the pool or client? I would assume I would want to keep it open in production so that I wouldn't need to open the connection again. - Why would I use a client?...

Type Declaration with TypeScript in Monorepo failes

I am trying to setup a monorepo with moon and pnpm, where shema lives in an additional package and is imported by other apps. Is there any monorepo example? Currently I get following error:
../db/src/schema/products.ts(4,14): error TS2742: The inferred type of 'products' cannot be named without a reference to '../../node_modules/drizzle-orm/db.d-a6fe1b19.js'. This is likely not portable. A type annotation is necessary.
../db/src/schema/products.ts(4,14): error TS2742: The inferred type of 'products' cannot be named without a reference to '../../node_modules/drizzle-orm/db.d-a6fe1b19.js'. This is likely not portable. A type annotation is necessary.
...

Type error?

``` import { pgTable, serial, integer } from 'drizzle-orm/pg-core'; export const users = pgTable('users', { id: serial('id').primaryKey(),...

Unsafe argument of type `any` inside select where eq query

I am getting the following type error even though I am not passing parameters of type any. Correct me if I am wrong because I am a typescript begineer. Refer to the screenshots attached. ```ts...

How to type results that includes relations ?

I have two tables: collections and products. Collection has many products. ```ts const results = await db.query.collections.findMany({ with: {...

Error: Either `connectionString` or `host, port, etc.` params be provided in config file

Hey, So i'm trying to setup Drizzle with PlanetScale, and want to use the drizzle kit push command, but i run into this error: ```console...

Setting AUTO_INCREMENT starting value

In MySQL it is possible to make auto incremented column to start from specified value. For example ALTER TABLE tbl AUTO_INCREMENT = 100; Is it possible to do that using Drizzle?

MySQL varchar gets inferred as MySqlText?

next-auth adapter help again. Is this my bug or Drizzle's? (Probably Drizzle's because Drizzle STINKS) TL;DR: MySQL varchars are getting inferred as MySqlText. Part of the requirements of next-auth is to provide a minimum schema but also let folks extend off of it. So, I have a minimum schema built for MySQL and am inferring it's type. But it looks to me like the inferred type of MySQL's varchar becomes MySqlText when it gets inferred. The problem with this ends up being that, when folks want to provide their custom table with the varchar (which is correct) they get an error because TS thinks it's supposed to be a MySqlText....

Problem with infering json type in zod schema

When using the following table/schema: ```ts const Test = mysqlTable( "Test", {...
Solution:
The .$type() helper only works on the type level, it cannot change the runtime behavior. The schema validation happens at runtime, thus it doesn't know about your type. If you want to validate your json field according to your type, you would need to refine the insert schema, like this: ```ts const TestInsertSchema = createInsertSchema, { value: () => z.object({ a: z.string(), b: z.number() }), });...

can't execute basic pg cmnds in drizzle orm .

I have written my schema and generated the table. I can use pg client to interact with the db but not with drizzle orm for some reason i am executing a simple command
const result = await db.select().from('auth_key')
const result = await db.select().from('auth_key')
it gives an error stating that
e: ReferenceError: auth_key is not defined
e: ReferenceError: auth_key is not defined
...