@triptease/sql-template 0.35.6 → 0.36.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +15 -12
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -34,11 +34,14 @@ import {SQL, id, values} from "@triptease/sql-template";
|
|
|
34
34
|
import {statement, prepareStatement} from "@triptease/sql-template-postgres";
|
|
35
35
|
|
|
36
36
|
const pool = new pg.Pool();
|
|
37
|
-
const
|
|
38
|
-
// SQL: select * from "users" where name = $1 values: ['Dan']
|
|
37
|
+
const table = 'users', name = "O'Brien";
|
|
39
38
|
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
await pool.query(statement(SQL`select * from ${id(table)} where name = ${name}`));
|
|
40
|
+
// { text: 'select * from "users" where name = $1', values: ["O'Brien"] }
|
|
41
|
+
|
|
42
|
+
// named prepared statement (the name defaults to a hash of the SQL)
|
|
43
|
+
await pool.query(prepareStatement(SQL`select * from users where id in (${values([1, 2, 3])})`));
|
|
44
|
+
// { name: 'feb13b21…', text: 'select * from users where id in ($1, $2, $3)', values: [1, 2, 3] }
|
|
42
45
|
```
|
|
43
46
|
|
|
44
47
|
### Bun
|
|
@@ -53,9 +56,10 @@ run on Node with `pg`, or when you want queries as plain immutable values you ca
|
|
|
53
56
|
```typescript
|
|
54
57
|
import {SQL, id, ids, text, values} from "@triptease/sql-template";
|
|
55
58
|
|
|
56
|
-
|
|
57
|
-
const
|
|
58
|
-
const
|
|
59
|
+
// templates nest, and values() can join them with an explicit (raw) separator
|
|
60
|
+
const filters = [SQL`${id('name')} = ${name}`, SQL`${id('age')} > ${30}`];
|
|
61
|
+
const query = SQL`select ${ids(['id', 'name'])} from users where ${values(filters, text(' and '))}`;
|
|
62
|
+
// select "id", "name" from users where "name" = $1 and "age" > $2
|
|
59
63
|
```
|
|
60
64
|
|
|
61
65
|
Templates are immutable (frozen) and flat. Expressions are identified by a `Symbol.for` brand rather than
|
|
@@ -162,7 +166,7 @@ Every push to `triptease/sql-template` that passes the `test` job runs the `publ
|
|
|
162
166
|
* It publishes core first, then postgres, with `npm publish <pkg>/dist`:
|
|
163
167
|
* to **GitHub Packages** (`npm.pkg.github.com`) on every run, using the workflow's `GITHUB_TOKEN`;
|
|
164
168
|
* to **npmjs** only when the repo variable `NPM_PUBLISH` is `true`, with `--access public --provenance`,
|
|
165
|
-
authenticated by npm Trusted Publishing (OIDC)
|
|
169
|
+
authenticated by npm Trusted Publishing (OIDC).
|
|
166
170
|
* Versions that are already on a registry are skipped, so a failed run can simply be re-run.
|
|
167
171
|
* The staged `dist` directories are kept as the `dist` artifact of the workflow run.
|
|
168
172
|
|
|
@@ -179,12 +183,11 @@ to include npmjs):
|
|
|
179
183
|
|
|
180
184
|
1. On npmjs.com, for **each** of `@triptease/sql-template` and `@triptease/sql-template-postgres`:
|
|
181
185
|
Settings → Trusted Publisher → GitHub Actions, organization `triptease`, repository `sql-template`,
|
|
182
|
-
workflow filename `build.yml`, environment empty
|
|
183
|
-
relationship, so do not rename `build.yml`.
|
|
184
|
-
|
|
186
|
+
workflow filename `build.yml`, environment empty, allowed actions: `npm publish` only. The workflow
|
|
187
|
+
filename is part of the trust relationship, so do not rename `build.yml`. Publishing access is set to
|
|
188
|
+
"require two-factor authentication and disallow tokens", so only this workflow can publish.
|
|
185
189
|
2. In the GitHub repo, set the Actions variable `NPM_PUBLISH` to `true` (Settings → Secrets and variables →
|
|
186
190
|
Actions → Variables). Until then npmjs publishing is skipped and only GitHub Packages is published.
|
|
187
|
-
(Alternative to step 1: add an `NPM_TOKEN` repo secret with publish rights; the publish step uses it if set.)
|
|
188
191
|
3. GitHub Packages: after the first publish, check both packages under the org's Packages page, make sure
|
|
189
192
|
they are linked to this repository and set their visibility to public if they should be visible
|
|
190
193
|
outside the org.
|