jawj / zapatos

Zero-abstraction Postgres for TypeScript: a non-ORM database library
https://jawj.github.io/zapatos/
Other
1.3k stars 46 forks source link

order by result of a lateral join using the select interface? #160

Closed jcoveney-anchorzero closed 3 months ago

jcoveney-anchorzero commented 1 year ago

let's say I have two tables

table_a, columns: the_id

and

table_b, columns: the_id, name

and there is a foreign key relationship between table_a and table_b, though that doesn't really affect the following query I suppose!

let's say I have a query as follows

zapatosDb
      .select('table_a', zapatosDb.all, {
        lateral: {
          table_b: zapatosDb.selectExactlyOne(
            'table_b',
            {
              the_id: zapatosDb.parent('the_id'),
            },
          ),
        },
      })
      .run(context.pool);

my goal is to sort this by table_b.name....as far as I know, it's not possible to do this, at least, I haven't figured out a syntax to do it. is this currently possible? or a limitation of the select API?

thank you very much

jawj commented 1 year ago

Sorry for the slow reply.

This is a limitation of the API, which would be really good (but as far as I can see not at all easy) to fix.

There is a workaround, as discussed in #62, but it may not be fast enough for you.