Skip to content

Commit c038277

Browse files
Update SDK pages
1 parent c4d004e commit c038277

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

docs/sdk/generator/builtin.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,42 @@ body: async (input, { env }) => {
5757
};
5858
```
5959

60+
### Raw SQL
61+
62+
For queries that the Kysely query builder can't express, use the `sql` tag re-exported from `@tailor-platform/sdk/kysely`. Plain value substitutions (`${...}`) are sent as bound parameters, so user-supplied values are parameterized safely. SQL fragments produced by Kysely helpers (for example `sql.raw(...)`, identifiers, refs) are inlined into the generated SQL string by design — do not pass untrusted input through those.
63+
64+
```typescript
65+
import { sql } from "@tailor-platform/sdk/kysely";
66+
import { getDB } from "./generated/tailordb";
67+
68+
createResolver({
69+
name: "supplierCountByState",
70+
operation: "query",
71+
input: { country: t.string() },
72+
output: t.object({
73+
rows: t.array(t.object({ state: t.string(), count: t.int() })),
74+
}),
75+
body: async ({ input }) => {
76+
const db = getDB("tailordb");
77+
const { rows } = await sql<{ state: string; count: number }>`
78+
SELECT state, COUNT(*) AS count
79+
FROM "Supplier"
80+
WHERE country = ${input.country}
81+
GROUP BY state
82+
`.execute(db);
83+
return { rows };
84+
},
85+
});
86+
```
87+
88+
The same `sql` tag works inside `db.transaction().execute(async (trx) => ...)` by passing `trx` to `.execute()`:
89+
90+
```typescript
91+
await db.transaction().execute(async (trx) => {
92+
await sql`UPDATE "Supplier" SET state = ${state} WHERE id = ${id}`.execute(trx);
93+
});
94+
```
95+
6096
## @tailor-platform/enum-constants
6197

6298
Extracts enum constants from TailorDB type definitions.

0 commit comments

Comments
 (0)