Drizzle Studio isn't compatible with custom type

Author: nilsmehlhornCreated Feb 5, 2024Updated Sep 30, 2026
Labelsbugdrizzle/studio

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:

typescript
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<ObjectIdTypeValues>({
    dataType() {
      return `uuid`;
    },
    fromDriver(value: string): string {
      return uuidToObjectId(options.prefix, value);
    },
    toDriver(value) {
      return objectIdToUuid(value);
    },
  })(name);

Versions

[email protected] [email protected] [email protected]

Source: drizzle-team/drizzle-orm