Skip to content

Commit d735d7b

Browse files
tomasreimersoguimbal
authored andcommitted
feat: add a sizable equivalent type
1 parent 7de1425 commit d735d7b

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

src/interfaces.ts

+3
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,9 @@ export interface ISchema {
342342
/** Register a simple type, which is equivalent to another */
343343
registerEquivalentType(type: IEquivalentType): IType;
344344

345+
/** Register a simple type, which is equivalent to another */
346+
registerEquivalentSizableType(type: IEquivalentType): IType;
347+
345348
/** Get an existing type */
346349
getType(name: DataType): IType;
347350

src/schema/schema.ts

+8
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,14 @@ export class DbSchema implements _ISchema, ISchema {
394394
registerEquivalentType(type: IEquivalentType): IType {
395395
const ret = new EquivalentType(type);
396396
this._registerType(ret);
397+
398+
return ret;
399+
}
400+
401+
registerEquivalentSizableType(type: IEquivalentType): IType {
402+
const ret = new EquivalentType(type);
403+
this._registerTypeSizeable(ret.primary, (_) => ret);
404+
397405
return ret;
398406
}
399407

src/tests/custom-types.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -96,5 +96,17 @@ describe('Custom types', () => {
9696
expectQueryError(() => none(`SELECT 'throw'::custom`), /Nope/);
9797
expectQueryError(() => none(`SELECT 'whatever'::custom`), /invalid input syntax for type custom/);
9898
expectQueryError(() => none(`SELECT 42::custom`), /cannot cast type integer to custom/);
99+
});
100+
101+
it('can register custom type with length', () => {
102+
db.public.registerEquivalentSizableType({
103+
name: 'vector',
104+
equivalentTo: DataType.text,
105+
isValid(val: string) {
106+
return true;
107+
}
108+
});
109+
110+
none(`CREATE TABLE "test" ("embedding" vector(1536) NOT NULL)`);
99111
})
100112
});

0 commit comments

Comments
 (0)