[FEATURE]: pg JSONb Type insertion
Describe what you want
in pg-core/columns/jsonb.d.ts
export type PgJsonbBuilderInitial<TName extends string> = PgJsonbBuilder<{
name: TName;
dataType: 'json';
columnType: 'PgJsonb';
data: unknown;
driverParam: unknown;
enumValues: undefined;
}>;
Can we somehow make this Generic? I would like to specify the data type. We use this for prototyping our apps.
The type safety would come in very handy, and I would rather not hack together my own type interface.
I believe .$type<..>() allows you to do this on column definition.
You can read more about it in the second section of the json column type https://orm.drizzle.team/docs/column-types/pg#jsonb and the dedicated section about it https://orm.drizzle.team/docs/column-types/pg#customizing-column-data-type
Example from the docs
// will be infered as { foo: string }
jsonb: jsonb('jsonb').$type<{ foo: string }>();
// will be infered as string[]
jsonb: jsonb('jsonb').$type<string[]>();
// won't compile
jsonb: jsonb('jsonb').$type<string[]>().default({});
Use PgJsonbBuilder instead of PgJsonbBuilderInitial. You can also make your own abstraction:
type JsonbBuilderWithData<TName extends string, TData as Record<string, any>> = PgJsonbBuilder<{
name: TName;
dataType: 'json';
columnType: 'PgJsonb';
data: TData;
driverParam: TData;
enumValues: undefined;
}>