tusken icon indicating copy to clipboard operation
tusken copied to clipboard

Add `db.list` for getting multiple rows by primary key

Open aleclarson opened this issue 3 years ago • 2 comments

We can't just let db.get take an array of keys, because we want to support array-based keys.

// Order is guaranteed to match the `userIds` array.
const rows = await db.list(t.user, userIds)

This is not simply a shorthand method for db.select(...).where(({ pk }) => pk.in(array)), because the result order is guaranteed to match the input array.

Note: When using this method, the primary key will always be included in the resulting objects.

aleclarson avatar Sep 12 '22 19:09 aleclarson

We can probably use WITH ORDINALITY to achieve this without JS massaging 👀

aleclarson avatar Sep 20 '22 15:09 aleclarson

We can't just let db.get take an array of keys, because we want to support array-based keys.

Now that we have runtime type information for columns, this isn't a constraint anymore. 👀

aleclarson avatar Oct 07 '22 23:10 aleclarson