romeerez/orchid-orm

Infer custom keys in group method.

Closed this issue · 1 comments

In the following example I am able to get month inferred inside the order method but not in the group method

 db.orders.select({month: db.orders.sql<number>`extract(month from "createdAt")`}).order('month').group('month')

I published a fix for this, and now grouping by selected SQL is supported.

I noticed that the month is returned as a string, you can parse it to a number in such way:

      const q = db.orders.select({
        month: db.orders.sql<string>`extract(month from "createdAt")`.type((t) =>
          t.string().parse(parseInt),
        ),
      }).group('month');