1import type * as sdb from "@distilled.cloud/aws/simpledb";
2import type * as Effect from "effect/Effect";
3import * as Binding from "../../Binding.ts";
4import type { RuntimeContext } from "../../RuntimeContext.ts";
5import type { Domain } from "./Domain.ts";
6
7export interface SelectRequest extends Omit<
8 sdb.SelectRequest,
9 "SelectExpression"
10> {
11 /**
12 * The select expression (`select output_list from domain [where ...]`).
13 *
14 * Pass a function to receive the domain's resolved physical name — useful
15 * because generated domain names are not known until deploy time:
16 * `(domain) => \`select * from \\\`${domain}\\\`\``.
17 */
18 SelectExpression: string | ((domainName: string) => string);
19}
20
21/**
22 * Runtime binding for `sdb:Select`.
23 *
24 * Bind this operation to a {@link Domain} inside a function runtime.
25 * `Select` addresses the domain inside the expression itself rather than via
26 * a request field, so the client accepts either a literal expression or a
27 * function of the domain's resolved physical name.
28 * ### Querying Items
29 * **Example:** Select All Items
30 * ```typescript
31 * const select = yield* AWS.SimpleDB.Select(domain);
32 *
33 * const result = yield* select({
34 * SelectExpression: (domain) => `select * from \`${domain}\``,
35 * ConsistentRead: true,
36 * });
37 * // result.Items: [{ Name: "user#123", Attributes: [...] }, ...]
38 * ```
39 *
40 * **Example:** Select with a Where Clause
41 * ```typescript
42 * const result = yield* select({
43 * SelectExpression: (domain) =>
44 * `select * from \`${domain}\` where plan = 'pro'`,
45 * });
46 * ```
47 *
48 * @binding
49 */
50export interface Select extends Binding.Service<
51 Select,
52 "AWS.SimpleDB.Select",
53 (
54 domain: Domain,
55 ) => Effect.Effect<
56 (
57 request: SelectRequest,
58 ) => Effect.Effect<sdb.SelectResponse, sdb.SelectError, RuntimeContext>
59 >
60> {}
61export const Select = Binding.Service<Select>("AWS.SimpleDB.Select");