Drizzle Team

DT

Drizzle Team

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

Join

Type Hinting $inferSelect

Hi Drizzle Team, I have the following tables set up with Postgres and Drizzle. There is a reviews table with an enum status field. When the status is assigned, the userId field is non-null, otherwise it's null. Is there a way to typehint reviews.$inferSelect such that it adheres to the type logic above?...

drizzle postgis geometry always geometry(point)

Hello, i am currently testing out the basic postGis support and it would be nice if i can get it working as desired... Basically i want point/pointZ and linestring/linestringZ... The 0.31.0 release added geometry from the PostgreSQL PostGIS extension, however, as indicated it currently only supports type: "point". But the release also states, that we can specify any other string to use some other type... ```...

NodeNext Module Resolution Causes `drizzle-kit generate` to fail.

Hiiiiii 👋 , I'm having trouble using the kit with "moduleResuolution": "NodeNext". Basicaly that means that in my typescript files I import modules like the following: File tree: ```tree src/schema...

Trouble assigning enum as input for sqlite database.

I have an enum in typescript ``` export enum InsuranceStatus { INSURANCE_NOT_REQUIRED = "insurance_not_required",...

Use results of a column to pass where conditions elsewhere in the query?

I have a field that stores filters that I parse into the SQL conditions for a where clause. Or at least, that's the goal. That field is in my views table. Is it possible to pass the result of that field in views into a nested where condition? ...

Is there a way to check/constrain a column?

I am building a Top 25 college football voting system for my website and I keep going back and forth on how to structure everyone 🫠 🙃 yay analysis paralysis. Anyways... I have been trying to figure out what is the "best" way to associate a ranking to points (a first place vote gets 25 points down to 1 point for a 25th place vote). I think I have figured out a decent way to accomplish this by basically making each rank in the ballot a row in the table. However, is there a way to make sure that the rank and points are 1-25? I want to then compile another table that calculates all the votes each team got and how many points they got for a particular week in the season. Also, open to any other suggestions on the best way to do this....
No description

How to achieve the same in drizzle ORM ?

```sql SELECT 'TOTAL_COURSES' AS name , COUNT(id) FROM course WHERE deleted_at IS NULL UNION ALL SELECT 'PUBLISHED_COURSES' AS name, COUNT(id) FROM course WHERE is_published = true AND deleted_at IS NULL UNION ALL...

How to properly handle/distinguish between errors

I'm using Drizzle ORM with a postgres. I'd like to distinguish between certain errors that occur when inserting / querying the database. In my current case, I would like to know specifically when my insertion fails as a result of a user not existing in the database....

Not enough information to infer relation with self-one-To-Many relation

Hello guys ! Thank for this community ! I'm looking everywhere to solve this. Got a schema with a question which can have parent question (one parentQuestion) and many child questions (subquestions) : ```js export const questionSchema = pgTable('questions', {...

Derived Values

Hi, Just wanted to know if there is a possible way to create derived values based on another field's value (maybe using customTypes or defaultFn ?)...

Drizzle Kit: How to introspect Postgres DB without creating relations in generated schema?

I've got a monster of target database, with relations all over the show. I'm not interested in have a fully representative schema, and only want to perform read operations against a subset of tables. Using the tablesFilter doesn't work as the relations keep wanting to exist, even though the related tables aren't in my tablesFilter. Can I disable this feature completely?

SQLITE_BUSY: database is locked

I'm seeing this error after increasing the amount of concurrent write operations I was performing. Has anyone else had to deal with this? (better-sqlite3 on node.js)...

Can't migrate on vercel postgres

Hello, I'm having issues connecting to Vercel Postgres at the moment. Does anyone else face the same issue? code: 'CONNECT_TIMEOUT', errno: 'CONNECT_TIMEOUT', ...

Need a sanity check on my idea for cursor pagination helper

I wanna create a helper to manage cursor-based pagination with Drizzle. To create a cursor your select query needs to contain the columns on which your data is ordered - so you need to include those columns in select. But my concern is that that may cause collisions say ```ts...

Where clause dependent on with relation

```typescript const news = await ctx.db.query.newsTable.findMany({ limit: 20, offset: 20 * input.page, orderBy: (newsTable, { desc }) => [desc(newsTable.createdAt)],...

Trying to get Drizzle, Lucia and Vercel-postress to work together (no changes to schema detected)

Hi! I'm new to drizzle and lucia and am just having a problem setting up both with vercel-postgres: I'm creating an adapter for Lucia in my schema.ts: export const createAdapter = (db: PgDatabase<any, any, any>) => new DrizzlePostgreSQLAdapter(db, sessionTable, userTable);...

Drizzle kit generating migrations but not migrating, claiming all remains the same

Can anybody help? I changed my schema to add 1 column to 2 new tables. I hadn’t updated kit in a long while, which I had to do. After all the updating, migration files show these 2 new columns. And when I run drizzle generate it works fine and generates teh migrations files but MIgrate claims db is teh same and does nothing. shoudl I go for push, instead? Thanks in advance...
Solution:
Solved by deleting migrations folder and table, using push to bypass migrations, changing back the schema and generating and migrating at long last. Ufff! 😄

could someone show me the way to do this query using drizzle

I have a query with a one to many join but I don't seem to be able to array agg and group by to stop the rows being produced multiple times, how could I do this?

How to make all relations be deleted when user is removed?

Hello! I'm trying to get my head around for table relations, and just can't seem to get this figured out. I've table for users, and user sessions. When I'm trying to delete a user, postgres throws error, that delete violates foreign key constraint on sessions. What might be proper way to define this relations? Below is my schema. ```typescript export const users = createTable(...

Many to many flatten response

I'm struggling to understand why does drizzle work this way and why there isnt an easy way to flatten the response structure. I have 3 tables, Profile, Interest and Language. I also have 2 other join tables, ProfileInterest and ProfileLanguage. As you may have noticed, I have a many-to-many relationship between Profile and Interest and between Profile and Language. All 5 tables are in place (3 "models" and 2 join tables). I also have all the relations created and everything works as expected. To query for a specific profile including its' interests and languages I run the following. ``` db.query.Profile.findFirst({ where: eq(Profile.id, input.id),...