diff --git a/src/interfaces.ts b/src/interfaces.ts index bad80e1..9c89d46 100644 --- a/src/interfaces.ts +++ b/src/interfaces.ts @@ -342,6 +342,9 @@ export interface ISchema { /** Register a simple type, which is equivalent to another */ registerEquivalentType(type: IEquivalentType): IType; + /** Register a simple type, which is equivalent to another */ + registerEquivalentSizableType(type: IEquivalentType): IType; + /** Get an existing type */ getType(name: DataType): IType; diff --git a/src/schema/schema.ts b/src/schema/schema.ts index b8d5940..9441823 100644 --- a/src/schema/schema.ts +++ b/src/schema/schema.ts @@ -394,6 +394,14 @@ export class DbSchema implements _ISchema, ISchema { registerEquivalentType(type: IEquivalentType): IType { const ret = new EquivalentType(type); this._registerType(ret); + + return ret; + } + + registerEquivalentSizableType(type: IEquivalentType): IType { + const ret = new EquivalentType(type); + this._registerTypeSizeable(ret.primary, (_) => ret); + return ret; } diff --git a/src/tests/custom-types.spec.ts b/src/tests/custom-types.spec.ts index b47e54b..9afbb9d 100644 --- a/src/tests/custom-types.spec.ts +++ b/src/tests/custom-types.spec.ts @@ -96,5 +96,17 @@ describe('Custom types', () => { expectQueryError(() => none(`SELECT 'throw'::custom`), /Nope/); expectQueryError(() => none(`SELECT 'whatever'::custom`), /invalid input syntax for type custom/); expectQueryError(() => none(`SELECT 42::custom`), /cannot cast type integer to custom/); + }); + + it('can register custom type with length', () => { + db.public.registerEquivalentSizableType({ + name: 'vector', + equivalentTo: DataType.text, + isValid(val: string) { + return true; + } + }); + + none(`CREATE TABLE "test" ("embedding" vector(1536) NOT NULL)`); }) });