Skip to content

Commit 0f7fe20

Browse files
authored
Add listOfCodec example (#2182)
2 parents 4dfca1e + ba94b21 commit 0f7fe20

File tree

1 file changed

+24
-0
lines changed
  • grafast/website/grafast/step-library/dataplan-pg/registry

1 file changed

+24
-0
lines changed

grafast/website/grafast/step-library/dataplan-pg/registry/codecs.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,30 @@ const forumCodec = recordCodec({
138138

139139
- `identifier` - the database name for this type
140140

141+
### Example
142+
143+
For example, in this hypothetical E-commerce scenario, `listOfCodec` is used
144+
in combination with the `$pgSelect.placeholder()` method to return a SQL
145+
expression that allows the transformed list of `$orderIds` to be referenced
146+
inside the step for selecting the associated order items.
147+
148+
```ts
149+
const $orders = orders.find({
150+
customer_id: context().get("customerId"),
151+
});
152+
153+
const $orderIds = applyTransforms(each($orders, ($order) => $order.get("id")));
154+
155+
const $orderItems = registry.pgResources.order_items.find();
156+
157+
$orderItems.where(
158+
sql`${$orderItems}.order_id = ANY (${$orderItems.placeholder(
159+
$orderIds,
160+
listOfCodec(TYPES.uuid),
161+
)})`,
162+
);
163+
```
164+
141165
## rangeOfCodec(innerCodec, name, identifier)
142166

143167
`rangeOfCodec` returns a new codec that represents a range of the given

0 commit comments

Comments
 (0)