customType and it's internal types - implementing tsid

I would like to realize a tsid support within my project with drizzle. It's similar to snowflake and its stored in the db as an bigint that with the help of a little library get's converted to a crockford's base32 string.
import { customType } from 'drizzle-orm/pg-core';
import { TSID } from 'tsid-ts';

export const tsidType = customType<{
data: string;
driverData: bigint;
}>({
dataType(config) {
return `bigint`;
},
fromDriver(value: bigint): string {
// at his point the typeof value is string
return new TSID(BigInt(value)).toString();
},
toDriver(value: string): bigint {
return TSID.fromString(value).toBigInt();
},
});
import { customType } from 'drizzle-orm/pg-core';
import { TSID } from 'tsid-ts';

export const tsidType = customType<{
data: string;
driverData: bigint;
}>({
dataType(config) {
return `bigint`;
},
fromDriver(value: bigint): string {
// at his point the typeof value is string
return new TSID(BigInt(value)).toString();
},
toDriver(value: string): bigint {
return TSID.fromString(value).toBigInt();
},
});
my converter is workgin smoothly but how could i control within the fromDriver that the value passed is really a bitint and not a string? what do i wrong? I've seen that for bigint itself the are different modes but this options are not available for customTypes as i see
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server