@runlot/pg 0.1.0-rc.100
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 +60 -0
- package/dist/bundler.d.ts +33 -0
- package/dist/bundler.d.ts.map +1 -0
- package/dist/bundler.js +276 -0
- package/dist/bundler.js.map +1 -0
- package/dist/client.d.ts +138 -0
- package/dist/client.d.ts.map +1 -0
- package/dist/client.js +505 -0
- package/dist/client.js.map +1 -0
- package/dist/emitter.d.ts +14 -0
- package/dist/emitter.d.ts.map +1 -0
- package/dist/emitter.js +63 -0
- package/dist/emitter.js.map +1 -0
- package/dist/errors.d.ts +34 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +46 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/dist/orm/drizzle.d.ts +9 -0
- package/dist/orm/drizzle.d.ts.map +1 -0
- package/dist/orm/drizzle.js +13 -0
- package/dist/orm/drizzle.js.map +1 -0
- package/dist/orm/knex.d.ts +6 -0
- package/dist/orm/knex.d.ts.map +1 -0
- package/dist/orm/knex.js +28 -0
- package/dist/orm/knex.js.map +1 -0
- package/dist/orm/kysely.d.ts +5 -0
- package/dist/orm/kysely.d.ts.map +1 -0
- package/dist/orm/kysely.js +14 -0
- package/dist/orm/kysely.js.map +1 -0
- package/dist/orm/prisma.d.ts +49 -0
- package/dist/orm/prisma.d.ts.map +1 -0
- package/dist/orm/prisma.js +344 -0
- package/dist/orm/prisma.js.map +1 -0
- package/dist/orm/sequelize.d.ts +4 -0
- package/dist/orm/sequelize.d.ts.map +1 -0
- package/dist/orm/sequelize.js +24 -0
- package/dist/orm/sequelize.js.map +1 -0
- package/dist/orm/typeorm.d.ts +11 -0
- package/dist/orm/typeorm.d.ts.map +1 -0
- package/dist/orm/typeorm.js +22 -0
- package/dist/orm/typeorm.js.map +1 -0
- package/dist/type-parsers.d.ts +159 -0
- package/dist/type-parsers.d.ts.map +1 -0
- package/dist/type-parsers.js +329 -0
- package/dist/type-parsers.js.map +1 -0
- package/dist/types.d.ts +93 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/package.json +83 -0
package/dist/errors.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The shape of node-postgres' `DatabaseError`.
|
|
3
|
+
*
|
|
4
|
+
* ORMs read the SQLSTATE out of `err.code` (Prisma's 23505 → unique violation
|
|
5
|
+
* mapping, Knex's retry decision). The Error that `env.db.exec` throws loses
|
|
6
|
+
* its custom fields at the RPC boundary, but this adapter is JS inside the
|
|
7
|
+
* worker and can make its own Error — so it takes the value from `tryExec` and
|
|
8
|
+
* throws here.
|
|
9
|
+
*/
|
|
10
|
+
export class DatabaseError extends Error {
|
|
11
|
+
code;
|
|
12
|
+
severity;
|
|
13
|
+
detail;
|
|
14
|
+
hint;
|
|
15
|
+
position;
|
|
16
|
+
/** pg always keeps this field. We have no value for it, so it stays
|
|
17
|
+
* undefined. */
|
|
18
|
+
schema = undefined;
|
|
19
|
+
table = undefined;
|
|
20
|
+
column = undefined;
|
|
21
|
+
constraint = undefined;
|
|
22
|
+
dataType = undefined;
|
|
23
|
+
file = undefined;
|
|
24
|
+
line = undefined;
|
|
25
|
+
routine = undefined;
|
|
26
|
+
internalPosition = undefined;
|
|
27
|
+
internalQuery = undefined;
|
|
28
|
+
where = undefined;
|
|
29
|
+
length;
|
|
30
|
+
constructor(e) {
|
|
31
|
+
super(e.message);
|
|
32
|
+
// pg's DatabaseError has the name "error". There is code that checks that
|
|
33
|
+
// value.
|
|
34
|
+
this.name = "error";
|
|
35
|
+
this.code = e.code;
|
|
36
|
+
this.severity = e.severity;
|
|
37
|
+
this.detail = e.detail ?? undefined;
|
|
38
|
+
this.hint = e.hint ?? undefined;
|
|
39
|
+
this.position = e.position ?? undefined;
|
|
40
|
+
this.length = e.message.length;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
export function isDatabaseError(e) {
|
|
44
|
+
return e instanceof DatabaseError;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"errors.js","sourceRoot":"","sources":["../src/errors.ts"],"names":[],"mappings":"AAEA;;;;;;;;GAQG;AACH,MAAM,OAAO,aAAc,SAAQ,KAAK;IAC7B,IAAI,CAAS;IACb,QAAQ,CAAS;IACjB,MAAM,CAAqB;IAC3B,IAAI,CAAqB;IACzB,QAAQ,CAAqB;IACtC;qBACiB;IACR,MAAM,GAAuB,SAAS,CAAC;IACvC,KAAK,GAAuB,SAAS,CAAC;IACtC,MAAM,GAAuB,SAAS,CAAC;IACvC,UAAU,GAAuB,SAAS,CAAC;IAC3C,QAAQ,GAAuB,SAAS,CAAC;IACzC,IAAI,GAAuB,SAAS,CAAC;IACrC,IAAI,GAAuB,SAAS,CAAC;IACrC,OAAO,GAAuB,SAAS,CAAC;IACxC,gBAAgB,GAAuB,SAAS,CAAC;IACjD,aAAa,GAAuB,SAAS,CAAC;IAC9C,KAAK,GAAuB,SAAS,CAAC;IACtC,MAAM,CAAS;IAExB,YAAY,CAAc;QACxB,KAAK,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;QACjB,0EAA0E;QAC1E,SAAS;QACT,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC;QACpB,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC;QACnB,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,CAAC;QAC3B,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,MAAM,IAAI,SAAS,CAAC;QACpC,IAAI,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,IAAI,SAAS,CAAC;QAChC,IAAI,CAAC,QAAQ,GAAG,CAAC,CAAC,QAAQ,IAAI,SAAS,CAAC;QACxC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC;IACjC,CAAC;CACF;AAED,MAAM,UAAU,eAAe,CAAC,CAAU;IACxC,OAAO,CAAC,YAAY,aAAa,CAAC;AACpC,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { Client, Pool, PoolClient, pgModule } from "./client.js";
|
|
2
|
+
import { DatabaseError } from "./errors.js";
|
|
3
|
+
export { Client, Pool, PoolClient, defaults, pgModule, parseCommandTag } from "./client.js";
|
|
4
|
+
export type { ClientConfig, PoolConfig, QueryConfig, QueryResult, FieldDef, QueryCallback, PgModule } from "./client.js";
|
|
5
|
+
export { DatabaseError, isDatabaseError } from "./errors.js";
|
|
6
|
+
export { types, builtins, getTypeParser, setTypeParser, parseArray } from "./type-parsers.js";
|
|
7
|
+
export type { Db, DbSession, TryExecResult, DbErrorData, DbColumn, Storage, StorageObject, StorageListPage } from "./types.js";
|
|
8
|
+
declare const escapeIdentifier: (s: string) => string;
|
|
9
|
+
declare const escapeLiteral: (s: string) => string;
|
|
10
|
+
export { escapeIdentifier, escapeLiteral };
|
|
11
|
+
declare const _default: {
|
|
12
|
+
Client: typeof Client;
|
|
13
|
+
Pool: typeof Pool;
|
|
14
|
+
PoolClient: typeof PoolClient;
|
|
15
|
+
DatabaseError: typeof DatabaseError;
|
|
16
|
+
types: {
|
|
17
|
+
builtins: {
|
|
18
|
+
readonly BOOL: 16;
|
|
19
|
+
readonly BYTEA: 17;
|
|
20
|
+
readonly CHAR: 18;
|
|
21
|
+
readonly INT8: 20;
|
|
22
|
+
readonly INT2: 21;
|
|
23
|
+
readonly INT4: 23;
|
|
24
|
+
readonly REGPROC: 24;
|
|
25
|
+
readonly TEXT: 25;
|
|
26
|
+
readonly OID: 26;
|
|
27
|
+
readonly TID: 27;
|
|
28
|
+
readonly XID: 28;
|
|
29
|
+
readonly CID: 29;
|
|
30
|
+
readonly JSON: 114;
|
|
31
|
+
readonly XML: 142;
|
|
32
|
+
readonly PG_NODE_TREE: 194;
|
|
33
|
+
readonly SMGR: 210;
|
|
34
|
+
readonly PATH: 602;
|
|
35
|
+
readonly POLYGON: 604;
|
|
36
|
+
readonly CIDR: 650;
|
|
37
|
+
readonly FLOAT4: 700;
|
|
38
|
+
readonly FLOAT8: 701;
|
|
39
|
+
readonly ABSTIME: 702;
|
|
40
|
+
readonly RELTIME: 703;
|
|
41
|
+
readonly TINTERVAL: 704;
|
|
42
|
+
readonly CIRCLE: 718;
|
|
43
|
+
readonly MACADDR8: 774;
|
|
44
|
+
readonly MONEY: 790;
|
|
45
|
+
readonly MACADDR: 829;
|
|
46
|
+
readonly INET: 869;
|
|
47
|
+
readonly ACLITEM: 1033;
|
|
48
|
+
readonly BPCHAR: 1042;
|
|
49
|
+
readonly VARCHAR: 1043;
|
|
50
|
+
readonly DATE: 1082;
|
|
51
|
+
readonly TIME: 1083;
|
|
52
|
+
readonly TIMESTAMP: 1114;
|
|
53
|
+
readonly TIMESTAMPTZ: 1184;
|
|
54
|
+
readonly INTERVAL: 1186;
|
|
55
|
+
readonly TIMETZ: 1266;
|
|
56
|
+
readonly BIT: 1560;
|
|
57
|
+
readonly VARBIT: 1562;
|
|
58
|
+
readonly NUMERIC: 1700;
|
|
59
|
+
readonly REFCURSOR: 1790;
|
|
60
|
+
readonly REGPROCEDURE: 2202;
|
|
61
|
+
readonly REGOPER: 2203;
|
|
62
|
+
readonly REGOPERATOR: 2204;
|
|
63
|
+
readonly REGCLASS: 2205;
|
|
64
|
+
readonly REGTYPE: 2206;
|
|
65
|
+
readonly UUID: 2950;
|
|
66
|
+
readonly TXID_SNAPSHOT: 2970;
|
|
67
|
+
readonly PG_LSN: 3220;
|
|
68
|
+
readonly PG_NDISTINCT: 3361;
|
|
69
|
+
readonly PG_DEPENDENCIES: 3402;
|
|
70
|
+
readonly TSVECTOR: 3614;
|
|
71
|
+
readonly TSQUERY: 3615;
|
|
72
|
+
readonly GTSVECTOR: 3642;
|
|
73
|
+
readonly REGCONFIG: 3734;
|
|
74
|
+
readonly REGDICTIONARY: 3769;
|
|
75
|
+
readonly JSONB: 3802;
|
|
76
|
+
readonly REGNAMESPACE: 4089;
|
|
77
|
+
readonly REGROLE: 4096;
|
|
78
|
+
};
|
|
79
|
+
getTypeParser: typeof import("./type-parsers.js").getTypeParser;
|
|
80
|
+
setTypeParser: typeof import("./type-parsers.js").setTypeParser;
|
|
81
|
+
arrayParser: {
|
|
82
|
+
create: (s: string, p: import("./type-parsers.js").TypeParser) => {
|
|
83
|
+
parse: () => unknown[];
|
|
84
|
+
};
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
defaults: Record<string, unknown>;
|
|
88
|
+
pgModule: typeof pgModule;
|
|
89
|
+
native: null;
|
|
90
|
+
escapeIdentifier: (s: string) => string;
|
|
91
|
+
escapeLiteral: (s: string) => string;
|
|
92
|
+
};
|
|
93
|
+
export default _default;
|
|
94
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAY,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAG5C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC5F,YAAY,EAAE,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,QAAQ,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACzH,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAC9F,YAAY,EAAE,EAAE,EAAE,SAAS,EAAE,aAAa,EAAE,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAE/H,QAAA,MAAM,gBAAgB,uBAAoC,CAAC;AAC3D,QAAA,MAAM,aAAa,uBAAiC,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAE3C,wBAWE"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @runlot/pg — a node-postgres compatible adapter on top of `env.db`
|
|
2
|
+
// (docs/pg-driver-support.md §3.2).
|
|
3
|
+
//
|
|
4
|
+
// The default export has the shape of the `pg` module. When an ORM looks for the driver
|
|
5
|
+
// with `import pg from "pg"`, a bundler alias (`pg` → `@runlot/pg`) hands it this module.
|
|
6
|
+
import { Client, Pool, PoolClient, defaults, pgModule } from "./client.js";
|
|
7
|
+
import { DatabaseError } from "./errors.js";
|
|
8
|
+
import { types } from "./type-parsers.js";
|
|
9
|
+
export { Client, Pool, PoolClient, defaults, pgModule, parseCommandTag } from "./client.js";
|
|
10
|
+
export { DatabaseError, isDatabaseError } from "./errors.js";
|
|
11
|
+
export { types, builtins, getTypeParser, setTypeParser, parseArray } from "./type-parsers.js";
|
|
12
|
+
const escapeIdentifier = Client.prototype.escapeIdentifier;
|
|
13
|
+
const escapeLiteral = Client.prototype.escapeLiteral;
|
|
14
|
+
export { escapeIdentifier, escapeLiteral };
|
|
15
|
+
export default {
|
|
16
|
+
Client,
|
|
17
|
+
Pool,
|
|
18
|
+
PoolClient,
|
|
19
|
+
DatabaseError,
|
|
20
|
+
types,
|
|
21
|
+
defaults,
|
|
22
|
+
pgModule,
|
|
23
|
+
native: null,
|
|
24
|
+
escapeIdentifier,
|
|
25
|
+
escapeLiteral,
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,qEAAqE;AACrE,oCAAoC;AACpC,EAAE;AACF,wFAAwF;AACxF,0FAA0F;AAC1F,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAE1C,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE5F,OAAO,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC7D,OAAO,EAAE,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG9F,MAAM,gBAAgB,GAAG,MAAM,CAAC,SAAS,CAAC,gBAAgB,CAAC;AAC3D,MAAM,aAAa,GAAG,MAAM,CAAC,SAAS,CAAC,aAAa,CAAC;AACrD,OAAO,EAAE,gBAAgB,EAAE,aAAa,EAAE,CAAC;AAE3C,eAAe;IACb,MAAM;IACN,IAAI;IACJ,UAAU;IACV,aAAa;IACb,KAAK;IACL,QAAQ;IACR,QAAQ;IACR,MAAM,EAAE,IAAI;IACZ,gBAAgB;IAChB,aAAa;CACd,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type NodePgDatabase } from "drizzle-orm/node-postgres";
|
|
2
|
+
import type { DrizzleConfig } from "drizzle-orm";
|
|
3
|
+
import { Pool } from "../client.js";
|
|
4
|
+
import type { Db } from "../types.js";
|
|
5
|
+
export type { NodePgDatabase };
|
|
6
|
+
export declare function drizzle<TSchema extends Record<string, unknown> = Record<string, never>>(db: Db, config?: DrizzleConfig<TSchema>): NodePgDatabase<TSchema> & {
|
|
7
|
+
$client: Pool;
|
|
8
|
+
};
|
|
9
|
+
//# sourceMappingURL=drizzle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.d.ts","sourceRoot":"","sources":["../../src/orm/drizzle.ts"],"names":[],"mappings":"AAMA,OAAO,EAAqB,KAAK,cAAc,EAAE,MAAM,2BAA2B,CAAC;AACnF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAGjD,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AACpC,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtC,YAAY,EAAE,cAAc,EAAE,CAAC;AAE/B,wBAAgB,OAAO,CAAC,OAAO,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,EACrF,EAAE,EAAE,EAAE,EACN,MAAM,CAAC,EAAE,aAAa,CAAC,OAAO,CAAC,GAC9B,cAAc,CAAC,OAAO,CAAC,GAAG;IAAE,OAAO,EAAE,IAAI,CAAA;CAAE,CAG7C"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// Drizzle: we give our Pool to `drizzle-orm/node-postgres`.
|
|
2
|
+
//
|
|
3
|
+
// Drizzle only calls `client.query({text, values, rowMode:'array', types})`
|
|
4
|
+
// (session.js). It tries to receive dates and intervals as strings through
|
|
5
|
+
// `types.getTypeParser`, and this adapter's per-query parser injection supports
|
|
6
|
+
// exactly that.
|
|
7
|
+
import { drizzle as nodePg } from "drizzle-orm/node-postgres";
|
|
8
|
+
import { Pool } from "../client.js";
|
|
9
|
+
export function drizzle(db, config) {
|
|
10
|
+
const pool = new Pool({ db });
|
|
11
|
+
return nodePg({ client: pool, ...(config ?? {}) });
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=drizzle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"drizzle.js","sourceRoot":"","sources":["../../src/orm/drizzle.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,EAAE;AACF,4EAA4E;AAC5E,2EAA2E;AAC3E,gFAAgF;AAChF,gBAAgB;AAChB,OAAO,EAAE,OAAO,IAAI,MAAM,EAAuB,MAAM,2BAA2B,CAAC;AAInF,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAKpC,MAAM,UAAU,OAAO,CACrB,EAAM,EACN,MAA+B;IAE/B,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC;IAC9B,OAAO,MAAM,CAAC,EAAE,MAAM,EAAE,IAAyB,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,CAA2D,CAAC;AACpI,CAAC"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Knex } from "knex";
|
|
2
|
+
import PgClient from "knex/lib/dialects/postgres/index.js";
|
|
3
|
+
import type { Db } from "../types.js";
|
|
4
|
+
export declare function knexClient(db: Db): typeof PgClient;
|
|
5
|
+
export declare function knex(db: Db, config?: Omit<Knex.Config, "client" | "connection">): Knex;
|
|
6
|
+
//# sourceMappingURL=knex.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knex.d.ts","sourceRoot":"","sources":["../../src/orm/knex.ts"],"names":[],"mappings":"AAMA,OAAoB,EAAE,KAAK,IAAI,EAAE,MAAM,MAAM,CAAC;AAC9C,OAAO,QAAQ,MAAM,qCAAqC,CAAC;AAG3D,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtC,wBAAgB,UAAU,CAAC,EAAE,EAAE,EAAE,GAAG,OAAO,QAAQ,CAOlD;AAED,wBAAgB,IAAI,CAAC,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE,QAAQ,GAAG,YAAY,CAAC,GAAG,IAAI,CAStF"}
|
package/dist/orm/knex.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Knex: the `_driver()` of `client: 'pg'` does `require('pg')`. We build a client
|
|
2
|
+
// class that puts our module in that spot — Knex accepts a class for `client`.
|
|
3
|
+
//
|
|
4
|
+
// Knex's pg client does `new Client()` + `connect()` per connection and reads
|
|
5
|
+
// `select version()` on the first one. The pool is managed by tarn; with a
|
|
6
|
+
// minimum size of 0 it holds no idle sessions.
|
|
7
|
+
import knexFactory, {} from "knex";
|
|
8
|
+
import PgClient from "knex/lib/dialects/postgres/index.js";
|
|
9
|
+
import { pgModule } from "../client.js";
|
|
10
|
+
export function knexClient(db) {
|
|
11
|
+
const mod = pgModule(db);
|
|
12
|
+
return class RunlotPgClient extends PgClient {
|
|
13
|
+
_driver() {
|
|
14
|
+
return mod;
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
export function knex(db, config) {
|
|
19
|
+
return knexFactory({
|
|
20
|
+
...(config ?? {}),
|
|
21
|
+
client: knexClient(db),
|
|
22
|
+
// A value has to be here or Knex warns that there is no connection. This
|
|
23
|
+
// object goes straight into `new Client(options)`, so it carries no `db` key.
|
|
24
|
+
connection: { runlot: true },
|
|
25
|
+
pool: { min: 0, max: 4, ...(config?.pool ?? {}) },
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=knex.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"knex.js","sourceRoot":"","sources":["../../src/orm/knex.ts"],"names":[],"mappings":"AAAA,kFAAkF;AAClF,+EAA+E;AAC/E,EAAE;AACF,8EAA8E;AAC9E,2EAA2E;AAC3E,+CAA+C;AAC/C,OAAO,WAAW,EAAE,EAAa,MAAM,MAAM,CAAC;AAC9C,OAAO,QAAQ,MAAM,qCAAqC,CAAC;AAE3D,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAGxC,MAAM,UAAU,UAAU,CAAC,EAAM;IAC/B,MAAM,GAAG,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;IACzB,OAAO,MAAM,cAAe,SAAQ,QAAQ;QAC1C,OAAO;YACL,OAAO,GAAG,CAAC;QACb,CAAC;KACiB,CAAC;AACvB,CAAC;AAED,MAAM,UAAU,IAAI,CAAC,EAAM,EAAE,MAAmD;IAC9E,OAAO,WAAW,CAAC;QACjB,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;QACjB,MAAM,EAAE,UAAU,CAAC,EAAE,CAAsB;QAC3C,yEAAyE;QACzE,8EAA8E;QAC9E,UAAU,EAAE,EAAE,MAAM,EAAE,IAAI,EAAuB;QACjD,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,IAAI,IAAI,EAAE,CAAC,EAAE;KAClD,CAAC,CAAC;AACL,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { Kysely, PostgresDialect, type KyselyConfig } from "kysely";
|
|
2
|
+
import type { Db } from "../types.js";
|
|
3
|
+
export declare function kyselyDialect(db: Db): PostgresDialect;
|
|
4
|
+
export declare function kysely<DB>(db: Db, config?: Omit<KyselyConfig, "dialect">): Kysely<DB>;
|
|
5
|
+
//# sourceMappingURL=kysely.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely.d.ts","sourceRoot":"","sources":["../../src/orm/kysely.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,MAAM,EAAE,eAAe,EAAE,KAAK,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGpE,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AAEtC,wBAAgB,aAAa,CAAC,EAAE,EAAE,EAAE,GAAG,eAAe,CAErD;AAED,wBAAgB,MAAM,CAAC,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,CAAC,EAAE,IAAI,CAAC,YAAY,EAAE,SAAS,CAAC,GAAG,MAAM,CAAC,EAAE,CAAC,CAErF"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// Kysely: `PostgresDialect({ pool })`.
|
|
2
|
+
//
|
|
3
|
+
// Kysely calls only `pool.connect()` → `client.query(sql, params)` → `client.release()`,
|
|
4
|
+
// and does transactions with `begin/commit/rollback` statements. PoolClient on top of a
|
|
5
|
+
// session handle fits as it is.
|
|
6
|
+
import { Kysely, PostgresDialect } from "kysely";
|
|
7
|
+
import { Pool } from "../client.js";
|
|
8
|
+
export function kyselyDialect(db) {
|
|
9
|
+
return new PostgresDialect({ pool: new Pool({ db }) });
|
|
10
|
+
}
|
|
11
|
+
export function kysely(db, config) {
|
|
12
|
+
return new Kysely({ ...(config ?? {}), dialect: kyselyDialect(db) });
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=kysely.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kysely.js","sourceRoot":"","sources":["../../src/orm/kysely.ts"],"names":[],"mappings":"AAAA,uCAAuC;AACvC,EAAE;AACF,yFAAyF;AACzF,wFAAwF;AACxF,gCAAgC;AAChC,OAAO,EAAE,MAAM,EAAE,eAAe,EAAqB,MAAM,QAAQ,CAAC;AAEpE,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC,MAAM,UAAU,aAAa,CAAC,EAAM;IAClC,OAAO,IAAI,eAAe,CAAC,EAAE,IAAI,EAAE,IAAI,IAAI,CAAC,EAAE,EAAE,EAAE,CAAU,EAAE,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,MAAM,CAAK,EAAM,EAAE,MAAsC;IACvE,OAAO,IAAI,MAAM,CAAK,EAAE,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAC3E,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { type ConnectionInfo, type IsolationLevel, type SqlDriverAdapter, type SqlDriverAdapterFactory, type SqlQuery, type SqlResultSet, type Transaction } from "@prisma/driver-adapter-utils";
|
|
2
|
+
import { Pool, type QueryResult } from "../client.js";
|
|
3
|
+
import { type TypeParser } from "../type-parsers.js";
|
|
4
|
+
import type { Db } from "../types.js";
|
|
5
|
+
declare class Queryable {
|
|
6
|
+
protected readonly client: {
|
|
7
|
+
query(cfg: {
|
|
8
|
+
text: string;
|
|
9
|
+
values: unknown[];
|
|
10
|
+
rowMode: "array";
|
|
11
|
+
types: {
|
|
12
|
+
getTypeParser(oid: number, format: "text"): TypeParser;
|
|
13
|
+
};
|
|
14
|
+
}): Promise<QueryResult<unknown>>;
|
|
15
|
+
};
|
|
16
|
+
readonly provider: "postgres";
|
|
17
|
+
readonly adapterName = "@runlot/pg/prisma";
|
|
18
|
+
constructor(client: {
|
|
19
|
+
query(cfg: {
|
|
20
|
+
text: string;
|
|
21
|
+
values: unknown[];
|
|
22
|
+
rowMode: "array";
|
|
23
|
+
types: {
|
|
24
|
+
getTypeParser(oid: number, format: "text"): TypeParser;
|
|
25
|
+
};
|
|
26
|
+
}): Promise<QueryResult<unknown>>;
|
|
27
|
+
});
|
|
28
|
+
queryRaw(query: SqlQuery): Promise<SqlResultSet>;
|
|
29
|
+
executeRaw(query: SqlQuery): Promise<number>;
|
|
30
|
+
protected perform(query: SqlQuery): Promise<QueryResult<unknown>>;
|
|
31
|
+
}
|
|
32
|
+
export declare class RunlotPrismaAdapter extends Queryable implements SqlDriverAdapter {
|
|
33
|
+
private readonly pool;
|
|
34
|
+
constructor(pool: Pool);
|
|
35
|
+
startTransaction(isolationLevel?: IsolationLevel): Promise<Transaction>;
|
|
36
|
+
executeScript(script: string): Promise<void>;
|
|
37
|
+
getConnectionInfo(): ConnectionInfo;
|
|
38
|
+
dispose(): Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
/** `new PrismaClient({ adapter: new PrismaRunlot(env.db) })`. */
|
|
41
|
+
export declare class PrismaRunlot implements SqlDriverAdapterFactory {
|
|
42
|
+
private readonly db;
|
|
43
|
+
readonly provider: "postgres";
|
|
44
|
+
readonly adapterName = "@runlot/pg/prisma";
|
|
45
|
+
constructor(db: Db);
|
|
46
|
+
connect(): Promise<SqlDriverAdapter>;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
49
|
+
//# sourceMappingURL=prisma.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prisma.d.ts","sourceRoot":"","sources":["../../src/orm/prisma.ts"],"names":[],"mappings":"AAOA,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,gBAAgB,EACrB,KAAK,uBAAuB,EAC5B,KAAK,QAAQ,EACb,KAAK,YAAY,EACjB,KAAK,WAAW,EAEjB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EAAE,IAAI,EAAc,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAElE,OAAO,EAAwB,KAAK,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAC3E,OAAO,KAAK,EAAE,EAAE,EAAE,MAAM,aAAa,CAAC;AA0NtC,cAAM,SAAS;IAGD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,OAAO,EAAE,CAAC;YAAC,OAAO,EAAE,OAAO,CAAC;YAAC,KAAK,EAAE;gBAAE,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAAA;aAAE,CAAA;SAAE,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAA;KAAE;IAF9M,QAAQ,CAAC,QAAQ,EAAG,UAAU,CAAU;IACxC,QAAQ,CAAC,WAAW,uBAAgB;gBACL,MAAM,EAAE;QAAE,KAAK,CAAC,GAAG,EAAE;YAAE,IAAI,EAAE,MAAM,CAAC;YAAC,MAAM,EAAE,OAAO,EAAE,CAAC;YAAC,OAAO,EAAE,OAAO,CAAC;YAAC,KAAK,EAAE;gBAAE,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,UAAU,CAAA;aAAE,CAAA;SAAE,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC,CAAA;KAAE;IAExM,QAAQ,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC;IAShD,UAAU,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC;cAIlC,OAAO,CAAC,KAAK,EAAE,QAAQ,GAAG,OAAO,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;CAaxE;AAkCD,qBAAa,mBAAoB,SAAQ,SAAU,YAAW,gBAAgB;IAChE,OAAO,CAAC,QAAQ,CAAC,IAAI;gBAAJ,IAAI,EAAE,IAAI;IAIjC,gBAAgB,CAAC,cAAc,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;IAavE,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAUlD,iBAAiB,IAAI,cAAc;IAI7B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAG/B;AAED,iEAAiE;AACjE,qBAAa,YAAa,YAAW,uBAAuB;IAG9C,OAAO,CAAC,QAAQ,CAAC,EAAE;IAF/B,QAAQ,CAAC,QAAQ,EAAG,UAAU,CAAU;IACxC,QAAQ,CAAC,WAAW,uBAAgB;gBACP,EAAE,EAAE,EAAE;IAC7B,OAAO,IAAI,OAAO,CAAC,gBAAgB,CAAC;CAG3C"}
|