diff --git a/packages/ucast-prisma/src/interpreters.ts b/packages/ucast-prisma/src/interpreters.ts index 7c81c27..8ea6629 100644 --- a/packages/ucast-prisma/src/interpreters.ts +++ b/packages/ucast-prisma/src/interpreters.ts @@ -11,6 +11,9 @@ import { export const eq = op("equals"); export const ne = op("not"); +export const startswith = op("startsWith"); +export const endswith = op("endsWith"); +export const contains = op("contains"); export const lt = op("lt"); export const lte = op("lte"); export const gt = op("gt"); @@ -84,6 +87,8 @@ function op(name: string): PrismaOperator> { (options as translateOpts)?.translate || // NOTE(sr): The 'as' here feels wrong, but I couldn't make it work otherwise. ((...x: string[]) => [x[0], x[1]]); const [tbl, field] = translate(...condition.field.split(".")); - return query.addCondition(tbl, { [field]: { [name]: condition.value } }); + return query.addCondition(tbl, { + [field]: { [name]: condition.value }, + }); }; } diff --git a/packages/ucast-prisma/tests/interpreters.test.ts b/packages/ucast-prisma/tests/interpreters.test.ts index 7bda693..572751d 100644 --- a/packages/ucast-prisma/tests/interpreters.test.ts +++ b/packages/ucast-prisma/tests/interpreters.test.ts @@ -7,12 +7,18 @@ describe("Condition interpreter", () => { describe("field operators", () => { const interpret = createPrismaInterpreter("table", { interpreters }); - it('generates query with `equals operator for "eq"', () => { + it('generates query with `equals` operator for "eq"', () => { const condition = new FieldCondition("eq", "table.name", "test"); const f = interpret(condition); expect(f).toStrictEqual({ name: { equals: "test" } }); }); + it('generates query with `startsWith` operator for "startswith"', () => { + const condition = new FieldCondition("startswith", "table.name", "test"); + const f = interpret(condition); + expect(f).toStrictEqual({ name: { startsWith: "test" } }); + }); + it('generates query with `not` operator for "ne"', () => { const condition = new FieldCondition("ne", "table.name", "test"); const f = interpret(condition);