@kequtech/tenon-orm 0.2.0 → 0.2.1
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 +8 -0
- package/README.md +4 -0
- package/dist/database.js +1 -0
- package/dist/types.d.ts +3 -0
- package/docs/adoption-guide.md +4 -0
- package/docs/agent-guide.md +6 -0
- package/docs/reference.md +32 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.2.1
|
|
4
|
+
|
|
5
|
+
- Added readonly `db.native` access to Tenon's existing Postgres.js client for LISTEN, cursors,
|
|
6
|
+
COPY, and other native features without another driver installation. Native calls use the pool
|
|
7
|
+
directly and bypass Tenon's query guards and observation; transaction clients expose only `query`.
|
|
8
|
+
- Connection ownership is unchanged: `db.close()` ends owned clients and their listeners, while
|
|
9
|
+
borrowed clients remain usable until their owner ends them.
|
|
10
|
+
|
|
3
11
|
## 0.2.0
|
|
4
12
|
|
|
5
13
|
Changes since 0.1.0, including improvements shipped in 0.1.1–0.1.4.
|
package/README.md
CHANGED
|
@@ -43,6 +43,10 @@ This standalone example assumes the table exists. In a server, reuse an instance
|
|
|
43
43
|
close it at shutdown, not after each request. Use `returns: 'many'` for an array, `'one'` when a row
|
|
44
44
|
must exist, or omit the option for the driver's full result.
|
|
45
45
|
|
|
46
|
+
Use [`db.native`](docs/reference.md#native-driver-access) to access the underlying Postgres.js client
|
|
47
|
+
for LISTEN, cursors, COPY, and other native features without installing another driver. Native calls
|
|
48
|
+
use the pool directly and bypass Tenon's query and transaction guards.
|
|
49
|
+
|
|
46
50
|
Tenon also provides:
|
|
47
51
|
|
|
48
52
|
- Transactions and affected-row limits that roll back rejected writes.
|
package/dist/database.js
CHANGED
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type postgres from 'postgres';
|
|
1
2
|
import type { QueryResult } from './connection.js';
|
|
2
3
|
import type { QueryOptions, QueryOutput, QueryReturnMode } from './query-options.js';
|
|
3
4
|
import type { SqlQuery } from './query.js';
|
|
@@ -12,6 +13,8 @@ export interface QueryClient {
|
|
|
12
13
|
}
|
|
13
14
|
export type Transaction = QueryClient;
|
|
14
15
|
export type Database = Transaction & {
|
|
16
|
+
/** The underlying pool-level driver client; native calls bypass Tenon's query and transaction guards. */
|
|
17
|
+
readonly native: postgres.Sql;
|
|
15
18
|
/** Await all work inside the callback. Commit on success; rollback on an escaping error. */
|
|
16
19
|
transaction<T>(callback: (tx: Transaction) => Promise<T>): Promise<T>;
|
|
17
20
|
close(): Promise<void>;
|
package/docs/adoption-guide.md
CHANGED
|
@@ -33,6 +33,10 @@ queries or generate types; keep the existing migration runner if that is the int
|
|
|
33
33
|
migration tooling until the migration transition below is complete, if that transition is part of
|
|
34
34
|
the work.
|
|
35
35
|
|
|
36
|
+
For driver features such as LISTEN or COPY, use [`db.native`](reference.md#native-driver-access).
|
|
37
|
+
Preserve the application's notification recovery and resource ownership. Native pool queries do
|
|
38
|
+
not join Tenon transactions; use `tx.query` for operations that must commit together.
|
|
39
|
+
|
|
36
40
|
## Replace local write helpers
|
|
37
41
|
|
|
38
42
|
Use `sql.insertValues(rows)` and `sql.assignments(patch)` in place of local object-to-SQL utilities:
|
package/docs/agent-guide.md
CHANGED
|
@@ -45,6 +45,12 @@ supplied clients remain application-owned. The driver retains its native connect
|
|
|
45
45
|
outstanding work before closing. Environment files are not loaded automatically. Qualify SQL names
|
|
46
46
|
or configure `search_path`; CLI `--namespace` does not change runtime query names.
|
|
47
47
|
|
|
48
|
+
Use `db.native` for Postgres.js features such as LISTEN, cursors, and COPY without another driver
|
|
49
|
+
installation. It is the existing pool-level client. Native calls bypass Tenon's guards and `onQuery`,
|
|
50
|
+
and do not join a Tenon transaction; transaction callbacks expose only `tx.query`. `db.close()` ends
|
|
51
|
+
owned clients and their listeners; borrowed clients stay application-owned. Follow the
|
|
52
|
+
[native access contract](reference.md#native-driver-access) for initialization and shutdown.
|
|
53
|
+
|
|
48
54
|
## Query contracts
|
|
49
55
|
|
|
50
56
|
```ts
|
package/docs/reference.md
CHANGED
|
@@ -16,7 +16,7 @@ setup; Tenon needs no special compiler configuration. `"type": "module"` and Typ
|
|
|
16
16
|
npm install @kequtech/tenon-orm
|
|
17
17
|
```
|
|
18
18
|
|
|
19
|
-
`createTenon({ connection, onQuery? })` returns a `Database` with `query`, `transaction`, and
|
|
19
|
+
`createTenon({ connection, onQuery? })` returns a `Database` with `query`, `transaction`, `native`, and
|
|
20
20
|
`close`. The required `connection` accepts a URL, Postgres.js options, or an existing Postgres.js client. An
|
|
21
21
|
explicit `{}` selects the driver's environment defaults. Tenon does not load environment files
|
|
22
22
|
automatically.
|
|
@@ -27,6 +27,37 @@ remain application-owned. Finish outstanding work before closing. Postgres.js ha
|
|
|
27
27
|
Qualify SQL names or configure the driver's `search_path`. The CLI's `--namespace` selects the
|
|
28
28
|
schema used by tooling, not a runtime query namespace.
|
|
29
29
|
|
|
30
|
+
## Native driver access
|
|
31
|
+
|
|
32
|
+
`db.native` is the underlying Postgres.js client, typed as `postgres.Sql`. The property is readonly
|
|
33
|
+
in TypeScript. It exposes the existing pool without creating another client or requiring a separate
|
|
34
|
+
driver installation. A supplied client is returned by identity. Use native APIs for LISTEN, cursors,
|
|
35
|
+
COPY, and other driver features; their behavior follows the included `postgres@3.4.9`.
|
|
36
|
+
|
|
37
|
+
```ts
|
|
38
|
+
const db = createTenon({ connection });
|
|
39
|
+
await db.native.listen('updates', handlePayload, refreshAfterSubscription);
|
|
40
|
+
// At application shutdown, after outstanding work finishes:
|
|
41
|
+
await db.close();
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Postgres.js LISTEN creates a dedicated physical connection alongside the query pool. Applications
|
|
45
|
+
own notification parsing, authorization, callback failures, and catch-up after resubscription. See
|
|
46
|
+
the [Postgres.js native API](https://github.com/porsager/postgres/tree/v3.4.9#listen--notify).
|
|
47
|
+
|
|
48
|
+
Native calls bypass Tenon's result contracts, affected-row guards, SQL boundary checks, and
|
|
49
|
+
`onQuery` observation. They use native preparation defaults. `db.native` always refers to the pool,
|
|
50
|
+
including inside `db.transaction`: its queries do not join that transaction. Transaction callbacks
|
|
51
|
+
expose only `tx.query`; use that for work that must commit or roll back together.
|
|
52
|
+
|
|
53
|
+
Native access is immediate and does not initialize Tenon's array correction. The first Tenon query
|
|
54
|
+
or transaction installs that correction on the shared client; already prepared native statements
|
|
55
|
+
can retain earlier parsers. Raw calls otherwise follow native driver behavior.
|
|
56
|
+
|
|
57
|
+
`db.close()` ends a Tenon-owned client and its native listeners. With a borrowed client, it closes
|
|
58
|
+
only the Tenon wrapper: native queries and listeners remain usable until their owner calls
|
|
59
|
+
`db.native.end()`. Calling `end()` directly also ends the client used by Tenon.
|
|
60
|
+
|
|
30
61
|
## Queries and result modes
|
|
31
62
|
|
|
32
63
|
```ts
|