Skip to content

Commit

Permalink
feat: add a sizable equivalent type
Browse files Browse the repository at this point in the history
  • Loading branch information
tomasreimers authored and oguimbal committed Oct 11, 2024
1 parent 7de1425 commit d735d7b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions src/schema/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
12 changes: 12 additions & 0 deletions src/tests/custom-types.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)`);
})
});

0 comments on commit d735d7b

Please sign in to comment.