@anabranch/db-postgres 0.1.5 → 0.1.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/esm/db/index.d.ts +3 -40
- package/esm/db/index.d.ts.map +1 -1
- package/esm/db/index.js +3 -40
- package/esm/db-postgres/index.d.ts +27 -0
- package/esm/db-postgres/index.d.ts.map +1 -1
- package/esm/db-postgres/index.js +27 -0
- package/esm/db-postgres/postgres.d.ts +11 -2
- package/esm/db-postgres/postgres.d.ts.map +1 -1
- package/esm/db-postgres/postgres.js +1 -0
- package/package.json +1 -1
package/esm/db/index.d.ts
CHANGED
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @anabranch/db
|
|
3
3
|
*
|
|
4
4
|
* Database primitives with Task/Stream semantics for error-tolerant async operations.
|
|
5
5
|
*
|
|
6
|
-
* ## Adapters vs Connectors
|
|
7
|
-
*
|
|
8
6
|
* A **DBConnector** produces connected **DBAdapter** instances. Use connectors for
|
|
9
|
-
* production code to properly manage connection lifecycles
|
|
7
|
+
* production code to properly manage connection lifecycles.
|
|
10
8
|
*
|
|
9
|
+
* @example
|
|
11
10
|
* ```ts
|
|
12
11
|
* import { DB, createInMemory } from "@anabranch/db";
|
|
13
12
|
*
|
|
@@ -21,42 +20,6 @@
|
|
|
21
20
|
* const db = new DB(adapter);
|
|
22
21
|
* ```
|
|
23
22
|
*
|
|
24
|
-
* ## Usage
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* import { DB, createInMemory } from "@anabranch/db";
|
|
28
|
-
*
|
|
29
|
-
* // Using withConnection for automatic lifecycle management
|
|
30
|
-
* await DB.withConnection(createInMemory(), async (db) => {
|
|
31
|
-
* await db.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)").run();
|
|
32
|
-
* await db.execute("INSERT INTO users (name) VALUES (?)", ["Alice"]).run();
|
|
33
|
-
* return db.query("SELECT * FROM users").run();
|
|
34
|
-
* }).run();
|
|
35
|
-
*
|
|
36
|
-
* // Stream large result sets
|
|
37
|
-
* const { successes, errors } = await db.stream("SELECT * FROM users")
|
|
38
|
-
* .map(u => processUser(u))
|
|
39
|
-
* .partition();
|
|
40
|
-
*
|
|
41
|
-
* // Transactions with automatic rollback on error
|
|
42
|
-
* const result = await DB.withConnection(createInMemory(), (db) =>
|
|
43
|
-
* db.withTransaction(async (tx) => {
|
|
44
|
-
* await tx.execute("INSERT INTO users (name) VALUES (?)", ["Bob"]).run();
|
|
45
|
-
* return tx.query("SELECT last_insert_rowid()").run();
|
|
46
|
-
* })
|
|
47
|
-
* ).run();
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* ## Error Types
|
|
51
|
-
*
|
|
52
|
-
* The following error types are exported for adapter implementors:
|
|
53
|
-
*
|
|
54
|
-
* - {@link ConnectionFailed} - Throw from connector's `connect()` on failure
|
|
55
|
-
* - {@link CloseError} - Throw from adapter's `close()` on failure
|
|
56
|
-
* - {@link QueryFailed} - Thrown for query execution errors
|
|
57
|
-
* - {@link ConstraintViolation} - Thrown for constraint violations (e.g., UNIQUE, FOREIGN KEY)
|
|
58
|
-
* - {@link TransactionFailed} - Thrown for transaction errors
|
|
59
|
-
*
|
|
60
23
|
* @module
|
|
61
24
|
*/
|
|
62
25
|
export { DB, DBTransaction } from "./db.js";
|
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;;;;;;;;;;;;;;;;;;;;;;;GAuBG;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
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @anabranch/db
|
|
3
3
|
*
|
|
4
4
|
* Database primitives with Task/Stream semantics for error-tolerant async operations.
|
|
5
5
|
*
|
|
6
|
-
* ## Adapters vs Connectors
|
|
7
|
-
*
|
|
8
6
|
* A **DBConnector** produces connected **DBAdapter** instances. Use connectors for
|
|
9
|
-
* production code to properly manage connection lifecycles
|
|
7
|
+
* production code to properly manage connection lifecycles.
|
|
10
8
|
*
|
|
9
|
+
* @example
|
|
11
10
|
* ```ts
|
|
12
11
|
* import { DB, createInMemory } from "@anabranch/db";
|
|
13
12
|
*
|
|
@@ -21,42 +20,6 @@
|
|
|
21
20
|
* const db = new DB(adapter);
|
|
22
21
|
* ```
|
|
23
22
|
*
|
|
24
|
-
* ## Usage
|
|
25
|
-
*
|
|
26
|
-
* ```ts
|
|
27
|
-
* import { DB, createInMemory } from "@anabranch/db";
|
|
28
|
-
*
|
|
29
|
-
* // Using withConnection for automatic lifecycle management
|
|
30
|
-
* await DB.withConnection(createInMemory(), async (db) => {
|
|
31
|
-
* await db.execute("CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)").run();
|
|
32
|
-
* await db.execute("INSERT INTO users (name) VALUES (?)", ["Alice"]).run();
|
|
33
|
-
* return db.query("SELECT * FROM users").run();
|
|
34
|
-
* }).run();
|
|
35
|
-
*
|
|
36
|
-
* // Stream large result sets
|
|
37
|
-
* const { successes, errors } = await db.stream("SELECT * FROM users")
|
|
38
|
-
* .map(u => processUser(u))
|
|
39
|
-
* .partition();
|
|
40
|
-
*
|
|
41
|
-
* // Transactions with automatic rollback on error
|
|
42
|
-
* const result = await DB.withConnection(createInMemory(), (db) =>
|
|
43
|
-
* db.withTransaction(async (tx) => {
|
|
44
|
-
* await tx.execute("INSERT INTO users (name) VALUES (?)", ["Bob"]).run();
|
|
45
|
-
* return tx.query("SELECT last_insert_rowid()").run();
|
|
46
|
-
* })
|
|
47
|
-
* ).run();
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* ## Error Types
|
|
51
|
-
*
|
|
52
|
-
* The following error types are exported for adapter implementors:
|
|
53
|
-
*
|
|
54
|
-
* - {@link ConnectionFailed} - Throw from connector's `connect()` on failure
|
|
55
|
-
* - {@link CloseError} - Throw from adapter's `close()` on failure
|
|
56
|
-
* - {@link QueryFailed} - Thrown for query execution errors
|
|
57
|
-
* - {@link ConstraintViolation} - Thrown for constraint violations (e.g., UNIQUE, FOREIGN KEY)
|
|
58
|
-
* - {@link TransactionFailed} - Thrown for transaction errors
|
|
59
|
-
*
|
|
60
23
|
* @module
|
|
61
24
|
*/
|
|
62
25
|
export { DB, DBTransaction } from "./db.js";
|
|
@@ -1,2 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @anabranch/db-postgres
|
|
3
|
+
*
|
|
4
|
+
* PostgreSQL database connector for the @anabranch/db package using `node:pg`.
|
|
5
|
+
*
|
|
6
|
+
* Provides a `DBConnector` implementation with connection pooling and
|
|
7
|
+
* cursor-based streaming via `pg-cursor` for memory-efficient processing
|
|
8
|
+
* of large result sets.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { DB } from "@anabranch/db";
|
|
13
|
+
* import { createPostgres } from "@anabranch/db-postgres";
|
|
14
|
+
*
|
|
15
|
+
* const db = new DB(
|
|
16
|
+
* await createPostgres({
|
|
17
|
+
* connectionString: "postgresql://user:pass@localhost:5432/mydb",
|
|
18
|
+
* }).connect(),
|
|
19
|
+
* );
|
|
20
|
+
*
|
|
21
|
+
* const users = await db
|
|
22
|
+
* .query<{ id: number; name: string }>("SELECT * FROM users")
|
|
23
|
+
* .run();
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
1
28
|
export { createPostgres, type PostgresConnector, type PostgresOptions, } from "./postgres.js";
|
|
2
29
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db-postgres/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/db-postgres/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,OAAO,EACL,cAAc,EACd,KAAK,iBAAiB,EACtB,KAAK,eAAe,GACrB,MAAM,eAAe,CAAC"}
|
package/esm/db-postgres/index.js
CHANGED
|
@@ -1 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @anabranch/db-postgres
|
|
3
|
+
*
|
|
4
|
+
* PostgreSQL database connector for the @anabranch/db package using `node:pg`.
|
|
5
|
+
*
|
|
6
|
+
* Provides a `DBConnector` implementation with connection pooling and
|
|
7
|
+
* cursor-based streaming via `pg-cursor` for memory-efficient processing
|
|
8
|
+
* of large result sets.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* import { DB } from "@anabranch/db";
|
|
13
|
+
* import { createPostgres } from "@anabranch/db-postgres";
|
|
14
|
+
*
|
|
15
|
+
* const db = new DB(
|
|
16
|
+
* await createPostgres({
|
|
17
|
+
* connectionString: "postgresql://user:pass@localhost:5432/mydb",
|
|
18
|
+
* }).connect(),
|
|
19
|
+
* );
|
|
20
|
+
*
|
|
21
|
+
* const users = await db
|
|
22
|
+
* .query<{ id: number; name: string }>("SELECT * FROM users")
|
|
23
|
+
* .run();
|
|
24
|
+
* ```
|
|
25
|
+
*
|
|
26
|
+
* @module
|
|
27
|
+
*/
|
|
1
28
|
export { createPostgres, } from "./postgres.js";
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
import type { DBAdapter } from "../db/index.js";
|
|
2
|
+
/** Creates a PostgreSQL connector with connection pooling. */
|
|
2
3
|
export declare function createPostgres(options?: PostgresOptions): PostgresConnector;
|
|
3
|
-
|
|
4
|
+
/** Connection options for PostgreSQL. */
|
|
5
|
+
export type PostgresOptions = {
|
|
6
|
+
/** @default "localhost" */
|
|
4
7
|
host?: string;
|
|
8
|
+
/** @default 5432 */
|
|
5
9
|
port?: number;
|
|
10
|
+
/** @default "postgres" */
|
|
6
11
|
user?: string;
|
|
12
|
+
/** @default "" */
|
|
7
13
|
password?: string;
|
|
14
|
+
/** @default "postgres" */
|
|
8
15
|
database?: string;
|
|
9
16
|
connectionString?: string;
|
|
10
17
|
max?: number;
|
|
11
18
|
idleTimeoutMillis?: number;
|
|
12
19
|
connectionTimeoutMillis?: number;
|
|
13
20
|
};
|
|
21
|
+
/** PostgreSQL database connector. */
|
|
14
22
|
export interface PostgresConnector {
|
|
23
|
+
/** Connects and returns a DBAdapter for query execution. */
|
|
15
24
|
connect(signal?: AbortSignal): Promise<DBAdapter>;
|
|
25
|
+
/** Closes the connection pool. */
|
|
16
26
|
end(): Promise<void>;
|
|
17
27
|
}
|
|
18
|
-
export type { PostgresOptions };
|
|
19
28
|
//# sourceMappingURL=postgres.d.ts.map
|
|
@@ -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,wBAAgB,cAAc,CAC5B,OAAO,GAAE,eAAoB,GAC5B,iBAAiB,CA4CnB;AAED,
|
|
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,8DAA8D;AAC9D,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,6 +2,7 @@ import pg from "pg";
|
|
|
2
2
|
import Cursor from "pg-cursor";
|
|
3
3
|
import process from "node:process";
|
|
4
4
|
const { Pool } = pg;
|
|
5
|
+
/** Creates a PostgreSQL connector with connection pooling. */
|
|
5
6
|
export function createPostgres(options = {}) {
|
|
6
7
|
const pool = new Pool(toPoolConfig(options));
|
|
7
8
|
return {
|