Drizzle Team

DT

Drizzle Team

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

Join

Instantiate a connection with PlanetScale in Cloudflare Workers

Hey, What would be the right way to instantiate a database connection with PlanetScale in Cloudflare workers and reuse it across different handlers? We cannot instantiate it outside the handler because we have no access to the environment variables : ...

select count(*) returns a string not a number? mysql

When running SELECT count(*) it returns a string. Attached is an image of the query and the output. Can someone help me make sense of this....
No description

Shared Table Behavior

I have a bunch shared metadata (and thus shared logic) across all my tables - things like ID generation, when to mark a row as updated, and by whom... Using drizzle, what's the recommended way to share logic like this across tables/models?...

Using query builder with views

How do you use the query builder with views? typescripts yells at me saying that db.query.nameOfView is not defined. Thank you in advance...

How to use "onConflictDoUpdate" with composite key?

If a user sends a friend request while one exists it should update to pending. But the "friends" table is using a composite key. Table looks like this ```...

Is there something wrong with my schema?

fyi: i'm building an authenticated todo app
No description

Error when pushing to the db

I am trying to do a one-to-many relationship, but I get an error that is column "twitchSubscription" cannot be automatically cast to type integer. According to what I read in the documentation I'm doing everything right but the error says something else, maybe I misses something. - Schema: ```ts export const GuildSubscriptionTable = pgTable(...

Nested where clauses in relational queries

I have this query: const asset = await db.query.assets.findFirst({ with: { assetImages : true,...

Default values to integer timestamps in sqlite

I would like to set a default timestamp on record create in mysql. My schema look like this: export const users = sqliteTable("user", { ... createdAt: integer("createdAt", { mode: "timestamp_ms" }) .default(new Date())...

Is it possible to use nanoid for uuid?

Hi, I want to see if I can customize the uuid generation but I have no idea how to do it. Is there a code sample that I can follow? Thank you...

findMany without additional options

When using const results = await db.query.habits.findMany() in my project, results is []. If add any option like ```ts const results = await db.query.habits.findMany({...

Not equal with relational queries

Has anyone used ne with relational queries? When I use the callback syntax, I get the following type error: ```ts...

What is wrong with my one to many schema?

``` export const jobs = pgTable('jobs', { id: serial('id').primaryKey(), user_id: varchar('user_id', { length: 15 }) .notNull()...
No description

only first db migration runs

thought I'd repost here in case someone else is experiencing this https://github.com/drizzle-team/drizzle-orm/issues/1017

Preferred way of adding generated column and unique partial index in schema

I want to add something like this sql in my schema: ``` ALTER TABLE TaskUsers ADD COLUMN is_assignee BOOLEAN GENERATED ALWAYS AS (role = 'assignee') STORED;...

Query builder insert

What is the syntax for creating an insert query with the query builder ? There are some examples on the website showcasing select, but i'm looking for insert logic, which the query builder under drizzle-orm/sqlite-core is missing ( seems to only have select on the QueryBuilder)...

Correct typing when using "columns" as param

Hello awesome people at Drizzle, I'm having this problem and I don't know how to fix it. So... I have this RoleManager service that has a method called getByName that can take in columns. The problem is that I can't seem to type this query in a nice way and what I've done doesn't tickle me the right way. xD...

Can I create a default row when `drizzle-kit push`

I have a config table and I want to have some default data when push to db. Can drizzle-kit create it automatically for me? Maybe like database seeding?

date column not being returned as string by drizzle

Hello, I have the following table: ```TypeScript export const productSnapshot = pgTable("product_snapshot", { productId: text("product_id").notNull().references(() => product.id), // You can use { mode: "bigint" } if numbers are exceeding js number limitations...

Studio issue with ::

Here's an interesting scenario. I'm using sveltekit and supabase. I was able to get everything set up fine. established three tables - introspect worked great - generated the schema - no issues. Loaded up another 35 tables - and now I'm running into this error when I try to pull up studio: node:internal/process/promises:289 triggerUncaughtException(err, true /* fromPromise */); ^...