Drizzle Team

DT

Drizzle Team

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

Join

Inserting into columns of type Enum

Hi, any code written here was done in TypeScript and the database I’m connecting to is AWS Aurora PostgreSQL. (I’m on mobile, sorry about the format) I’ve defined an enum as follows:...

Extracting literal values from Drizzle enums

I'm trying to make a zod enum schema from the values of a Drizzle enum I've created. I've looked through several other posts trying to do the same thing and it's unclear to me how to do this, particularly for mysqlEnum. The most promising way came from inspecting the enums at runtime. I found that I could access the values, just as I wanted, at myEnum.config.enumValues. The only problem is that Typescript declares config protected and I get type errors.

`where` within `where`? confused about complex query

```ts export const posts = pgTable('posts', { id: uuid('id').defaultRandom().primaryKey(), userId: char('user_id', { length: 17 }).notNull().references(() => users.id), description: text('description'),...

IS IT POSSIBLE: to use a relation field in a where clause?

Anyone knows if it's possible to have a nested relation in a where clause?

Is there a way to save the generated response Type from a query?

I see that when you hover over the type for the response of a query, you can see what data will be returned. Is there a way to extract, or save that Type somehow, so I can use it elsewhere?

Ordering by relation in relational query

I am trying to sort on an attribute of a relation using the relational queries api, but as far as I can tell it is not supported? Example: ``` await db.query.city.findMany({...

Nested Schema, Helper Functions

Hi, I am new to Drizzle. 1. I have the following User schema and I was wondering is there any way for combining some columns in one type, in this case I want to merge all profile fields into one type. const User = pgSchema(configService.postgres.schema).table('users', {...

types from nested relational queries

wondering what the type of user is? ```ts async function getUserWithSettings(steamId: string): Promise<User> { const user = await db.query.users.findFirst({ where: (user, { eq }) => eq(user.steamId, steamId),...

drizzle-kit@win still not working. What am I doing wrong?

/Users/alexanderniebuhr/Developer/Projects/alexanderniebuhr_blog/packages/db/drizzle.config.ts ``` import type { Config } from 'drizzle-kit' export default {...

SQLITE_ERROR: near "ilike": syntax error

I've currently setup an my SQL query as follows: ```ts export const getObservationsByUserId = async ( db: LibSQLDatabase,...

Composite Primary Key from Foreign Keys

```ts export const userItemsHas = pgTable('user_items_has', { postId: uuid('post_id').references(() => posts.id), userItemId: serial("user_item_id").references(() => userItems.id), },(table) => {...

Introspect command failing

I'm setting up Drizzle for the first time, I'm trying to get the introspect command to run with mysql / planetscale. When I run introspect I get "Expected undefined or a fully resolved URL string to be returned for the "responseURL" from the "drizzle-kit/loader.mjs 'load'" function but got instance of String.". Has anyone seen this one before? package.json...

Error while push:sqlite after update

I am getting this error while using
npx drizzle-kit push:sqlite
npx drizzle-kit push:sqlite
here is drizzle.config.json ``` {...

What do i do when introspection gives an error?

drizzle-kit introspect:pg --config drizzle.config.ts drizzle-kit: v0.19.1 drizzle-orm: v0.27.0 length: 352, severity: 'ERROR',...

introspect schema generation forgets import

introspect schema generation doesn't add import for smallint

.get() returning only one element

Hey I am using DrizzleORM with Turso and I am having a problem thath this query return only one element, not a list of objects. How? export async function GET(req) { const page = req.query?.page ? parseInt(req.query.page) : 1; const limit = req.query?.limit ? parseInt(req.query.limit) : 10; ...

Cursor pagination on table using UUID as primary key

Hello everybody! We've switched from Prisma and are trying to implement cursor pagination. It turns out our tables are using UUID instead of integers as primary keys. I couldn't find anything on Drizzle's documentation about it. Even Google search didn't return a result. Could someone here provide guidance? Thank you very much!

createdAt and expiresAt defaults

Is this the best way?
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
expiresAt: timestamp('expires_at', { withTimezone: true }).default(sql`(now() + interval '7 days')`),
createdAt: timestamp('created_at', { withTimezone: true }).defaultNow(),
expiresAt: timestamp('expires_at', { withTimezone: true }).default(sql`(now() + interval '7 days')`),
...

Delete using pg query in drizzle

Hello guys, is there any way to implement following query in drizzle? ``` DELETE FROM CustomerVehiclePart AS a USING CustomerVehicle AS b, Vehicle AS c...

Using postgres connection for cockroachdb

Hello everyone, would it be possible to use postgres for cockroachdb? Or is there maybe something that I need to change in order for it to be compatible?