@typesql/postgres 0.2.4 → 0.2.6
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/CHANGELOG.md +16 -0
- package/README.md +9 -0
- package/dist/client.d.ts +4 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js +10 -1
- package/dist/client.js.map +1 -1
- package/package.json +2 -2
- package/src/client.ts +15 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @typesql/postgres
|
|
2
2
|
|
|
3
|
+
## 0.2.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Execute sql.prepare() queries with postgres.js prepared statements, including queries without parameters.
|
|
8
|
+
|
|
9
|
+
- Updated dependencies:
|
|
10
|
+
- @typesql/core@0.7.3
|
|
11
|
+
|
|
12
|
+
## 0.2.5
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Updated dependencies:
|
|
17
|
+
- @typesql/core@0.7.2
|
|
18
|
+
|
|
3
19
|
## 0.2.4
|
|
4
20
|
|
|
5
21
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -34,6 +34,15 @@ If your connection parses `int8` to `bigint` (`types: { bigint: postgres.BigInt
|
|
|
34
34
|
- [postgres.js adapter](https://typesql.karsli.net/adapters/postgres): running queries, transactions and migrations
|
|
35
35
|
- [Type mapping](https://typesql.karsli.net/reference/type-mapping#postgres-js): the TypeScript type of every Postgres type
|
|
36
36
|
|
|
37
|
+
## Prepared statements
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
const findPost = sql.prepare("SELECT id, title FROM posts WHERE author_id = $1");
|
|
41
|
+
const posts = await findPost(7).execute();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Reuse `findPost` with new values. TypeSQL assembles the SQL once and enables postgres.js prepared statements for execution, including queries without parameters. The driver's global `prepare: false` option is respected. All `execute*` methods work. Named parameters and fixed fragments are supported too. Inside a transaction, use `tx.prepare(...)` to bind it to that transaction.
|
|
45
|
+
|
|
37
46
|
## License
|
|
38
47
|
|
|
39
48
|
[MIT](LICENSE)
|
package/dist/client.d.ts
CHANGED
|
@@ -12,7 +12,10 @@ export type PostgresJsRows = readonly unknown[] & {
|
|
|
12
12
|
* a `TransactionSql` inside `begin`, a `ReservedSql`, or a fake in tests.
|
|
13
13
|
*/
|
|
14
14
|
export interface PostgresJsQueryable {
|
|
15
|
-
unsafe(query: string, parameters?: unknown[]
|
|
15
|
+
unsafe(query: string, parameters?: unknown[], options?: {
|
|
16
|
+
readonly prepare: boolean;
|
|
17
|
+
readonly simple: boolean;
|
|
18
|
+
}): PromiseLike<PostgresJsRows>;
|
|
16
19
|
}
|
|
17
20
|
/** Anything with postgres.js' `begin(fn)`: the `Sql` instance or a `ReservedSql`. */
|
|
18
21
|
export interface PostgresJsTransactable<Tx extends PostgresJsQueryable = PostgresJsQueryable> {
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,OAAO,EAAE,GAAG;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC,MAAM,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,SAAS,OAAO,EAAE,GAAG;IACjD,QAAQ,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC9B,CAAC;AAEF;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC,MAAM,CACL,KAAK,EAAE,MAAM,EACb,UAAU,CAAC,EAAE,OAAO,EAAE,EACtB,OAAO,CAAC,EAAE;QAAE,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;QAAC,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;KAAE,GAC/D,WAAW,CAAC,cAAc,CAAC,CAAC;CAC/B;AAED,qFAAqF;AACrF,MAAM,WAAW,sBAAsB,CACtC,EAAE,SAAS,mBAAmB,GAAG,mBAAmB;IAEpD,KAAK,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,KAAK,OAAO,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1D;AASD;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,mBAAmB,GAAG,QAAQ,CAc3D;AAsBD,0DAA0D;AAC1D,eAAO,MAAM,MAAM,EAAE,SAAS,CAAC,mBAAmB,CAA6B,CAAC;AAEhF,oGAAoG;AACpG,MAAM,WAAW,eAAe;IAC/B,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;CACvC;AAED;;;;GAIG;AACH,wBAAsB,OAAO,CAAC,EAAE,SAAS,mBAAmB,EAC3D,GAAG,EAAE,sBAAsB,CAAC,EAAE,CAAC,EAC/B,CAAC,EAAE,eAAe,GAChB,OAAO,CAAC,IAAI,CAAC,CAIf"}
|
package/dist/client.js
CHANGED
|
@@ -3,10 +3,19 @@
|
|
|
3
3
|
* `{ rows, rowCount }` (postgres.js' `.count`, so `q.executeCount()` works).
|
|
4
4
|
*/
|
|
5
5
|
export function executor(sql) {
|
|
6
|
-
|
|
6
|
+
const run = async (text, values) => {
|
|
7
7
|
const result = await sql.unsafe(text, Array.from(values));
|
|
8
8
|
return { rows: Array.from(result), rowCount: result.count ?? null };
|
|
9
9
|
};
|
|
10
|
+
return Object.assign(run, {
|
|
11
|
+
prepare: () => async (text, values) => {
|
|
12
|
+
const result = await sql.unsafe(text, Array.from(values), {
|
|
13
|
+
prepare: true,
|
|
14
|
+
simple: false,
|
|
15
|
+
});
|
|
16
|
+
return { rows: Array.from(result), rowCount: result.count ?? null };
|
|
17
|
+
},
|
|
18
|
+
});
|
|
10
19
|
}
|
|
11
20
|
/**
|
|
12
21
|
* Run `fn` inside a transaction: `tx.savepoint(fn)` on a `TransactionSql` (only those have it),
|
package/dist/client.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"client.js","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAqCA;;;GAGG;AACH,MAAM,UAAU,QAAQ,CAAC,GAAwB;IAChD,MAAM,GAAG,GAAa,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;QAC5C,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC;QAC1D,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;IACrE,CAAC,CAAC;IACF,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE;QACzB,OAAO,EAAE,GAAa,EAAE,CAAC,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE;YAC/C,MAAM,MAAM,GAAG,MAAM,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE;gBACzD,OAAO,EAAE,IAAI;gBACb,MAAM,EAAE,KAAK;aACb,CAAC,CAAC;YACH,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,KAAK,IAAI,IAAI,EAAE,CAAC;QACrE,CAAC;KACD,CAAC,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,KAAK,UAAU,WAAW,CACzB,GAAwB,EACxB,MAAc,EACd,EAA2C;IAE3C,MAAM,EAAE,SAAS,EAAE,KAAK,EAAE,GAAG,GAE5B,CAAC;IACF,IAAI,SAAS;QAAE,OAAO,CAAC,MAAM,SAAS,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAM,CAAC;IAC3D,IAAI,KAAK;QAAE,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAM,CAAC;IACnD,MAAM,IAAI,KAAK,CACd,6GAA6G,CAC7G,CAAC;AACH,CAAC;AAED,0DAA0D;AAC1D,MAAM,CAAC,MAAM,MAAM,GAAmC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;AAOhF;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,OAAO,CAC5B,GAA+B,EAC/B,CAAkB;IAElB,MAAM,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,EAAE,EAAE,EAAE;QAC5B,KAAK,MAAM,SAAS,IAAI,CAAC,CAAC,UAAU;YAAE,MAAM,EAAE,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typesql/postgres",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.6",
|
|
4
4
|
"description": "postgres.js adapter for TypeSQL.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
"access": "public"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@typesql/core": "0.7.
|
|
31
|
+
"@typesql/core": "0.7.3"
|
|
32
32
|
},
|
|
33
33
|
"peerDependencies": {
|
|
34
34
|
"postgres": ">=3"
|
package/src/client.ts
CHANGED
|
@@ -14,7 +14,11 @@ export type PostgresJsRows = readonly unknown[] & {
|
|
|
14
14
|
* a `TransactionSql` inside `begin`, a `ReservedSql`, or a fake in tests.
|
|
15
15
|
*/
|
|
16
16
|
export interface PostgresJsQueryable {
|
|
17
|
-
unsafe(
|
|
17
|
+
unsafe(
|
|
18
|
+
query: string,
|
|
19
|
+
parameters?: unknown[],
|
|
20
|
+
options?: { readonly prepare: boolean; readonly simple: boolean },
|
|
21
|
+
): PromiseLike<PostgresJsRows>;
|
|
18
22
|
}
|
|
19
23
|
|
|
20
24
|
/** Anything with postgres.js' `begin(fn)`: the `Sql` instance or a `ReservedSql`. */
|
|
@@ -36,10 +40,19 @@ interface PostgresJsSavepointable {
|
|
|
36
40
|
* `{ rows, rowCount }` (postgres.js' `.count`, so `q.executeCount()` works).
|
|
37
41
|
*/
|
|
38
42
|
export function executor(sql: PostgresJsQueryable): Executor {
|
|
39
|
-
|
|
43
|
+
const run: Executor = async (text, values) => {
|
|
40
44
|
const result = await sql.unsafe(text, Array.from(values));
|
|
41
45
|
return { rows: Array.from(result), rowCount: result.count ?? null };
|
|
42
46
|
};
|
|
47
|
+
return Object.assign(run, {
|
|
48
|
+
prepare: (): Executor => async (text, values) => {
|
|
49
|
+
const result = await sql.unsafe(text, Array.from(values), {
|
|
50
|
+
prepare: true,
|
|
51
|
+
simple: false,
|
|
52
|
+
});
|
|
53
|
+
return { rows: Array.from(result), rowCount: result.count ?? null };
|
|
54
|
+
},
|
|
55
|
+
});
|
|
43
56
|
}
|
|
44
57
|
|
|
45
58
|
/**
|