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 handle initial undefined state

Hey guys! I need some help on something that is probably trivial to a lot of you. I am using the useLiveQuery hook to get and then display data on a screen in my app (it's a todo app and i'm essentially getting the list data to be able to display) . The problem is that whenever I want to access said data, I ALWAYS have to use the optional selector to handle the initial undefined state. So my code is FILLED with a whole bunch of ? marks... How do you guys avoid having to do this?? I've used React Query before and the nice thing with them is that their useQuery hook returns a loading state that I can use to handle the initial undefined state of data and then display it, but I don't have that kind of feature with Drizzle....

Constraint does not exist when running migration

This is happening because one of my tables was looking like this: ```ts export const profiles = pgTable('profiles', { userId: uuid('user_id').references(() => users.id, { onDelete: 'cascade' }); ... rest of the columns...

Docker build error with sveltekit

Hello everyone, whenever I try to docker build my sveltekit app that uses drizzle I get the following error: ``` 0.187 > vite build
0.187 ...

serial primary key start from

Hi, I'm wondering is there a way to say to the primary key, from which value to start? I'm using postgress
id: serial('id').primaryKey()
id: serial('id').primaryKey()
...

Multiple exports with the same name

Drizzle is telling me ERROR: Multiple exports with the same name "lessonsRelations" but there's only one export as seen in the screenshot. How can I fix this? No idea what's happening....
No description

Reusable values for `with` property in findFirst and findMany

This works as expected: const result = await db.query.users.findFirst({ with: { usersMeta: true }}); I want to achieve something like this: ```ts...

Identifying error due to Serializable isolation failure in postgres

I have a transaction with serializable isolation level
db.transaction((tx) => {....}, {isolationLevel: "serializable"})
db.transaction((tx) => {....}, {isolationLevel: "serializable"})
...

numeric as number instead of a string

In a table I have numerals: numeric().array().notNull() Now while I know that internally the DB treats numeric as strings, on the TS side of things I would rather deal with it as a number...

Pull from an existing schema, but skip in migrations?

Hey all, I'm trying to do something a bit weird. I have a Keycloak instance that I am using to manage user identity, and have the schema stored in my postgres database in the "keycloak" schema. I would love to be able to reference user_entity ids in my public schema (managed by drizzle). I was able to (mostly) pull the keycloak schema using drizzle kit pull, but then, when I try to create migrations, it attempts to create all of the existing keycloak schema (which itself is managed by another migration tool).
Is there a way to pull in an existing schema, but to skip it when it comes to migrations?
Essentially, I just want to be able to build relations, and ideally create row-level security policies. thanks!...

Place relations into seperate file?

When I put relations into it's own file such as relations.ts and also have schema.ts and then do... ```ts import * as relations from '$lib/db/relations.js';...

Grant Privileges to Role

I created roles in my project using the pgRole() in order to enable RLS on my database. After running the migration my user has no privileges on my tables and cannot access them. How can I grant all privileges to my role?

How can I skip columns I don't want to have generated?

I'm using drizzle-seed (btw, there's no tag yet in the Discord help space) and I don't want some columns generated (default). How can I specify this? Currently, the script fails with column with type xata_file is not supported for now. Even though the table that has a count > 0 has no such columns....

I wonder I don't get reply_to_id in my tables after I migrate and push

```jsx export const Comment = pgTable( "comments", { id: serial("id").primaryKey(),...
No description

How to deal with initial undefined data

Hi guys! I am using the useLiveQuery hook in my Expo app to display data in the UI. It works great...except for one thing. When I go into a page that uses it, I get undefined errors. My understanding is that initially the data would be undefined as Drizzle is still fetching it and once it has fetched it, the data would of been "initialized" and ready to be used in the UI. To get around this, I use optional chaining as you can see in my example below. But this gets really annoying to have to write all the time... I used to use React Query to fetch data and their hook provides a nice isLoading state that I usually used to say if the data is still loading, return null or a loading state. But with Drizzle's useLiveQuery, I don't have access to a similar state. ...

Struggling with Complex Query Filters in Drizzle: Need Help with Global and Specific Conditions

Hey everyone, I have a query in Drizzle where I'm trying to create a view with multiple filters, but I'm stuck trying to figure out how to combine them effectively. This part of the query works fine:...

Need advice on how to work with timezones, please

Hello anyone, The problem is that in production I cannot save date in UTC. I got date from the client (frontend) in this format 2025-01-16T23:10....

this.client.migrate is not a function

Here's my drizzle.config.ts: ```ts import { defineConfig } from 'drizzle-kit'; if (!process.env.DATABASE_URL) throw new Error('DATABASE_URL is not set'); ...

I'm receiving error when trying to do a self referencing

I saw somewhere in this discord this self referencing coz this also receives type error too replyToId: integer("reply_to_id").references(() => Comment.id), ...
No description

Error: D1_ERROR: too many SQL variables at offset 460: SQLITE_ERROR

Hey there! Getting the following error ``` Error: D1_ERROR: too many SQL variables at offset 460: SQLITE_ERROR at D1DatabaseSessionAlwaysPrimary._sendOrThrow (cloudflare-internal:d1-api:129:19)...

[Solved] applying migrations...error: type "application_status" does not exist

Hi! I am getting this error when trying pgEnum ```ts schema.ts ...
Next