ozone-team / surrealised

Just another SurrealDB Client
8 stars 0 forks source link

`query.orderBy` throws `not assignable` type on field #1

Open ThatOneCalculator opened 5 months ago

ThatOneCalculator commented 5 months ago

The line query.orderBy({ field: "createdAt", direction: "DESC" });

throws a TS error on field:

Type '"createdAt"' is not assignable to type '"ASC" | "DESC"'.ts(2322)

but according to https://github.com/ozone-team/surrealised?tab=readme-ov-file#orderbyfields-orderbyfield , field should be the db field and only direction should be enforced as "DESC" | "ASC".

ThatOneCalculator commented 5 months ago

On further inspection, this seems to be implemented incorrectly:

https://github.com/ozone-team/surrealised/blob/7c203342d0a94c5356421f7c72c438255fc797e7/src/SurrealQueryBuilder.ts#L229-L235

According to https://surrealdb.com/docs/surrealdb/surrealql/statements/select#sort-records-using-the-order-by-clause , those should actually be ORDER BY fieldname, fieldname, COLLATE direction, but the query builder doesn't ever add COLLATE.