@anabranch/db-postgres 0.1.6 → 0.1.8
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/esm/anabranch/streams/source.d.ts +8 -1
- package/esm/anabranch/streams/source.d.ts.map +1 -1
- package/esm/anabranch/streams/source.js +25 -20
- package/esm/anabranch/streams/stream.d.ts.map +1 -1
- package/esm/anabranch/streams/stream.js +4 -2
- package/esm/db/index.d.ts +64 -7
- package/esm/db/index.d.ts.map +1 -1
- package/esm/db/index.js +64 -7
- package/esm/db-postgres/postgres.d.ts +44 -1
- package/esm/db-postgres/postgres.d.ts.map +1 -1
- package/esm/db-postgres/postgres.js +44 -1
- package/package.json +2 -2
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _StreamImpl } from "./stream.js";
|
|
2
|
+
import type { Result } from "./util.js";
|
|
2
3
|
/**
|
|
3
4
|
* The entry point for creating a {@link Stream}. Wraps an async generator so
|
|
4
5
|
* that yielded values become success results and any thrown error becomes a
|
|
@@ -22,7 +23,7 @@ import { _StreamImpl } from "./stream.js";
|
|
|
22
23
|
* ```
|
|
23
24
|
*/
|
|
24
25
|
export declare class Source<T, E> extends _StreamImpl<T, E> {
|
|
25
|
-
private readonly
|
|
26
|
+
private readonly resultSource;
|
|
26
27
|
/**
|
|
27
28
|
* @param source An async generator function. Each yielded value becomes a
|
|
28
29
|
* success result; any thrown error becomes an error result and terminates
|
|
@@ -56,6 +57,12 @@ export declare class Source<T, E> extends _StreamImpl<T, E> {
|
|
|
56
57
|
*/
|
|
57
58
|
static from<T, E>(source: AsyncIterable<T>): Source<T, E>;
|
|
58
59
|
static from<T, E>(fn: () => AsyncGenerator<T>): Source<T, E>;
|
|
60
|
+
/**
|
|
61
|
+
* Creates a {@link Source} from an async generator that yields {@link Result}
|
|
62
|
+
* values directly. This is useful when you want to yield both successes and
|
|
63
|
+
* errors from the source without terminating it on the first error.
|
|
64
|
+
*/
|
|
65
|
+
static fromResults<T, E>(source: () => AsyncGenerator<Result<T, E>>): Source<T, E>;
|
|
59
66
|
/**
|
|
60
67
|
* Sets the maximum number of concurrent operations for the stream.
|
|
61
68
|
*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../../src/anabranch/streams/source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../../src/anabranch/streams/source.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,WAAW,CAAC;AAExC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,MAAM,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC;IAS/C,OAAO,CAAC,QAAQ,CAAC,YAAY;IAR/B;;;;;;OAMG;IACH,OAAO;IAQP;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IACzD,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,EAAE,MAAM,cAAc,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAoB5D;;;;OAIG;IACH,MAAM,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,EACrB,MAAM,EAAE,MAAM,cAAc,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GACzC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAIf;;OAEG;IACH,eAAe,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;IAIxC;;OAEG;IACH,cAAc,CAAC,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC;CAGxC"}
|
|
@@ -29,10 +29,22 @@ export class Source extends _StreamImpl {
|
|
|
29
29
|
* @param concurrency Maximum number of concurrent operations. Defaults to `Infinity`.
|
|
30
30
|
* @param bufferSize Maximum number of buffered results before backpressure is applied. Defaults to `Infinity`.
|
|
31
31
|
*/
|
|
32
|
-
constructor(
|
|
33
|
-
|
|
32
|
+
constructor(resultSource, concurrency = Infinity, bufferSize = Infinity) {
|
|
33
|
+
super(resultSource, concurrency, bufferSize);
|
|
34
|
+
Object.defineProperty(this, "resultSource", {
|
|
35
|
+
enumerable: true,
|
|
36
|
+
configurable: true,
|
|
37
|
+
writable: true,
|
|
38
|
+
value: resultSource
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
static from(source) {
|
|
42
|
+
const fn = typeof source === "function" ? source : async function* () {
|
|
43
|
+
yield* source;
|
|
44
|
+
};
|
|
45
|
+
const resultSource = async function* () {
|
|
34
46
|
try {
|
|
35
|
-
for await (const value of
|
|
47
|
+
for await (const value of fn()) {
|
|
36
48
|
yield { type: "success", value };
|
|
37
49
|
}
|
|
38
50
|
}
|
|
@@ -40,33 +52,26 @@ export class Source extends _StreamImpl {
|
|
|
40
52
|
yield { type: "error", error: error };
|
|
41
53
|
}
|
|
42
54
|
};
|
|
43
|
-
|
|
44
|
-
Object.defineProperty(this, "rawSource", {
|
|
45
|
-
enumerable: true,
|
|
46
|
-
configurable: true,
|
|
47
|
-
writable: true,
|
|
48
|
-
value: void 0
|
|
49
|
-
});
|
|
50
|
-
this.rawSource = source;
|
|
55
|
+
return new Source(resultSource);
|
|
51
56
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
/**
|
|
58
|
+
* Creates a {@link Source} from an async generator that yields {@link Result}
|
|
59
|
+
* values directly. This is useful when you want to yield both successes and
|
|
60
|
+
* errors from the source without terminating it on the first error.
|
|
61
|
+
*/
|
|
62
|
+
static fromResults(source) {
|
|
63
|
+
return new Source(source);
|
|
59
64
|
}
|
|
60
65
|
/**
|
|
61
66
|
* Sets the maximum number of concurrent operations for the stream.
|
|
62
67
|
*/
|
|
63
68
|
withConcurrency(n) {
|
|
64
|
-
return new Source(this.
|
|
69
|
+
return new Source(this.resultSource, n, this.bufferSize);
|
|
65
70
|
}
|
|
66
71
|
/**
|
|
67
72
|
* Sets the maximum number of buffered results before backpressure is applied to the stream. If the buffer is full, the stream will pause until there is space in the buffer for new results.
|
|
68
73
|
*/
|
|
69
74
|
withBufferSize(n) {
|
|
70
|
-
return new Source(this.
|
|
75
|
+
return new Source(this.resultSource, this.concurrency, n);
|
|
71
76
|
}
|
|
72
77
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stream.d.ts","sourceRoot":"","sources":["../../../src/anabranch/streams/stream.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkB,KAAK,UAAU,EAAE,KAAK,MAAM,EAAE,MAAM,WAAW,CAAC;AAiCzE;;;;;;;;;;GAUG;AACH,MAAM,WAAW,MAAM,CAAC,CAAC,EAAE,CAAC,CAAE,SAAQ,aAAa,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAC/D;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACtD;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,KAAK,EACjB,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,EAC/B,KAAK,EAAE,CAAC,KAAK,EAAE,OAAO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CAAC,EAAE,EAAE,CAAC,CAAC;IAwBhC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,UAAU,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,CAAC;IAwBjE,OAAO,CAAC,EAAE,SAAS,CAAC,EAClB,KAAK,EAAE,CAAC,KAAK,EAAE,CAAC,KAAK,KAAK,IAAI,EAAE,GAC/B,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;CAgB7B"}
|
|
@@ -390,16 +390,18 @@ export class _StreamImpl {
|
|
|
390
390
|
const concurrency = this.concurrency;
|
|
391
391
|
const bufferSize = this.bufferSize;
|
|
392
392
|
return new _StreamImpl(async function* () {
|
|
393
|
+
if (n <= 0)
|
|
394
|
+
return;
|
|
393
395
|
const gen = source();
|
|
394
396
|
try {
|
|
395
397
|
let count = 0;
|
|
396
398
|
for await (const result of gen) {
|
|
397
399
|
if (result.type === "success") {
|
|
398
|
-
if (count >= n)
|
|
399
|
-
break;
|
|
400
400
|
count += 1;
|
|
401
401
|
}
|
|
402
402
|
yield result;
|
|
403
|
+
if (count >= n)
|
|
404
|
+
break;
|
|
403
405
|
}
|
|
404
406
|
}
|
|
405
407
|
finally {
|
package/esm/db/index.d.ts
CHANGED
|
@@ -2,22 +2,79 @@
|
|
|
2
2
|
* @anabranch/db
|
|
3
3
|
*
|
|
4
4
|
* Database primitives with Task/Stream semantics for error-tolerant async operations.
|
|
5
|
+
* Integrates with anabranch's {@link Task}, {@link Stream}, {@link Source}, and
|
|
6
|
+
* {@link Channel} types for composable error handling and concurrent processing.
|
|
7
|
+
*
|
|
8
|
+
* ## Adapters vs Connectors
|
|
5
9
|
*
|
|
6
10
|
* A **DBConnector** produces connected **DBAdapter** instances. Use connectors for
|
|
7
|
-
* production code to properly manage connection lifecycles
|
|
11
|
+
* production code to properly manage connection lifecycles:
|
|
12
|
+
*
|
|
13
|
+
* - **Connector**: Manages connection pool/lifecycle, produces adapters
|
|
14
|
+
* - **Adapter**: Low-level query/execute/close interface
|
|
15
|
+
* - **DB**: Wrapper providing Task/Stream semantics over an adapter
|
|
16
|
+
*
|
|
17
|
+
* ## Core Types
|
|
18
|
+
*
|
|
19
|
+
* - {@link DBConnector} - Interface for connection factories
|
|
20
|
+
* - {@link DBAdapter} - Low-level database operations interface
|
|
21
|
+
* - {@link DB} - High-level wrapper with Task/Stream methods
|
|
22
|
+
* - {@link DBTransaction} - Transaction scope with commit/rollback
|
|
23
|
+
*
|
|
24
|
+
* ## Error Types
|
|
25
|
+
*
|
|
26
|
+
* All errors are typed for catchable handling:
|
|
27
|
+
* - {@link ConnectionFailed} - Connection establishment failed
|
|
28
|
+
* - {@link QueryFailed} - Query execution error
|
|
29
|
+
* - {@link ConstraintViolation} - Constraint violation (UNIQUE, FOREIGN KEY, etc.)
|
|
30
|
+
* - {@link TransactionFailed} - Transaction error
|
|
31
|
+
*
|
|
32
|
+
* @example Basic query with Task semantics
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { DB, createInMemory } from "@anabranch/db";
|
|
35
|
+
*
|
|
36
|
+
* const users = await DB.withConnection(createInMemory(), (db) =>
|
|
37
|
+
* db.query("SELECT * FROM users WHERE active = ?", [true])
|
|
38
|
+
* ).run();
|
|
39
|
+
* ```
|
|
8
40
|
*
|
|
9
|
-
* @example
|
|
41
|
+
* @example Streaming large result sets with error collection
|
|
10
42
|
* ```ts
|
|
11
43
|
* import { DB, createInMemory } from "@anabranch/db";
|
|
12
44
|
*
|
|
13
|
-
*
|
|
45
|
+
* const { successes, errors } = await DB.withConnection(createInMemory(), (db) =>
|
|
46
|
+
* db.stream("SELECT * FROM large_table")
|
|
47
|
+
* .withConcurrency(10)
|
|
48
|
+
* .map(row => processRow(row))
|
|
49
|
+
* .partition()
|
|
50
|
+
* ).run();
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example Transactions with automatic rollback on error
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { DB, ConstraintViolation, createInMemory } from "@anabranch/db";
|
|
56
|
+
*
|
|
14
57
|
* const result = await DB.withConnection(createInMemory(), (db) =>
|
|
15
|
-
* db.
|
|
58
|
+
* db.withTransaction(async (tx) => {
|
|
59
|
+
* await tx.execute("INSERT INTO orders (user_id) VALUES (?)", [userId]);
|
|
60
|
+
* await tx.execute("UPDATE users SET order_count = order_count + 1 WHERE id = ?", [userId]);
|
|
61
|
+
* return tx.query("SELECT last_insert_rowid()");
|
|
62
|
+
* })
|
|
63
|
+
* ).recoverWhen(
|
|
64
|
+
* (e) => e instanceof ConstraintViolation,
|
|
65
|
+
* (e) => ({ id: 0, error: e.message })
|
|
16
66
|
* ).run();
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example Retry with exponential backoff
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { DB, createPostgres } from "@anabranch/db";
|
|
72
|
+
* import { createPostgres } from "@anabranch/db-postgres";
|
|
17
73
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
74
|
+
* const users = await DB.withConnection(createPostgres(), (db) =>
|
|
75
|
+
* db.query("SELECT * FROM users")
|
|
76
|
+
* .retry({ attempts: 3, delay: (attempt) => 100 * Math.pow(2, attempt) })
|
|
77
|
+
* ).run();
|
|
21
78
|
* ```
|
|
22
79
|
*
|
|
23
80
|
* @module
|
package/esm/db/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgFG;AACH,OAAO,EAAE,EAAE,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC5C,YAAY,EACV,SAAS,EACT,WAAW,EACX,oBAAoB,GACrB,MAAM,cAAc,CAAC;AACtB,cAAc,aAAa,CAAC;AAC5B,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC"}
|
package/esm/db/index.js
CHANGED
|
@@ -2,22 +2,79 @@
|
|
|
2
2
|
* @anabranch/db
|
|
3
3
|
*
|
|
4
4
|
* Database primitives with Task/Stream semantics for error-tolerant async operations.
|
|
5
|
+
* Integrates with anabranch's {@link Task}, {@link Stream}, {@link Source}, and
|
|
6
|
+
* {@link Channel} types for composable error handling and concurrent processing.
|
|
7
|
+
*
|
|
8
|
+
* ## Adapters vs Connectors
|
|
5
9
|
*
|
|
6
10
|
* A **DBConnector** produces connected **DBAdapter** instances. Use connectors for
|
|
7
|
-
* production code to properly manage connection lifecycles
|
|
11
|
+
* production code to properly manage connection lifecycles:
|
|
12
|
+
*
|
|
13
|
+
* - **Connector**: Manages connection pool/lifecycle, produces adapters
|
|
14
|
+
* - **Adapter**: Low-level query/execute/close interface
|
|
15
|
+
* - **DB**: Wrapper providing Task/Stream semantics over an adapter
|
|
16
|
+
*
|
|
17
|
+
* ## Core Types
|
|
18
|
+
*
|
|
19
|
+
* - {@link DBConnector} - Interface for connection factories
|
|
20
|
+
* - {@link DBAdapter} - Low-level database operations interface
|
|
21
|
+
* - {@link DB} - High-level wrapper with Task/Stream methods
|
|
22
|
+
* - {@link DBTransaction} - Transaction scope with commit/rollback
|
|
23
|
+
*
|
|
24
|
+
* ## Error Types
|
|
25
|
+
*
|
|
26
|
+
* All errors are typed for catchable handling:
|
|
27
|
+
* - {@link ConnectionFailed} - Connection establishment failed
|
|
28
|
+
* - {@link QueryFailed} - Query execution error
|
|
29
|
+
* - {@link ConstraintViolation} - Constraint violation (UNIQUE, FOREIGN KEY, etc.)
|
|
30
|
+
* - {@link TransactionFailed} - Transaction error
|
|
31
|
+
*
|
|
32
|
+
* @example Basic query with Task semantics
|
|
33
|
+
* ```ts
|
|
34
|
+
* import { DB, createInMemory } from "@anabranch/db";
|
|
35
|
+
*
|
|
36
|
+
* const users = await DB.withConnection(createInMemory(), (db) =>
|
|
37
|
+
* db.query("SELECT * FROM users WHERE active = ?", [true])
|
|
38
|
+
* ).run();
|
|
39
|
+
* ```
|
|
8
40
|
*
|
|
9
|
-
* @example
|
|
41
|
+
* @example Streaming large result sets with error collection
|
|
10
42
|
* ```ts
|
|
11
43
|
* import { DB, createInMemory } from "@anabranch/db";
|
|
12
44
|
*
|
|
13
|
-
*
|
|
45
|
+
* const { successes, errors } = await DB.withConnection(createInMemory(), (db) =>
|
|
46
|
+
* db.stream("SELECT * FROM large_table")
|
|
47
|
+
* .withConcurrency(10)
|
|
48
|
+
* .map(row => processRow(row))
|
|
49
|
+
* .partition()
|
|
50
|
+
* ).run();
|
|
51
|
+
* ```
|
|
52
|
+
*
|
|
53
|
+
* @example Transactions with automatic rollback on error
|
|
54
|
+
* ```ts
|
|
55
|
+
* import { DB, ConstraintViolation, createInMemory } from "@anabranch/db";
|
|
56
|
+
*
|
|
14
57
|
* const result = await DB.withConnection(createInMemory(), (db) =>
|
|
15
|
-
* db.
|
|
58
|
+
* db.withTransaction(async (tx) => {
|
|
59
|
+
* await tx.execute("INSERT INTO orders (user_id) VALUES (?)", [userId]);
|
|
60
|
+
* await tx.execute("UPDATE users SET order_count = order_count + 1 WHERE id = ?", [userId]);
|
|
61
|
+
* return tx.query("SELECT last_insert_rowid()");
|
|
62
|
+
* })
|
|
63
|
+
* ).recoverWhen(
|
|
64
|
+
* (e) => e instanceof ConstraintViolation,
|
|
65
|
+
* (e) => ({ id: 0, error: e.message })
|
|
16
66
|
* ).run();
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* @example Retry with exponential backoff
|
|
70
|
+
* ```ts
|
|
71
|
+
* import { DB, createPostgres } from "@anabranch/db";
|
|
72
|
+
* import { createPostgres } from "@anabranch/db-postgres";
|
|
17
73
|
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
74
|
+
* const users = await DB.withConnection(createPostgres(), (db) =>
|
|
75
|
+
* db.query("SELECT * FROM users")
|
|
76
|
+
* .retry({ attempts: 3, delay: (attempt) => 100 * Math.pow(2, attempt) })
|
|
77
|
+
* ).run();
|
|
21
78
|
* ```
|
|
22
79
|
*
|
|
23
80
|
* @module
|
|
@@ -1,5 +1,48 @@
|
|
|
1
1
|
import type { DBAdapter } from "../db/index.js";
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Creates a PostgreSQL connector with connection pooling.
|
|
4
|
+
*
|
|
5
|
+
* Returns a connector that can be used with {@link DB.withConnection} to
|
|
6
|
+
* acquire connections. Each call to `connect()` returns a new adapter with
|
|
7
|
+
* query, execute, and stream methods. The stream method uses pg-cursor for
|
|
8
|
+
* memory-efficient streaming of large result sets.
|
|
9
|
+
*
|
|
10
|
+
* @example Connect and query with error handling
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { DB } from "@anabranch/db";
|
|
13
|
+
* import { createPostgres } from "@anabranch/db-postgres";
|
|
14
|
+
*
|
|
15
|
+
* const users = await DB.withConnection(createPostgres(), (db) =>
|
|
16
|
+
* db.query("SELECT * FROM users WHERE active = ?", [true])
|
|
17
|
+
* ).run();
|
|
18
|
+
* ```
|
|
19
|
+
*
|
|
20
|
+
* @example Stream large result sets with concurrency
|
|
21
|
+
* ```ts
|
|
22
|
+
* import { DB } from "@anabranch/db";
|
|
23
|
+
* import { createPostgres } from "@anabranch/db-postgres";
|
|
24
|
+
*
|
|
25
|
+
* const { successes, errors } = await DB.withConnection(createPostgres(), (db) =>
|
|
26
|
+
* db.stream("SELECT * FROM large_table")
|
|
27
|
+
* .withConcurrency(10)
|
|
28
|
+
* .map(row => processRow(row))
|
|
29
|
+
* .partition()
|
|
30
|
+
* ).run();
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* @example Transactions with automatic rollback
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { DB } from "@anabranch/db";
|
|
36
|
+
* import { createPostgres } from "@anabranch/db-postgres";
|
|
37
|
+
*
|
|
38
|
+
* const result = await DB.withConnection(createPostgres(), (db) =>
|
|
39
|
+
* db.withTransaction(async (tx) => {
|
|
40
|
+
* await tx.execute("INSERT INTO orders (user_id) VALUES (?)", [userId]);
|
|
41
|
+
* return tx.query("SELECT last_insert_rowid()");
|
|
42
|
+
* })
|
|
43
|
+
* ).run();
|
|
44
|
+
* ```
|
|
45
|
+
*/
|
|
3
46
|
export declare function createPostgres(options?: PostgresOptions): PostgresConnector;
|
|
4
47
|
/** Connection options for PostgreSQL. */
|
|
5
48
|
export type PostgresOptions = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/db-postgres/postgres.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKhD
|
|
1
|
+
{"version":3,"file":"postgres.d.ts","sourceRoot":"","sources":["../../src/db-postgres/postgres.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAKhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2CG;AACH,wBAAgB,cAAc,CAC5B,OAAO,GAAE,eAAoB,GAC5B,iBAAiB,CA4CnB;AAED,yCAAyC;AACzC,MAAM,MAAM,eAAe,GAAG;IAC5B,2BAA2B;IAC3B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,oBAAoB;IACpB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,0BAA0B;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,kBAAkB;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,uBAAuB,CAAC,EAAE,MAAM,CAAC;CAClC,CAAC;AAEF,qCAAqC;AACrC,MAAM,WAAW,iBAAiB;IAChC,4DAA4D;IAC5D,OAAO,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;IAClD,kCAAkC;IAClC,GAAG,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACtB"}
|
|
@@ -2,7 +2,50 @@ import pg from "pg";
|
|
|
2
2
|
import Cursor from "pg-cursor";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
const { Pool } = pg;
|
|
5
|
-
/**
|
|
5
|
+
/**
|
|
6
|
+
* Creates a PostgreSQL connector with connection pooling.
|
|
7
|
+
*
|
|
8
|
+
* Returns a connector that can be used with {@link DB.withConnection} to
|
|
9
|
+
* acquire connections. Each call to `connect()` returns a new adapter with
|
|
10
|
+
* query, execute, and stream methods. The stream method uses pg-cursor for
|
|
11
|
+
* memory-efficient streaming of large result sets.
|
|
12
|
+
*
|
|
13
|
+
* @example Connect and query with error handling
|
|
14
|
+
* ```ts
|
|
15
|
+
* import { DB } from "@anabranch/db";
|
|
16
|
+
* import { createPostgres } from "@anabranch/db-postgres";
|
|
17
|
+
*
|
|
18
|
+
* const users = await DB.withConnection(createPostgres(), (db) =>
|
|
19
|
+
* db.query("SELECT * FROM users WHERE active = ?", [true])
|
|
20
|
+
* ).run();
|
|
21
|
+
* ```
|
|
22
|
+
*
|
|
23
|
+
* @example Stream large result sets with concurrency
|
|
24
|
+
* ```ts
|
|
25
|
+
* import { DB } from "@anabranch/db";
|
|
26
|
+
* import { createPostgres } from "@anabranch/db-postgres";
|
|
27
|
+
*
|
|
28
|
+
* const { successes, errors } = await DB.withConnection(createPostgres(), (db) =>
|
|
29
|
+
* db.stream("SELECT * FROM large_table")
|
|
30
|
+
* .withConcurrency(10)
|
|
31
|
+
* .map(row => processRow(row))
|
|
32
|
+
* .partition()
|
|
33
|
+
* ).run();
|
|
34
|
+
* ```
|
|
35
|
+
*
|
|
36
|
+
* @example Transactions with automatic rollback
|
|
37
|
+
* ```ts
|
|
38
|
+
* import { DB } from "@anabranch/db";
|
|
39
|
+
* import { createPostgres } from "@anabranch/db-postgres";
|
|
40
|
+
*
|
|
41
|
+
* const result = await DB.withConnection(createPostgres(), (db) =>
|
|
42
|
+
* db.withTransaction(async (tx) => {
|
|
43
|
+
* await tx.execute("INSERT INTO orders (user_id) VALUES (?)", [userId]);
|
|
44
|
+
* return tx.query("SELECT last_insert_rowid()");
|
|
45
|
+
* })
|
|
46
|
+
* ).run();
|
|
47
|
+
* ```
|
|
48
|
+
*/
|
|
6
49
|
export function createPostgres(options = {}) {
|
|
7
50
|
const pool = new Pool(toPoolConfig(options));
|
|
8
51
|
return {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@anabranch/db-postgres",
|
|
3
|
-
"version": "0.1.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.1.8",
|
|
4
|
+
"description": "PostgreSQL database adapter",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/frodi-karlsson/anabranch.git"
|