drizzle-team / drizzle-team/drizzle-orm
Drizzle Studio isn't compatible with custom type
- Dominant language
- TypeScript
- Stars
- 35.8k
- Forks
- 1.6k
- Avg merge
- 2d 7h
- Merged PRs (30d)
- 4
Description
I've implemented a custom type around Postgres' UUID type which encodes it into a URL-friendly string. Unfortunately, Drizzle Studio doesn't seem to be fully compatible with custom types. While it displays the encoded version of the UUID, I can only filter based the original UUID. Also, when navigating between relations or inserting/updating rows I get the following error:
> invalid input syntax for type uuid: "ast_2VDCabaqTSZOiEdUbfNL8"
Note: the string from the error decodes to `018d7554-8b9c-7be4-8b12-31f8acc59aa6`.
My custom type looks as follows where `uuidToObjectId` and `objectIdToUuid` can basically be any functions that convert the UUID to/from a different string deterministically:
```ts
import { customType } from "drizzle-orm/pg-core";
export type ObjectIdTypeValues = {
data: string;
driverData: string;
};
export type ObjectIdOptions = {
prefix: string;
};
export const objectId = (name: string, options: ObjectIdOptions) =>
customType({
dataType() {
return `uuid`;
},
fromDriver(value: string): string {
return uuidToObjectId(options.prefix, value);
},
toDriver(value) {
return objectIdToUuid(value);
},
})(name);
```
#### Versions
drizzle-kit@0.20.13
drizzle-orm@0.29.1
pg@8.11.3
Contributor guide
Assessment
This issue has not been assessed yet.