romeerez / orchid-orm

Orchid ORM
https://orchid-orm.netlify.app/
MIT License
494 stars 14 forks source link

[bug] `jsonPathQueryFirst` with `equals` #344

Open bingtsingw opened 2 months ago

bingtsingw commented 2 months ago

https://orchid-orm.netlify.app/guide/json.html#jsonpathqueryfirst

In the latest version, using .jsonPathQueryFirst with .equals like this broke sql, but it has no type error.

// using it in `where`
const filtered = await db.table.where((q) =>
  // filtering records by the `name` property from the `data` JSON column
  q.get('data').jsonPathQueryFirst('$.name').equals('name'),
);

We can use it like contains.

const filtered = await db.table.where((q) =>
  // filtering records by the `name` property from the `data` JSON column
  q.get('data').jsonPathQueryFirst('$.name', (t) => t.string()).equals('name'),
);

Maybe we need to update the type check and docs to use (t) => t.string(). Or maybe we need to support.jsonPathQueryFirst('$.name').equals('name')` like previous versions.

romeerez commented 2 months ago

It's a regression, equals and other basic operations shouldn't require a type, I'll fix it in a few days, and temporary please add the (t) => t.string().