@rudderjs/database 1.1.0
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/LICENSE +21 -0
- package/dist/db.d.ts +78 -0
- package/dist/db.d.ts.map +1 -0
- package/dist/db.js +142 -0
- package/dist/db.js.map +1 -0
- package/dist/execution.d.ts +2 -0
- package/dist/execution.d.ts.map +1 -0
- package/dist/execution.js +13 -0
- package/dist/execution.js.map +1 -0
- package/dist/expression.d.ts +2 -0
- package/dist/expression.d.ts.map +1 -0
- package/dist/expression.js +6 -0
- package/dist/expression.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -0
- package/dist/registry-bridge.d.ts +69 -0
- package/dist/registry-bridge.d.ts.map +1 -0
- package/dist/registry-bridge.js +107 -0
- package/dist/registry-bridge.js.map +1 -0
- package/package.json +43 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Suleiman Shahbari
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/db.d.ts
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import type { QueryListener, Row } from '@rudderjs/contracts';
|
|
2
|
+
import { Expression } from './expression.js';
|
|
3
|
+
/**
|
|
4
|
+
* A scoped facade over one NAMED connection — what `DB.connection('reporting')`
|
|
5
|
+
* returns. Same raw-SQL surface as `DB`, resolved against that connection's
|
|
6
|
+
* adapter (opened lazily on first use). One divergence from the root facade:
|
|
7
|
+
* `listen()` is async here, because attaching the listener may first open the
|
|
8
|
+
* connection.
|
|
9
|
+
*/
|
|
10
|
+
export interface DBConnection {
|
|
11
|
+
select(sql: string, bindings?: readonly unknown[]): Promise<Row[]>;
|
|
12
|
+
insert(sql: string, bindings?: readonly unknown[]): Promise<number>;
|
|
13
|
+
update(sql: string, bindings?: readonly unknown[]): Promise<number>;
|
|
14
|
+
delete(sql: string, bindings?: readonly unknown[]): Promise<number>;
|
|
15
|
+
statement(sql: string, bindings?: readonly unknown[]): Promise<number>;
|
|
16
|
+
transaction<T>(fn: () => Promise<T>): Promise<T>;
|
|
17
|
+
listen(listener: QueryListener): Promise<void>;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* The DB facade. Raw-SQL escape hatch over the active ORM adapter, mirroring
|
|
21
|
+
* Laravel's `DB` facade. All methods take positional `bindings` (`?` / `$n`
|
|
22
|
+
* placeholders) — values are never string-interpolated into `sql`.
|
|
23
|
+
*/
|
|
24
|
+
export declare const DB: {
|
|
25
|
+
/** Run a raw `SELECT` and resolve to the matched rows. */
|
|
26
|
+
readonly select: (sql: string, bindings?: readonly unknown[]) => Promise<Row[]>;
|
|
27
|
+
/** Run a raw `INSERT`. Resolves to the number of rows affected. */
|
|
28
|
+
readonly insert: (sql: string, bindings?: readonly unknown[]) => Promise<number>;
|
|
29
|
+
/** Run a raw `UPDATE`. Resolves to the number of rows affected. */
|
|
30
|
+
readonly update: (sql: string, bindings?: readonly unknown[]) => Promise<number>;
|
|
31
|
+
/** Run a raw `DELETE`. Resolves to the number of rows affected. */
|
|
32
|
+
readonly delete: (sql: string, bindings?: readonly unknown[]) => Promise<number>;
|
|
33
|
+
/** Run an arbitrary raw statement (DDL, etc.). Resolves to rows affected. */
|
|
34
|
+
readonly statement: (sql: string, bindings?: readonly unknown[]) => Promise<number>;
|
|
35
|
+
/**
|
|
36
|
+
* Run `fn` inside a database transaction, mirroring Laravel's `DB::transaction`.
|
|
37
|
+
* Every `Model.*` and `DB.*` call issued inside `fn` runs on the *same* open
|
|
38
|
+
* transaction — the runner (pushed in by `@rudderjs/orm`) threads the
|
|
39
|
+
* transaction-scoped adapter through `AsyncLocalStorage`, so no connection is
|
|
40
|
+
* passed around. Commits when `fn` resolves; rolls back and re-throws if it
|
|
41
|
+
* rejects. Nested `DB.transaction()` / `Model.transaction()` calls map to
|
|
42
|
+
* savepoints where the driver supports them.
|
|
43
|
+
*
|
|
44
|
+
* @throws if no transaction runner is registered (no database provider loaded),
|
|
45
|
+
* or if the active adapter doesn't implement `transaction()`.
|
|
46
|
+
*/
|
|
47
|
+
readonly transaction: <T>(fn: () => Promise<T>) => Promise<T>;
|
|
48
|
+
/**
|
|
49
|
+
* Register a query listener, mirroring Laravel's `DB::listen`. The listener
|
|
50
|
+
* fires once per executed query with `{ sql, bindings, duration }` (duration
|
|
51
|
+
* in ms) — use it for app-level query logging or slow-query alerting.
|
|
52
|
+
* Delegates to the active adapter's `onQuery()` hook; listener errors are
|
|
53
|
+
* swallowed by the adapter and never break the query.
|
|
54
|
+
*
|
|
55
|
+
* Synchronous, unlike the exec methods — registration happens immediately
|
|
56
|
+
* against the adapter resolved at call time.
|
|
57
|
+
*
|
|
58
|
+
* @throws if no adapter is registered, or the active adapter doesn't
|
|
59
|
+
* implement query listening (`onQuery`).
|
|
60
|
+
*/
|
|
61
|
+
readonly listen: (listener: QueryListener) => void;
|
|
62
|
+
/** Wrap a literal SQL fragment so the query layer splices it verbatim. */
|
|
63
|
+
readonly raw: (value: string | number) => Expression;
|
|
64
|
+
/**
|
|
65
|
+
* A facade scoped to a NAMED connection from `config/database.ts`'s
|
|
66
|
+
* `connections` map, mirroring Laravel's `DB::connection('name')`. The
|
|
67
|
+
* connection opens lazily on the first executed call (cheap to call this
|
|
68
|
+
* method itself — it resolves nothing). Inside a `transaction(fn,
|
|
69
|
+
* { connection: name })` callback, calls on the matching scoped facade join
|
|
70
|
+
* that open transaction.
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* const rows = await DB.connection('reporting').select('select * from stats')
|
|
74
|
+
* await DB.connection('reporting').transaction(async () => { ... })
|
|
75
|
+
*/
|
|
76
|
+
readonly connection: (name: string) => DBConnection;
|
|
77
|
+
};
|
|
78
|
+
//# sourceMappingURL=db.d.ts.map
|
package/dist/db.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.d.ts","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAc,aAAa,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA;AAOzE,OAAO,EAAE,UAAU,EAAO,MAAM,iBAAiB,CAAA;AAoCjD;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,CAAA;IAClE,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,SAAS,OAAO,EAAE,GAAG,OAAO,CAAC,MAAM,CAAC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OAWG;gCACc,MAAM,KAAG,YAAY;CA0B9B,CAAA"}
|
package/dist/db.js
ADDED
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
// ─── DB facade ─────────────────────────────────────────────
|
|
2
|
+
//
|
|
3
|
+
// Laravel-style raw-SQL entry point: `DB.select / insert / update / delete /
|
|
4
|
+
// statement / raw / listen`. It resolves the active ORM adapter (via the
|
|
5
|
+
// registry bridge) and maps onto the adapter's raw-exec seam:
|
|
6
|
+
// - reads (select) → adapter.selectRaw → Row[]
|
|
7
|
+
// - writes (insert/update/delete/statement) → adapter.affectingStatement → number
|
|
8
|
+
// - query listening (listen) → adapter.onQuery
|
|
9
|
+
//
|
|
10
|
+
// One adapter instance is shared with the Models — no second connection. If the
|
|
11
|
+
// active adapter doesn't implement the seam (older/partial adapters), each method
|
|
12
|
+
// throws a clear error naming that adapter.
|
|
13
|
+
import { resolveAdapter, resolveTransactionRunner, resolveConnectionResolver, resolveNamedTransactionRunner, } from './registry-bridge.js';
|
|
14
|
+
import { raw } from './expression.js';
|
|
15
|
+
function adapterName(adapter) {
|
|
16
|
+
return adapter.constructor?.name ?? 'the active adapter';
|
|
17
|
+
}
|
|
18
|
+
function requireSelectRaw(adapter) {
|
|
19
|
+
if (typeof adapter.selectRaw !== 'function') {
|
|
20
|
+
throw new Error(`[RudderJS DB] ${adapterName(adapter)} does not implement selectRaw() — ` +
|
|
21
|
+
'this adapter cannot run raw DB.select() queries.');
|
|
22
|
+
}
|
|
23
|
+
return adapter.selectRaw.bind(adapter);
|
|
24
|
+
}
|
|
25
|
+
function requireAffecting(adapter) {
|
|
26
|
+
if (typeof adapter.affectingStatement !== 'function') {
|
|
27
|
+
throw new Error(`[RudderJS DB] ${adapterName(adapter)} does not implement affectingStatement() — ` +
|
|
28
|
+
'this adapter cannot run raw DB.insert()/update()/delete()/statement() calls.');
|
|
29
|
+
}
|
|
30
|
+
return adapter.affectingStatement.bind(adapter);
|
|
31
|
+
}
|
|
32
|
+
function requireOnQuery(adapter) {
|
|
33
|
+
if (typeof adapter.onQuery !== 'function') {
|
|
34
|
+
throw new Error(`[RudderJS DB] ${adapterName(adapter)} does not implement onQuery() — ` +
|
|
35
|
+
'this adapter does not support query listening, so DB.listen() has nothing to hook into.');
|
|
36
|
+
}
|
|
37
|
+
return adapter.onQuery.bind(adapter);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The DB facade. Raw-SQL escape hatch over the active ORM adapter, mirroring
|
|
41
|
+
* Laravel's `DB` facade. All methods take positional `bindings` (`?` / `$n`
|
|
42
|
+
* placeholders) — values are never string-interpolated into `sql`.
|
|
43
|
+
*/
|
|
44
|
+
// `async` (not bare `return`) so a missing-adapter / missing-seam guard throws
|
|
45
|
+
// as a rejected promise rather than synchronously — the facade always presents a
|
|
46
|
+
// Promise-returning contract, so callers can `.catch()` / `await assert.rejects`.
|
|
47
|
+
export const DB = {
|
|
48
|
+
/** Run a raw `SELECT` and resolve to the matched rows. */
|
|
49
|
+
async select(sql, bindings = []) {
|
|
50
|
+
return requireSelectRaw(resolveAdapter())(sql, bindings);
|
|
51
|
+
},
|
|
52
|
+
/** Run a raw `INSERT`. Resolves to the number of rows affected. */
|
|
53
|
+
async insert(sql, bindings = []) {
|
|
54
|
+
return requireAffecting(resolveAdapter())(sql, bindings);
|
|
55
|
+
},
|
|
56
|
+
/** Run a raw `UPDATE`. Resolves to the number of rows affected. */
|
|
57
|
+
async update(sql, bindings = []) {
|
|
58
|
+
return requireAffecting(resolveAdapter())(sql, bindings);
|
|
59
|
+
},
|
|
60
|
+
/** Run a raw `DELETE`. Resolves to the number of rows affected. */
|
|
61
|
+
async delete(sql, bindings = []) {
|
|
62
|
+
return requireAffecting(resolveAdapter())(sql, bindings);
|
|
63
|
+
},
|
|
64
|
+
/** Run an arbitrary raw statement (DDL, etc.). Resolves to rows affected. */
|
|
65
|
+
async statement(sql, bindings = []) {
|
|
66
|
+
return requireAffecting(resolveAdapter())(sql, bindings);
|
|
67
|
+
},
|
|
68
|
+
/**
|
|
69
|
+
* Run `fn` inside a database transaction, mirroring Laravel's `DB::transaction`.
|
|
70
|
+
* Every `Model.*` and `DB.*` call issued inside `fn` runs on the *same* open
|
|
71
|
+
* transaction — the runner (pushed in by `@rudderjs/orm`) threads the
|
|
72
|
+
* transaction-scoped adapter through `AsyncLocalStorage`, so no connection is
|
|
73
|
+
* passed around. Commits when `fn` resolves; rolls back and re-throws if it
|
|
74
|
+
* rejects. Nested `DB.transaction()` / `Model.transaction()` calls map to
|
|
75
|
+
* savepoints where the driver supports them.
|
|
76
|
+
*
|
|
77
|
+
* @throws if no transaction runner is registered (no database provider loaded),
|
|
78
|
+
* or if the active adapter doesn't implement `transaction()`.
|
|
79
|
+
*/
|
|
80
|
+
async transaction(fn) {
|
|
81
|
+
return resolveTransactionRunner()(fn);
|
|
82
|
+
},
|
|
83
|
+
/**
|
|
84
|
+
* Register a query listener, mirroring Laravel's `DB::listen`. The listener
|
|
85
|
+
* fires once per executed query with `{ sql, bindings, duration }` (duration
|
|
86
|
+
* in ms) — use it for app-level query logging or slow-query alerting.
|
|
87
|
+
* Delegates to the active adapter's `onQuery()` hook; listener errors are
|
|
88
|
+
* swallowed by the adapter and never break the query.
|
|
89
|
+
*
|
|
90
|
+
* Synchronous, unlike the exec methods — registration happens immediately
|
|
91
|
+
* against the adapter resolved at call time.
|
|
92
|
+
*
|
|
93
|
+
* @throws if no adapter is registered, or the active adapter doesn't
|
|
94
|
+
* implement query listening (`onQuery`).
|
|
95
|
+
*/
|
|
96
|
+
listen(listener) {
|
|
97
|
+
requireOnQuery(resolveAdapter())(listener);
|
|
98
|
+
},
|
|
99
|
+
/** Wrap a literal SQL fragment so the query layer splices it verbatim. */
|
|
100
|
+
raw(value) {
|
|
101
|
+
return raw(value);
|
|
102
|
+
},
|
|
103
|
+
/**
|
|
104
|
+
* A facade scoped to a NAMED connection from `config/database.ts`'s
|
|
105
|
+
* `connections` map, mirroring Laravel's `DB::connection('name')`. The
|
|
106
|
+
* connection opens lazily on the first executed call (cheap to call this
|
|
107
|
+
* method itself — it resolves nothing). Inside a `transaction(fn,
|
|
108
|
+
* { connection: name })` callback, calls on the matching scoped facade join
|
|
109
|
+
* that open transaction.
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* const rows = await DB.connection('reporting').select('select * from stats')
|
|
113
|
+
* await DB.connection('reporting').transaction(async () => { ... })
|
|
114
|
+
*/
|
|
115
|
+
connection(name) {
|
|
116
|
+
const adapterFor = async () => resolveConnectionResolver()(name);
|
|
117
|
+
return {
|
|
118
|
+
async select(sql, bindings = []) {
|
|
119
|
+
return requireSelectRaw(await adapterFor())(sql, bindings);
|
|
120
|
+
},
|
|
121
|
+
async insert(sql, bindings = []) {
|
|
122
|
+
return requireAffecting(await adapterFor())(sql, bindings);
|
|
123
|
+
},
|
|
124
|
+
async update(sql, bindings = []) {
|
|
125
|
+
return requireAffecting(await adapterFor())(sql, bindings);
|
|
126
|
+
},
|
|
127
|
+
async delete(sql, bindings = []) {
|
|
128
|
+
return requireAffecting(await adapterFor())(sql, bindings);
|
|
129
|
+
},
|
|
130
|
+
async statement(sql, bindings = []) {
|
|
131
|
+
return requireAffecting(await adapterFor())(sql, bindings);
|
|
132
|
+
},
|
|
133
|
+
async transaction(fn) {
|
|
134
|
+
return resolveNamedTransactionRunner()(name, fn);
|
|
135
|
+
},
|
|
136
|
+
async listen(listener) {
|
|
137
|
+
requireOnQuery(await adapterFor())(listener);
|
|
138
|
+
},
|
|
139
|
+
};
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
//# sourceMappingURL=db.js.map
|
package/dist/db.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"db.js","sourceRoot":"","sources":["../src/db.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,6EAA6E;AAC7E,yEAAyE;AACzE,8DAA8D;AAC9D,yEAAyE;AACzE,oFAAoF;AACpF,8DAA8D;AAC9D,EAAE;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execution.ts"],"names":[],"mappings":"AAYA,YAAY,EAAE,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// ─── DB execution contracts (re-export) ────────────────────
|
|
2
|
+
//
|
|
3
|
+
// The canonical execution types — `Row`, `Executor`, `Transaction`,
|
|
4
|
+
// `Connection` — are owned by `@rudderjs/contracts` (the zero-dependency
|
|
5
|
+
// foundation, beside `OrmAdapter`). `@rudderjs/database` is their conceptual
|
|
6
|
+
// home — the DB *facade* — so we re-export them here as the public surface.
|
|
7
|
+
//
|
|
8
|
+
// Keeping the definitions in contracts avoids a build cycle: `@rudderjs/database`
|
|
9
|
+
// depends on `@rudderjs/contracts` (for `OrmAdapter`), so contracts cannot depend
|
|
10
|
+
// back on database. Every adapter already imports from contracts, so there's a
|
|
11
|
+
// single import point and no flag-day when the data layer is later extracted.
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=execution.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execution.js","sourceRoot":"","sources":["../src/execution.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,oEAAoE;AACpE,yEAAyE;AACzE,6EAA6E;AAC7E,4EAA4E;AAC5E,EAAE;AACF,kFAAkF;AAClF,kFAAkF;AAClF,+EAA+E;AAC/E,8EAA8E"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.d.ts","sourceRoot":"","sources":["../src/expression.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
// Raw SQL expression wrapper — moved to @rudderjs/contracts so the query
|
|
2
|
+
// builder's raw methods stay client-safe (@rudderjs/database is node-only).
|
|
3
|
+
// Re-exported here to keep `DB.raw()` and `import { raw } from
|
|
4
|
+
// '@rudderjs/database'` working.
|
|
5
|
+
export { Expression, raw } from '@rudderjs/contracts';
|
|
6
|
+
//# sourceMappingURL=expression.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expression.js","sourceRoot":"","sources":["../src/expression.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,4EAA4E;AAC5E,+DAA+D;AAC/D,iCAAiC;AACjC,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { DB } from './db.js';
|
|
2
|
+
export type { DBConnection } from './db.js';
|
|
3
|
+
export { Expression, raw } from './expression.js';
|
|
4
|
+
export { registerAdapterResolver, resolveAdapter, registerTransactionRunner, resolveTransactionRunner, registerConnectionResolver, resolveConnectionResolver, registerNamedTransactionRunner, resolveNamedTransactionRunner, __resetAdapterResolver, } from './registry-bridge.js';
|
|
5
|
+
export type { TransactionRunner, ConnectionResolver, NamedTransactionRunner } from './registry-bridge.js';
|
|
6
|
+
export type { Row, Executor, Transaction, Connection } from './execution.js';
|
|
7
|
+
export type { QueryEvent, QueryListener } from '@rudderjs/contracts';
|
|
8
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAC5B,YAAY,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,yBAAyB,EACzB,wBAAwB,EACxB,0BAA0B,EAC1B,yBAAyB,EACzB,8BAA8B,EAC9B,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,sBAAsB,CAAA;AAC7B,YAAY,EAAE,iBAAiB,EAAE,kBAAkB,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AACzG,YAAY,EAAE,GAAG,EAAE,QAAQ,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC5E,YAAY,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
// @rudderjs/database — the SQL data-layer foundation.
|
|
2
|
+
//
|
|
3
|
+
// PR1 establishes the package boundary + the public `DB` facade contract. The
|
|
4
|
+
// query-builder breadth, connection manager, and native-engine internals land in
|
|
5
|
+
// later PRs (see docs/plans/2026-06-01-database-package-extraction-PR1.md).
|
|
6
|
+
export { DB } from './db.js';
|
|
7
|
+
export { Expression, raw } from './expression.js';
|
|
8
|
+
export { registerAdapterResolver, resolveAdapter, registerTransactionRunner, resolveTransactionRunner, registerConnectionResolver, resolveConnectionResolver, registerNamedTransactionRunner, resolveNamedTransactionRunner, __resetAdapterResolver, } from './registry-bridge.js';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,sDAAsD;AACtD,EAAE;AACF,8EAA8E;AAC9E,iFAAiF;AACjF,4EAA4E;AAE5E,OAAO,EAAE,EAAE,EAAE,MAAM,SAAS,CAAA;AAE5B,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAA;AACjD,OAAO,EACL,uBAAuB,EACvB,cAAc,EACd,yBAAyB,EACzB,wBAAwB,EACxB,0BAA0B,EAC1B,yBAAyB,EACzB,8BAA8B,EAC9B,6BAA6B,EAC7B,sBAAsB,GACvB,MAAM,sBAAsB,CAAA"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import type { OrmAdapter } from '@rudderjs/contracts';
|
|
2
|
+
/**
|
|
3
|
+
* Runs `fn` inside a database transaction, returning its result. Pushed in by
|
|
4
|
+
* `@rudderjs/orm` (its `transaction()` free function) so `DB.transaction()` reuses
|
|
5
|
+
* the ORM's `AsyncLocalStorage` transaction scoping — every `Model.*` AND `DB.*`
|
|
6
|
+
* call inside `fn` joins the *same* open transaction (one connection, not two).
|
|
7
|
+
* `@rudderjs/database` can't import `@rudderjs/orm`, so the runner is injected the
|
|
8
|
+
* same way the adapter resolver is.
|
|
9
|
+
*/
|
|
10
|
+
export type TransactionRunner = <T>(fn: () => Promise<T>) => Promise<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Resolves the adapter for a NAMED connection (`DB.connection('reporting')`),
|
|
13
|
+
* opening it lazily on first use. Pushed in by `@rudderjs/orm`'s `db-bridge`
|
|
14
|
+
* (it closes over the ConnectionManager + the transaction-scope lookup, so a
|
|
15
|
+
* `DB.connection(name).select()` inside a `transaction(fn, { connection:
|
|
16
|
+
* name })` callback joins that open transaction). Async because the first
|
|
17
|
+
* access may open the connection (driver import + connect).
|
|
18
|
+
*/
|
|
19
|
+
export type ConnectionResolver = (name: string) => Promise<OrmAdapter>;
|
|
20
|
+
/** Runs `fn` inside a transaction on a NAMED connection — the named
|
|
21
|
+
* counterpart of {@link TransactionRunner}, same injection rationale. */
|
|
22
|
+
export type NamedTransactionRunner = <T>(name: string, fn: () => Promise<T>) => Promise<T>;
|
|
23
|
+
/**
|
|
24
|
+
* Register the function that resolves the active ORM adapter. Called once by
|
|
25
|
+
* `@rudderjs/orm`'s `db-bridge` module (imported for side effect from each
|
|
26
|
+
* adapter provider). Idempotent — the last registration wins, which matches a
|
|
27
|
+
* dev HMR re-boot re-installing the same accessor.
|
|
28
|
+
*/
|
|
29
|
+
export declare function registerAdapterResolver(fn: () => OrmAdapter): void;
|
|
30
|
+
/**
|
|
31
|
+
* Resolve the active ORM adapter. Throws a clear error when no resolver has been
|
|
32
|
+
* registered — i.e. `@rudderjs/orm` (and a database provider) wasn't loaded, so
|
|
33
|
+
* there is no adapter for the DB facade to run against.
|
|
34
|
+
*/
|
|
35
|
+
export declare function resolveAdapter(): OrmAdapter;
|
|
36
|
+
/**
|
|
37
|
+
* Register the function that runs work inside a transaction. Called by
|
|
38
|
+
* `@rudderjs/orm`'s `db-bridge` module alongside {@link registerAdapterResolver},
|
|
39
|
+
* passing the ORM's `transaction()` free function (which owns the ALS scoping).
|
|
40
|
+
* Idempotent — last registration wins (a dev HMR re-boot re-installs the same fn).
|
|
41
|
+
*/
|
|
42
|
+
export declare function registerTransactionRunner(fn: TransactionRunner): void;
|
|
43
|
+
/**
|
|
44
|
+
* Resolve the active transaction runner. Throws a clear error when none has been
|
|
45
|
+
* registered — i.e. `@rudderjs/orm` (and a database provider) wasn't loaded.
|
|
46
|
+
*/
|
|
47
|
+
export declare function resolveTransactionRunner(): TransactionRunner;
|
|
48
|
+
/**
|
|
49
|
+
* Register the function that resolves a named connection's adapter. Called by
|
|
50
|
+
* `@rudderjs/orm`'s `db-bridge` module alongside {@link registerAdapterResolver}.
|
|
51
|
+
* Idempotent — last registration wins (dev HMR re-boot re-installs it).
|
|
52
|
+
*/
|
|
53
|
+
export declare function registerConnectionResolver(fn: ConnectionResolver): void;
|
|
54
|
+
/**
|
|
55
|
+
* Resolve the named-connection resolver. Throws a clear error when none has
|
|
56
|
+
* been registered — i.e. `@rudderjs/orm` (and a database provider) wasn't
|
|
57
|
+
* loaded, or the installed `@rudderjs/orm` predates named-connection support.
|
|
58
|
+
*/
|
|
59
|
+
export declare function resolveConnectionResolver(): ConnectionResolver;
|
|
60
|
+
/**
|
|
61
|
+
* Register the function that runs work inside a transaction on a named
|
|
62
|
+
* connection. Called by `@rudderjs/orm`'s `db-bridge` module. Idempotent —
|
|
63
|
+
* last registration wins.
|
|
64
|
+
*/
|
|
65
|
+
export declare function registerNamedTransactionRunner(fn: NamedTransactionRunner): void;
|
|
66
|
+
/** Resolve the named transaction runner. Throws a clear error when none has
|
|
67
|
+
* been registered. */
|
|
68
|
+
export declare function resolveNamedTransactionRunner(): NamedTransactionRunner;
|
|
69
|
+
//# sourceMappingURL=registry-bridge.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-bridge.d.ts","sourceRoot":"","sources":["../src/registry-bridge.ts"],"names":[],"mappings":"AAaA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAErD;;;;;;;GAOG;AACH,MAAM,MAAM,iBAAiB,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;AAEvE;;;;;;;GAOG;AACH,MAAM,MAAM,kBAAkB,GAAG,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,UAAU,CAAC,CAAA;AAEtE;0EAC0E;AAC1E,MAAM,MAAM,sBAAsB,GAAG,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,CAAA;AAO1F;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,EAAE,EAAE,MAAM,UAAU,GAAG,IAAI,CAElE;AAED;;;;GAIG;AACH,wBAAgB,cAAc,IAAI,UAAU,CAS3C;AAED;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,EAAE,EAAE,iBAAiB,GAAG,IAAI,CAErE;AAED;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI,iBAAiB,CAS5D;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,EAAE,EAAE,kBAAkB,GAAG,IAAI,CAEvE;AAED;;;;GAIG;AACH,wBAAgB,yBAAyB,IAAI,kBAAkB,CAU9D;AAED;;;;GAIG;AACH,wBAAgB,8BAA8B,CAAC,EAAE,EAAE,sBAAsB,GAAG,IAAI,CAE/E;AAED;uBACuB;AACvB,wBAAgB,6BAA6B,IAAI,sBAAsB,CAStE"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
// ─── Adapter-resolver bridge (orm → database) ──────────────
|
|
2
|
+
//
|
|
3
|
+
// `@rudderjs/database` must NOT import `@rudderjs/orm` (the dependency direction
|
|
4
|
+
// is orm → database). But the DB facade needs the *same* active adapter the
|
|
5
|
+
// Models use — opening a second connection would violate the one-connection
|
|
6
|
+
// rule. So `@rudderjs/orm` PUSHES its `ModelRegistry.getAdapter` accessor into
|
|
7
|
+
// this module via {@link registerAdapterResolver}; the facade pulls it via
|
|
8
|
+
// {@link resolveAdapter}.
|
|
9
|
+
//
|
|
10
|
+
// Resolving through the accessor (not a cached adapter) means `DB.*` inside a
|
|
11
|
+
// `Model.transaction()` callback transparently joins the open transaction —
|
|
12
|
+
// `ModelRegistry.getAdapter()` already returns the transaction-scoped adapter.
|
|
13
|
+
let resolver = null;
|
|
14
|
+
let txRunner = null;
|
|
15
|
+
let connectionResolver = null;
|
|
16
|
+
let namedTxRunner = null;
|
|
17
|
+
/**
|
|
18
|
+
* Register the function that resolves the active ORM adapter. Called once by
|
|
19
|
+
* `@rudderjs/orm`'s `db-bridge` module (imported for side effect from each
|
|
20
|
+
* adapter provider). Idempotent — the last registration wins, which matches a
|
|
21
|
+
* dev HMR re-boot re-installing the same accessor.
|
|
22
|
+
*/
|
|
23
|
+
export function registerAdapterResolver(fn) {
|
|
24
|
+
resolver = fn;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Resolve the active ORM adapter. Throws a clear error when no resolver has been
|
|
28
|
+
* registered — i.e. `@rudderjs/orm` (and a database provider) wasn't loaded, so
|
|
29
|
+
* there is no adapter for the DB facade to run against.
|
|
30
|
+
*/
|
|
31
|
+
export function resolveAdapter() {
|
|
32
|
+
if (!resolver) {
|
|
33
|
+
throw new Error('[RudderJS DB] No ORM adapter is available. The DB facade resolves the ' +
|
|
34
|
+
'active adapter from @rudderjs/orm — make sure a database provider is ' +
|
|
35
|
+
'registered (and @rudderjs/orm installed) before calling DB.*');
|
|
36
|
+
}
|
|
37
|
+
return resolver();
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Register the function that runs work inside a transaction. Called by
|
|
41
|
+
* `@rudderjs/orm`'s `db-bridge` module alongside {@link registerAdapterResolver},
|
|
42
|
+
* passing the ORM's `transaction()` free function (which owns the ALS scoping).
|
|
43
|
+
* Idempotent — last registration wins (a dev HMR re-boot re-installs the same fn).
|
|
44
|
+
*/
|
|
45
|
+
export function registerTransactionRunner(fn) {
|
|
46
|
+
txRunner = fn;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Resolve the active transaction runner. Throws a clear error when none has been
|
|
50
|
+
* registered — i.e. `@rudderjs/orm` (and a database provider) wasn't loaded.
|
|
51
|
+
*/
|
|
52
|
+
export function resolveTransactionRunner() {
|
|
53
|
+
if (!txRunner) {
|
|
54
|
+
throw new Error('[RudderJS DB] No transaction runner is available. DB.transaction() runs ' +
|
|
55
|
+
'through @rudderjs/orm — make sure a database provider is registered (and ' +
|
|
56
|
+
'@rudderjs/orm installed) before calling DB.transaction().');
|
|
57
|
+
}
|
|
58
|
+
return txRunner;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Register the function that resolves a named connection's adapter. Called by
|
|
62
|
+
* `@rudderjs/orm`'s `db-bridge` module alongside {@link registerAdapterResolver}.
|
|
63
|
+
* Idempotent — last registration wins (dev HMR re-boot re-installs it).
|
|
64
|
+
*/
|
|
65
|
+
export function registerConnectionResolver(fn) {
|
|
66
|
+
connectionResolver = fn;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Resolve the named-connection resolver. Throws a clear error when none has
|
|
70
|
+
* been registered — i.e. `@rudderjs/orm` (and a database provider) wasn't
|
|
71
|
+
* loaded, or the installed `@rudderjs/orm` predates named-connection support.
|
|
72
|
+
*/
|
|
73
|
+
export function resolveConnectionResolver() {
|
|
74
|
+
if (!connectionResolver) {
|
|
75
|
+
throw new Error('[RudderJS DB] No connection resolver is available. DB.connection(name) ' +
|
|
76
|
+
'resolves named connections through @rudderjs/orm — make sure a database ' +
|
|
77
|
+
'provider is registered (and @rudderjs/orm installed) before calling ' +
|
|
78
|
+
'DB.connection().');
|
|
79
|
+
}
|
|
80
|
+
return connectionResolver;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Register the function that runs work inside a transaction on a named
|
|
84
|
+
* connection. Called by `@rudderjs/orm`'s `db-bridge` module. Idempotent —
|
|
85
|
+
* last registration wins.
|
|
86
|
+
*/
|
|
87
|
+
export function registerNamedTransactionRunner(fn) {
|
|
88
|
+
namedTxRunner = fn;
|
|
89
|
+
}
|
|
90
|
+
/** Resolve the named transaction runner. Throws a clear error when none has
|
|
91
|
+
* been registered. */
|
|
92
|
+
export function resolveNamedTransactionRunner() {
|
|
93
|
+
if (!namedTxRunner) {
|
|
94
|
+
throw new Error('[RudderJS DB] No named transaction runner is available. ' +
|
|
95
|
+
'DB.connection(name).transaction() runs through @rudderjs/orm — make sure ' +
|
|
96
|
+
'a database provider is registered (and @rudderjs/orm installed) first.');
|
|
97
|
+
}
|
|
98
|
+
return namedTxRunner;
|
|
99
|
+
}
|
|
100
|
+
/** @internal — test-only reset of the registered resolvers + transaction runners. */
|
|
101
|
+
export function __resetAdapterResolver() {
|
|
102
|
+
resolver = null;
|
|
103
|
+
txRunner = null;
|
|
104
|
+
connectionResolver = null;
|
|
105
|
+
namedTxRunner = null;
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=registry-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-bridge.js","sourceRoot":"","sources":["../src/registry-bridge.ts"],"names":[],"mappings":"AAAA,8DAA8D;AAC9D,EAAE;AACF,iFAAiF;AACjF,4EAA4E;AAC5E,4EAA4E;AAC5E,+EAA+E;AAC/E,2EAA2E;AAC3E,0BAA0B;AAC1B,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,+EAA+E;AA4B/E,IA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EAAE,CAAC;QACnB,MAAM,IAAI,KAAK,CACb,0DAA0D;YACxD,2EAA2E;YAC3E,wEAAwE,CAC3E,CAAA;IACH,CAAC;IACD,OAAO,aAAa,CAAA;AACtB,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,sBAAsB;IACpC,QAAQ,GAAG,IAAI,CAAA;IACf,QAAQ,GAAG,IAAI,CAAA;IACf,kBAAkB,GAAG,IAAI,CAAA;IACzB,aAAa,GAAG,IAAI,CAAA;AACtB,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@rudderjs/database",
|
|
3
|
+
"version": "1.1.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/rudderjs/rudder",
|
|
8
|
+
"directory": "packages/database"
|
|
9
|
+
},
|
|
10
|
+
"type": "module",
|
|
11
|
+
"engines": {
|
|
12
|
+
"node": ">=22.12.0"
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"dist",
|
|
16
|
+
"boost"
|
|
17
|
+
],
|
|
18
|
+
"main": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
".": {
|
|
22
|
+
"import": "./dist/index.js",
|
|
23
|
+
"types": "./dist/index.d.ts"
|
|
24
|
+
}
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@rudderjs/contracts": "^1.10.0"
|
|
28
|
+
},
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"@types/node": "^20.0.0",
|
|
31
|
+
"typescript": "^5.4.0",
|
|
32
|
+
"tsx": "^4.0.0"
|
|
33
|
+
},
|
|
34
|
+
"author": "Suleiman Shahbari",
|
|
35
|
+
"scripts": {
|
|
36
|
+
"build": "tsc -p tsconfig.build.json",
|
|
37
|
+
"dev": "tsc -p tsconfig.build.json --watch",
|
|
38
|
+
"typecheck": "tsc --noEmit",
|
|
39
|
+
"lint": "eslint src",
|
|
40
|
+
"clean": "rm -rf dist",
|
|
41
|
+
"test": "tsc -p tsconfig.test.json && node --test \"dist-test/**/*.test.js\""
|
|
42
|
+
}
|
|
43
|
+
}
|