From 21cf68408cd41c6e887d4464fa7c04ad15c49f08 Mon Sep 17 00:00:00 2001 From: Harry Buisman Date: Wed, 25 Sep 2024 09:03:14 +1000 Subject: [PATCH 1/2] Add listOfCodec example --- .../dataplan-pg/registry/codecs.md | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/grafast/website/grafast/step-library/dataplan-pg/registry/codecs.md b/grafast/website/grafast/step-library/dataplan-pg/registry/codecs.md index b8572a5339..76034a9222 100644 --- a/grafast/website/grafast/step-library/dataplan-pg/registry/codecs.md +++ b/grafast/website/grafast/step-library/dataplan-pg/registry/codecs.md @@ -138,6 +138,30 @@ const forumCodec = recordCodec({ - `identifier` - the database name for this type +### Example + +For example, in this hypothetical E-commerce scenario, `listOfCodec` is used +in combination with the `$pgSelect.placeholder` method to return a SQL +expression that allows the transformed list of `$order_ids` to be referenced +inside the step for selecting the associated order items. + +```ts +const $orders = orders.find({ + customer_id: context().get("customerId"), +}); + +const $order_ids = applyTransforms(each($orders, ($order) => $order.get("id"))); + +const $order_items = order_items.find(); + +$order_items.where( + sql`${$order_items}.order_id = ANY (${$order_items.placeholder( + $order_ids, + listOfCodec(TYPES.uuid), + )})`, +); +``` + ## rangeOfCodec(innerCodec, name, identifier) `rangeOfCodec` returns a new codec that represents a range of the given From 6d7efdf1456166820a87e8e4679eaa5f8fc36e48 Mon Sep 17 00:00:00 2001 From: Benjie Date: Wed, 25 Sep 2024 12:55:28 +0100 Subject: [PATCH 2/2] Update grafast/website/grafast/step-library/dataplan-pg/registry/codecs.md --- .../step-library/dataplan-pg/registry/codecs.md | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/grafast/website/grafast/step-library/dataplan-pg/registry/codecs.md b/grafast/website/grafast/step-library/dataplan-pg/registry/codecs.md index 76034a9222..8f08d14c02 100644 --- a/grafast/website/grafast/step-library/dataplan-pg/registry/codecs.md +++ b/grafast/website/grafast/step-library/dataplan-pg/registry/codecs.md @@ -141,8 +141,8 @@ const forumCodec = recordCodec({ ### Example For example, in this hypothetical E-commerce scenario, `listOfCodec` is used -in combination with the `$pgSelect.placeholder` method to return a SQL -expression that allows the transformed list of `$order_ids` to be referenced +in combination with the `$pgSelect.placeholder()` method to return a SQL +expression that allows the transformed list of `$orderIds` to be referenced inside the step for selecting the associated order items. ```ts @@ -150,13 +150,13 @@ const $orders = orders.find({ customer_id: context().get("customerId"), }); -const $order_ids = applyTransforms(each($orders, ($order) => $order.get("id"))); +const $orderIds = applyTransforms(each($orders, ($order) => $order.get("id"))); -const $order_items = order_items.find(); +const $orderItems = registry.pgResources.order_items.find(); -$order_items.where( - sql`${$order_items}.order_id = ANY (${$order_items.placeholder( - $order_ids, +$orderItems.where( + sql`${$orderItems}.order_id = ANY (${$orderItems.placeholder( + $orderIds, listOfCodec(TYPES.uuid), )})`, );