drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Track constraints in the type system

Open
#2,536 0 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
TypeScript
Stars
35.8k
Forks
1.6k
Avg merge
2d 7h
Merged PRs (30d)
4

Description

### Describe what you want

It would be a nice to have for strict type checking

```ts
import * as DP from "drizzle-orm/pg-core";

export const Participant = DP.pgTable(
"participants",
{
id: DP.uuid("id").primaryKey(),
name: DP.varchar("name", { length: 500 }).notNull(),
surname: DP.varchar("surname", { length: 500 }).notNull(),
email: DP.varchar("email", { length: 100 }).$type().unique("email_unique").notNull(),
bio: DP.text("bio").notNull(),
},
tb => ({ uniq: DP.primaryKey({ columns: [tb.id], name: "no_homonymies" }) }),
);
export type ParticipantInsert = DO.InferInsertModel;
export type Constraints = (typeof Participant)["_"]["config"]["contraints"];
// ^ ['email_unique', 'no_homonymies', '']

```

Such that in case of insert/update I can discriminate between different constraints and have TS validating my logic

Would this be possible and, hopefully, easy to implement?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.