drizzle-team / drizzle-team/drizzle-orm

[FEATURE]: Support custom types for createSelectSchema/createInsertSchema

Open
#5,692 1 comment 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

### Feature hasn't been suggested before.

- [x] I have verified this feature I'm about to request hasn't been suggested before.

### Describe the enhancement you want to request

I have a custom type to go between a postgres timestamp type in the DB and a Temporal.Instant in my code:
```
const instantTimestamptz = customType<{ data: Temporal.Instant; driverData: string; }>({
dataType() { return 'timestamp with time zone'; },
fromDriver(value) { return Temporal.Instant.from(value); },
toDriver(value) { return value.toString(); },
});
```

I then have zod codec to handle serializing/deserializing these `Temporal.Instant` values, which I'll call `temporalInstantCodec`. Then when I run createInsertSchema for the `entities` table, where `entities` has a instantTimestamptz field time, I have to do `createInsertSchema(entities, { time: temporalInstantCodec.optional() })` or else it fails because createInsertSchema doesn't know what to with my custom type. Is there some way to not have to write this out for each custom type when running createSelectSchema or createInsertSchema?

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.