@groundbrick/db-core 0.3.0 → 0.4.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/README.md +170 -132
- package/dist/adapters/BaseSqlAdapter.d.ts.map +1 -1
- package/dist/adapters/BaseSqlAdapter.js +2 -3
- package/dist/adapters/BaseSqlAdapter.js.map +1 -1
- package/dist/adapters/DatabaseAdapter.d.ts +14 -9
- package/dist/adapters/DatabaseAdapter.d.ts.map +1 -1
- package/dist/adapters/DatabaseAdapter.js +39 -37
- package/dist/adapters/DatabaseAdapter.js.map +1 -1
- package/dist/base/BaseTransaction.d.ts +8 -11
- package/dist/base/BaseTransaction.d.ts.map +1 -1
- package/dist/base/BaseTransaction.js +8 -18
- package/dist/base/BaseTransaction.js.map +1 -1
- package/dist/custom-types/MigrationRecord.d.ts.map +1 -1
- package/dist/custom-types/QueryParams.d.ts +1 -1
- package/dist/custom-types/Transaction.d.ts.map +1 -1
- package/dist/error-handling/QueryError.d.ts.map +1 -1
- package/dist/error-handling/QueryError.js +2 -4
- package/dist/error-handling/QueryError.js.map +1 -1
- package/dist/index.d.ts +2 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/interfaces/DatabaseTransaction.d.ts +0 -1
- package/dist/interfaces/DatabaseTransaction.d.ts.map +1 -1
- package/dist/interfaces/QueryResult.d.ts +0 -2
- package/dist/interfaces/QueryResult.d.ts.map +1 -1
- package/dist/logging/transactionFailure.d.ts +3 -8
- package/dist/logging/transactionFailure.d.ts.map +1 -1
- package/dist/logging/transactionFailure.js +3 -8
- package/dist/logging/transactionFailure.js.map +1 -1
- package/dist/sql/quoteIdentifier.d.ts +4 -6
- package/dist/sql/quoteIdentifier.d.ts.map +1 -1
- package/dist/sql/quoteIdentifier.js +4 -6
- package/dist/sql/quoteIdentifier.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -1,214 +1,252 @@
|
|
|
1
|
-
|
|
2
1
|
# @groundbrick/db-core
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
This package provides the backbone for integrating with relational databases (PostgreSQL or MySQL), offering a unified layer for connection handling, querying, transactions, and migrations.
|
|
7
|
-
|
|
8
|
-
---
|
|
9
|
-
|
|
10
|
-
## 🔧 Key Features
|
|
11
|
-
|
|
12
|
-
- Unified interface for database clients
|
|
13
|
-
- Adapter support for PostgreSQL and MySQL (via external factories)
|
|
14
|
-
- Full support for transactions
|
|
15
|
-
- Strongly-typed migration system
|
|
16
|
-
- Configuration validation and health checks
|
|
17
|
-
- Granular error handling by operation type
|
|
3
|
+
Core database interfaces, base classes, error classes and SQL helpers for PostgreSQL and MySQL clients.
|
|
18
4
|
|
|
19
5
|
---
|
|
20
6
|
|
|
21
|
-
##
|
|
7
|
+
## Installation
|
|
22
8
|
|
|
23
9
|
```bash
|
|
24
10
|
npm install @groundbrick/db-core
|
|
25
11
|
```
|
|
26
12
|
|
|
27
|
-
|
|
13
|
+
Client implementations are in `@groundbrick/db-postgres` and `@groundbrick/db-mysql`.
|
|
28
14
|
|
|
29
15
|
---
|
|
30
16
|
|
|
31
|
-
##
|
|
17
|
+
## Quick Start
|
|
32
18
|
|
|
33
19
|
```ts
|
|
34
|
-
import {
|
|
35
|
-
|
|
36
|
-
const adapter = new DatabaseAdapter({
|
|
37
|
-
type: 'postgresql',
|
|
38
|
-
host: 'localhost',
|
|
39
|
-
user: 'admin',
|
|
40
|
-
password: 'secret',
|
|
41
|
-
database: 'mydb',
|
|
42
|
-
port: 5432
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
await adapter.initialize();
|
|
20
|
+
import type { DatabaseClient } from '@groundbrick/db-core';
|
|
46
21
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
22
|
+
async function activeUsers(db: DatabaseClient) {
|
|
23
|
+
const result = await db.query<{ id: number; email: string }>(
|
|
24
|
+
'SELECT id, email FROM users WHERE active = $1',
|
|
25
|
+
[true]
|
|
26
|
+
);
|
|
27
|
+
return result.rows;
|
|
28
|
+
}
|
|
50
29
|
```
|
|
51
30
|
|
|
52
|
-
|
|
31
|
+
`query()` sends the SQL as written: use `$1` placeholders with PostgreSQL and `?` with MySQL.
|
|
53
32
|
|
|
54
|
-
|
|
33
|
+
### Transactions
|
|
55
34
|
|
|
56
35
|
```ts
|
|
57
|
-
await
|
|
58
|
-
await trx.query('INSERT INTO logs (event, ts) VALUES ($1, now())', ['create_user']);
|
|
59
|
-
|
|
36
|
+
await db.transaction(async (trx) => {
|
|
60
37
|
const result = await trx.query<{ id: number }>(
|
|
61
38
|
'INSERT INTO users (email, active) VALUES ($1, $2) RETURNING id',
|
|
62
39
|
['user@example.com', true]
|
|
63
40
|
);
|
|
64
41
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
await trx.query('INSERT INTO profiles (user_id) VALUES ($1)', [userId]);
|
|
42
|
+
await trx.query('INSERT INTO profiles (user_id) VALUES ($1)', [result.rows[0].id]);
|
|
68
43
|
});
|
|
69
44
|
```
|
|
70
45
|
|
|
71
|
-
- The transaction
|
|
72
|
-
-
|
|
73
|
-
- Nested transactions are not natively supported
|
|
46
|
+
- The transaction **commits** when the callback resolves.
|
|
47
|
+
- The transaction **rolls back** when the callback throws.
|
|
74
48
|
|
|
75
49
|
---
|
|
76
50
|
|
|
77
|
-
##
|
|
51
|
+
## API
|
|
78
52
|
|
|
79
|
-
|
|
80
|
-
const status = await adapter.healthCheck();
|
|
53
|
+
### Interfaces and types
|
|
81
54
|
|
|
82
|
-
|
|
83
|
-
|
|
55
|
+
```ts
|
|
56
|
+
interface DatabaseClient {
|
|
57
|
+
initialize(): Promise<void>;
|
|
58
|
+
close(): Promise<void>;
|
|
59
|
+
query<T>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
60
|
+
transaction<T>(callback: (tx: DatabaseTransaction) => Promise<T>): Promise<T>;
|
|
61
|
+
getDatabaseType(): 'postgresql' | 'mysql';
|
|
62
|
+
supportsReturning(): boolean;
|
|
63
|
+
healthCheck(): Promise<HealthCheckResult>;
|
|
64
|
+
getConnectionInfo?(): { total: number; idle: number; waiting: number };
|
|
84
65
|
}
|
|
85
|
-
```
|
|
86
66
|
|
|
87
|
-
|
|
67
|
+
interface DatabaseTransaction {
|
|
68
|
+
query<T = any>(text: string, params?: any[]): Promise<QueryResult<T>>;
|
|
69
|
+
commit(): Promise<void>;
|
|
70
|
+
rollback(): Promise<void>;
|
|
71
|
+
isCompleted(): boolean;
|
|
72
|
+
getDatabaseType(): 'postgresql' | 'mysql';
|
|
73
|
+
supportsReturning(): boolean;
|
|
74
|
+
adaptSql(sql: string): string;
|
|
75
|
+
createInsertSql(tableName: string, columns: string[]): string;
|
|
76
|
+
createUpdateSql(tableName: string, columns: string[]): string;
|
|
77
|
+
}
|
|
88
78
|
|
|
89
|
-
|
|
79
|
+
interface QueryResult<T = any> {
|
|
80
|
+
rows: T[];
|
|
81
|
+
rowCount: number | null;
|
|
82
|
+
insertId?: number; // id generated by an INSERT on engines without RETURNING (MySQL)
|
|
83
|
+
fields?: Array<{
|
|
84
|
+
name: string;
|
|
85
|
+
dataTypeID?: number;
|
|
86
|
+
dataTypeSize?: number;
|
|
87
|
+
dataTypeModifier?: number;
|
|
88
|
+
}>;
|
|
89
|
+
}
|
|
90
90
|
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
interface HealthCheckResult {
|
|
92
|
+
status: 'healthy' | 'unhealthy' | 'degraded';
|
|
93
|
+
timestamp: Date;
|
|
94
|
+
responseTime?: number;
|
|
95
|
+
message?: string;
|
|
96
|
+
activeConnections?: number;
|
|
97
|
+
totalConnections?: number;
|
|
98
|
+
error?: string;
|
|
99
|
+
details?: Record<string, any>;
|
|
95
100
|
}
|
|
96
101
|
```
|
|
97
102
|
|
|
98
|
-
|
|
103
|
+
| Type | Description |
|
|
104
|
+
|------|-------------|
|
|
105
|
+
| `DatabaseConfig` | `host`, `port`, `database`, `user`, `password`, plus optional `ssl`, pool options and any additional key |
|
|
106
|
+
| `DatabaseFactory` | `getInstance(config, logger?)` and optional `closeInstance()` |
|
|
107
|
+
| `ConfigValidator` | `validate(config)`, `getRequiredFields()`, `getOptionalFields()` |
|
|
108
|
+
| `SqlAdapter` | Contract of the database-specific SQL builders |
|
|
109
|
+
| `MigrationManager`, `Migration`, `MigrationStatus` | Migration contracts (see [Migrations](#migrations)) |
|
|
110
|
+
| `Transaction` | Alias of `DatabaseTransaction` |
|
|
111
|
+
| `MigrationRecord` | Alias of `MigrationStatus` |
|
|
112
|
+
| `TransactionCallback<T>` | `(trx: DatabaseTransaction) => Promise<T>` |
|
|
113
|
+
| `QueryParams` | `any[]` |
|
|
114
|
+
| `DatabaseType`, `SupportedDatabases` | `'postgresql' \| 'mysql'` |
|
|
115
|
+
| `AdapterConfig` | `DatabaseConfig` plus `type: DatabaseType` |
|
|
116
|
+
|
|
117
|
+
### `BaseTransaction`
|
|
99
118
|
|
|
100
|
-
|
|
119
|
+
Abstract class implementing `DatabaseTransaction`. Subclasses implement `query()`, `doCommit()`, `doRollback()` and `doCleanup(error?)`.
|
|
101
120
|
|
|
102
121
|
```ts
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
}
|
|
106
|
-
```
|
|
122
|
+
import { BaseTransaction, type QueryResult } from '@groundbrick/db-core';
|
|
123
|
+
import type { Logger } from '@groundbrick/logger';
|
|
107
124
|
|
|
108
|
-
|
|
125
|
+
class MyTransaction extends BaseTransaction {
|
|
126
|
+
constructor(private readonly connection: MyConnection, logger: Logger) {
|
|
127
|
+
super(logger, 'postgresql');
|
|
128
|
+
}
|
|
109
129
|
|
|
110
|
-
|
|
130
|
+
async query<T = any>(text: string, params: any[] = []): Promise<QueryResult<T>> {
|
|
131
|
+
return this.connection.query(text, params);
|
|
132
|
+
}
|
|
111
133
|
|
|
112
|
-
|
|
134
|
+
protected async doCommit() { await this.connection.query('COMMIT'); }
|
|
135
|
+
protected async doRollback() { await this.connection.query('ROLLBACK'); }
|
|
136
|
+
protected async doCleanup(error?: unknown) { this.connection.release(error); }
|
|
137
|
+
}
|
|
138
|
+
```
|
|
113
139
|
|
|
114
|
-
|
|
140
|
+
- `commit()` throws `TransactionError` when the transaction is already completed or `doCommit()` fails.
|
|
141
|
+
- `rollback()` does nothing when the transaction is already completed, and throws `TransactionError` when `doRollback()` fails.
|
|
142
|
+
- Both mark the transaction completed and run `doCleanup()` once, on success and on failure. `doCleanup()` receives the error thrown by `doCommit()`/`doRollback()`, if any; its own errors are logged and not thrown.
|
|
143
|
+
- `adaptSql()` converts every `?` in the SQL to `$1`, `$2`... on PostgreSQL and returns the SQL unchanged on MySQL.
|
|
115
144
|
|
|
116
|
-
|
|
117
|
-
- `.query(sql, params)`
|
|
118
|
-
- `.transaction(cb)`
|
|
119
|
-
- `.healthCheck()`
|
|
120
|
-
- `.getClient()` (direct access to `DatabaseClient`)
|
|
145
|
+
### `BaseSqlAdapter`
|
|
121
146
|
|
|
122
|
-
|
|
147
|
+
Abstract class implementing `SqlAdapter`. Subclasses implement `adaptSql()`, `getDatabaseType()`, `supportsReturning()` and the protected `createPlaceholder(index)`.
|
|
123
148
|
|
|
124
|
-
|
|
149
|
+
| Method | Result |
|
|
150
|
+
|--------|--------|
|
|
151
|
+
| `createInsertSql(tableName, columns)` | `INSERT` with placeholders, plus `RETURNING *` when supported |
|
|
152
|
+
| `createUpdateSql(tableName, columns)` | `UPDATE ... WHERE id = <placeholder>`, plus `RETURNING *` when supported |
|
|
153
|
+
| `createDeleteSql(tableName)` | `DELETE ... WHERE id = <placeholder>` |
|
|
154
|
+
| `getNowFunction()` | `NOW()` |
|
|
155
|
+
| `getLimitClause(limit, offset = 0)` | `LIMIT n` or `LIMIT n OFFSET m`; throws for values that are not non-negative integers |
|
|
125
156
|
|
|
126
|
-
|
|
157
|
+
Table and column names are quoted.
|
|
127
158
|
|
|
128
|
-
|
|
129
|
-
interface DatabaseClient {
|
|
130
|
-
initialize(): Promise<void>;
|
|
131
|
-
close(): Promise<void>;
|
|
132
|
-
query<T>(sql: string, params?: any[]): Promise<QueryResult<T>>;
|
|
133
|
-
transaction<T>(cb: (trx: DatabaseTransaction) => Promise<T>): Promise<T>;
|
|
134
|
-
healthCheck(): Promise<HealthCheckResult>;
|
|
135
|
-
isReady(): boolean;
|
|
136
|
-
}
|
|
137
|
-
```
|
|
159
|
+
### `DatabaseAdapter`
|
|
138
160
|
|
|
139
|
-
|
|
161
|
+
Delegates to the client of `config.type`. The client comes from the factory given as third constructor argument (`new DatabaseAdapter(config, logger, PostgresFactory)`). Without it, `initialize()` imports `@groundbrick/db-postgres` or `@groundbrick/db-mysql`, which must be resolvable from `db-core`, and rejects with `Failed to load PostgreSQL driver: ...` or `Failed to load MySQL driver: ...` when it cannot. Before `initialize()`, `getClient()`, `query()` and `transaction()` fail with `Database adapter not initialized`. An unsupported type throws in the constructor.
|
|
140
162
|
|
|
141
|
-
|
|
163
|
+
| Method | Description |
|
|
164
|
+
|--------|-------------|
|
|
165
|
+
| `initialize()` | Loads the driver and initializes the client |
|
|
166
|
+
| `close()` | Closes the client, if loaded |
|
|
167
|
+
| `query(sql, params?)` | Returns `{ rows, rowCount }` |
|
|
168
|
+
| `transaction(callback)` | Passes the callback an object with `query()`; its `transaction()` rejects with `Nested transactions not supported` |
|
|
169
|
+
| `healthCheck()` | Runs `SELECT 1`; returns `{ status: 'ok' \| 'error', timestamp, reason? }` |
|
|
170
|
+
| `getClient()` | The underlying `DatabaseClient` |
|
|
171
|
+
| `getDatabaseType()` | The configured type |
|
|
172
|
+
| `isReady()` | `true` once the driver is loaded |
|
|
142
173
|
|
|
143
|
-
|
|
174
|
+
### Functions and constants
|
|
144
175
|
|
|
145
|
-
|
|
176
|
+
| Export | Description |
|
|
177
|
+
|--------|-------------|
|
|
178
|
+
| `quoteIdentifier(name, dbType)` | Quotes a table or column name. Dotted names are quoted part by part, `*` is left as is and embedded quote characters are doubled |
|
|
179
|
+
| `transactionFailureLogLevel(error)` | `'warn'` for a `DatabaseError`, `'debug'` for an `Error` named `BusinessError`, `'error'` for anything else |
|
|
180
|
+
| `validateDatabaseConfig(config)` | Type guard: `host`, `database`, `user` and `password` are strings and `port` is a number |
|
|
181
|
+
| `createConnectionKey(config)` | `host:port:database:user` |
|
|
182
|
+
| `sanitizeConfigForLogging(config)` | Copy of the config without `password` |
|
|
183
|
+
| `DEFAULT_POOL_CONFIG` | `max: 10`, `min: 2`, `connectionTimeoutMillis: 60000`, `idleTimeoutMillis: 30000`, `acquireTimeout: 60000`, `timeout: 60000` |
|
|
184
|
+
| `MIGRATION_FILE_PATTERN` | `/^(\d{3})_(.+)\.sql$/` |
|
|
146
185
|
|
|
147
|
-
```
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
│ ├── adapters/ # Generic adapter layer
|
|
151
|
-
│ ├── base/ # Reusable base logic (e.g., transactions)
|
|
152
|
-
│ ├── custom-types/ # Utility and internal types
|
|
153
|
-
│ ├── error-handling/ # Operation-specific error classes
|
|
154
|
-
│ ├── interfaces/ # Public contract definitions
|
|
155
|
-
│ └── index.ts # Entry point
|
|
186
|
+
```ts
|
|
187
|
+
quoteIdentifier('public.order', 'postgresql'); // "public"."order"
|
|
188
|
+
quoteIdentifier('order', 'mysql'); // `order`
|
|
156
189
|
```
|
|
157
190
|
|
|
158
191
|
---
|
|
159
192
|
|
|
160
|
-
##
|
|
161
|
-
|
|
162
|
-
The core defines types for managing and recording schema migrations. You can implement your own `MigrationManager`:
|
|
193
|
+
## Migrations
|
|
163
194
|
|
|
164
195
|
```ts
|
|
165
|
-
|
|
196
|
+
interface MigrationManager {
|
|
197
|
+
migrate(): Promise<void>;
|
|
198
|
+
rollback(): Promise<void>;
|
|
199
|
+
rollbackTo(migrationId: string): Promise<void>;
|
|
200
|
+
getStatus(): Promise<MigrationStatus[]>;
|
|
201
|
+
getPending(): Promise<Migration[]>;
|
|
202
|
+
reset(): Promise<void>;
|
|
203
|
+
}
|
|
166
204
|
|
|
167
|
-
|
|
205
|
+
interface Migration {
|
|
206
|
+
id: string;
|
|
207
|
+
description: string;
|
|
208
|
+
up: string;
|
|
209
|
+
down: string;
|
|
210
|
+
checksum?: string;
|
|
211
|
+
}
|
|
168
212
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
console.error(`Failed to apply migration ${migration.version}:`, err);
|
|
175
|
-
break;
|
|
176
|
-
}
|
|
213
|
+
interface MigrationStatus {
|
|
214
|
+
id: string;
|
|
215
|
+
description: string;
|
|
216
|
+
applied_at: Date;
|
|
217
|
+
checksum: string;
|
|
177
218
|
}
|
|
178
219
|
```
|
|
179
220
|
|
|
180
|
-
Each migration should follow the `Migration` type contract with `up`, `down`, and `version` fields.
|
|
181
|
-
|
|
182
221
|
---
|
|
183
222
|
|
|
184
|
-
##
|
|
185
|
-
|
|
186
|
-
All operations raise specific error classes for easier diagnosis:
|
|
223
|
+
## Error Handling
|
|
187
224
|
|
|
188
|
-
|
|
189
|
-
- `QueryError`
|
|
190
|
-
- `MigrationError`
|
|
191
|
-
- `TransactionError`
|
|
192
|
-
- `DatabaseError` (generic base class)
|
|
193
|
-
|
|
194
|
-
---
|
|
225
|
+
All error classes extend `DatabaseError`, which has the optional fields `code`, `severity`, `constraint`, `detail` and `cause`.
|
|
195
226
|
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
227
|
+
| Class | Type guard | Fields |
|
|
228
|
+
|-------|------------|--------|
|
|
229
|
+
| `DatabaseError` | `isDatabaseError` | As passed in `options` |
|
|
230
|
+
| `ConnectionError` | `isConnectionError` | `cause` |
|
|
231
|
+
| `QueryError` | `isQueryError` | `code: 'QUERY_ERROR'`, `severity: 'ERROR'`, `constraint` when the driver reports one, `detail` with the query and the parameter count (never the values), `cause` |
|
|
232
|
+
| `TransactionError` | `isTransactionError` | `cause` |
|
|
233
|
+
| `MigrationError` | `isMigrationError` | `code: 'MIGRATION_ERROR'`, `severity: 'ERROR'`, `constraint: 'migration_<id>'` when an id is given, `cause` |
|
|
199
234
|
|
|
200
235
|
```ts
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
236
|
+
import { isQueryError } from '@groundbrick/db-core';
|
|
237
|
+
|
|
238
|
+
try {
|
|
239
|
+
await db.query('INSERT INTO users (email) VALUES ($1)', ['user@example.com']);
|
|
240
|
+
} catch (error) {
|
|
241
|
+
if (isQueryError(error) && error.constraint === 'users_email_key') {
|
|
242
|
+
// duplicate email
|
|
204
243
|
}
|
|
244
|
+
throw error;
|
|
205
245
|
}
|
|
206
246
|
```
|
|
207
247
|
|
|
208
|
-
Inside `DatabaseAdapter`, you would dynamically import and use this factory depending on the type.
|
|
209
|
-
|
|
210
248
|
---
|
|
211
249
|
|
|
212
|
-
##
|
|
250
|
+
## License
|
|
213
251
|
|
|
214
|
-
MIT
|
|
252
|
+
MIT
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseSqlAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/BaseSqlAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;
|
|
1
|
+
{"version":3,"file":"BaseSqlAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/BaseSqlAdapter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,6BAA6B,CAAC;AAgBzD,8BAAsB,cAAe,YAAW,UAAU;IACtD,QAAQ,CAAC,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM;IACtC,QAAQ,CAAC,eAAe,IAAI,YAAY,GAAG,OAAO;IAClD,QAAQ,CAAC,iBAAiB,IAAI,OAAO;IAErC,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM;IAY7D,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM;IAe7D,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,MAAM;IAI1C,cAAc,IAAI,MAAM;IAIxB,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,GAAE,MAAU,GAAG,MAAM;IASzD,SAAS,CAAC,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM;IAI3C,SAAS,CAAC,QAAQ,CAAC,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;IAE3D,SAAS,CAAC,kBAAkB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM;CAGtD"}
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { quoteIdentifier } from "../sql/quoteIdentifier.js";
|
|
2
2
|
/**
|
|
3
|
-
* LIMIT/OFFSET
|
|
4
|
-
*
|
|
5
|
-
* would otherwise become SQL.
|
|
3
|
+
* Validates a LIMIT/OFFSET value: a plain non-negative integer.
|
|
4
|
+
* @throws Error for any other value.
|
|
6
5
|
*/
|
|
7
6
|
function sqlCount(value, name) {
|
|
8
7
|
const count = typeof value === 'number' ? value : Number.NaN;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseSqlAdapter.js","sourceRoot":"","sources":["../../src/adapters/BaseSqlAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D
|
|
1
|
+
{"version":3,"file":"BaseSqlAdapter.js","sourceRoot":"","sources":["../../src/adapters/BaseSqlAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAE5D;;;GAGG;AACH,SAAS,QAAQ,CAAC,KAAc,EAAE,IAAY;IAC1C,MAAM,KAAK,GAAG,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC;IAC7D,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,CAAC,EAAE,CAAC;QAC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AED,OAAO,GAAG,CAAC;IACf,CAAC;IAED,eAAe,CAAC,SAAiB;QAC7B,OAAO,IAAI,CAAC,QAAQ,CAAC,eAAe,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,eAAe,CAAC,CAAC;IAC9E,CAAC;IAED,cAAc;QACV,OAAO,OAAO,CAAC;IACnB,CAAC;IAED,cAAc,CAAC,KAAa,EAAE,SAAiB,CAAC;QAC5C,MAAM,SAAS,GAAG,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC3C,MAAM,UAAU,GAAG,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;QAC9C,IAAI,UAAU,GAAG,CAAC,EAAE,CAAC;YACjB,OAAO,SAAS,SAAS,WAAW,UAAU,EAAE,CAAC;QACrD,CAAC;QACD,OAAO,SAAS,SAAS,EAAE,CAAC;IAChC,CAAC;IAES,KAAK,CAAC,UAAkB;QAC9B,OAAO,eAAe,CAAC,UAAU,EAAE,IAAI,CAAC,eAAe,EAAE,CAAC,CAAC;IAC/D,CAAC;IAIS,kBAAkB,CAAC,KAAa;QACtC,OAAO,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,IAAI,CAAC,iBAAiB,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7F,CAAC;CACJ"}
|
|
@@ -1,26 +1,32 @@
|
|
|
1
1
|
import { Logger } from '@groundbrick/logger';
|
|
2
2
|
import { DatabaseClient, DatabaseConfig } from '../interfaces/index.js';
|
|
3
|
+
import type { DatabaseFactory } from '../interfaces/DatabaseFactory.js';
|
|
3
4
|
export type DatabaseType = 'postgresql' | 'mysql';
|
|
4
5
|
export interface AdapterConfig extends DatabaseConfig {
|
|
5
6
|
type: DatabaseType;
|
|
6
7
|
}
|
|
7
8
|
/**
|
|
8
|
-
* Database Adapter that provides a unified interface for both PostgreSQL and MySQL
|
|
9
|
-
*
|
|
9
|
+
* Database Adapter that provides a unified interface for both PostgreSQL and MySQL.
|
|
10
|
+
* The client is created by initialize().
|
|
10
11
|
*/
|
|
11
12
|
export declare class DatabaseAdapter {
|
|
13
|
+
private config;
|
|
14
|
+
private driverFactory?;
|
|
12
15
|
private client;
|
|
13
16
|
private logger;
|
|
14
17
|
private dbType;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
+
/**
|
|
19
|
+
* @param driverFactory - Factory that creates the client. By default, the one
|
|
20
|
+
* exported by the driver package of `config.type`, loaded by initialize().
|
|
21
|
+
*/
|
|
22
|
+
constructor(config: AdapterConfig, logger?: Logger, driverFactory?: Pick<DatabaseFactory, "getInstance"> | undefined);
|
|
23
|
+
private loadClient;
|
|
18
24
|
/**
|
|
19
25
|
* Get the database type
|
|
20
26
|
*/
|
|
21
27
|
getDatabaseType(): DatabaseType;
|
|
22
28
|
/**
|
|
23
|
-
*
|
|
29
|
+
* Load the driver and initialize the database connection
|
|
24
30
|
*/
|
|
25
31
|
initialize(): Promise<void>;
|
|
26
32
|
/**
|
|
@@ -28,8 +34,7 @@ export declare class DatabaseAdapter {
|
|
|
28
34
|
*/
|
|
29
35
|
close(): Promise<void>;
|
|
30
36
|
/**
|
|
31
|
-
* Get the underlying database client
|
|
32
|
-
* This allows access to all database-specific methods
|
|
37
|
+
* Get the underlying database client. Throws before initialize().
|
|
33
38
|
*/
|
|
34
39
|
getClient(): DatabaseClient;
|
|
35
40
|
/**
|
|
@@ -52,7 +57,7 @@ export declare class DatabaseAdapter {
|
|
|
52
57
|
reason?: string;
|
|
53
58
|
}>;
|
|
54
59
|
/**
|
|
55
|
-
* Check if
|
|
60
|
+
* Check if the driver is loaded
|
|
56
61
|
*/
|
|
57
62
|
isReady(): boolean;
|
|
58
63
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/DatabaseAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAExE,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,OAAO,CAAC;AAElD,MAAM,WAAW,aAAc,SAAQ,cAAc;IACjD,IAAI,EAAE,YAAY,CAAC;CACtB;
|
|
1
|
+
{"version":3,"file":"DatabaseAdapter.d.ts","sourceRoot":"","sources":["../../src/adapters/DatabaseAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAgB,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAC3D,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AACxE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAExE,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,OAAO,CAAC;AAElD,MAAM,WAAW,aAAc,SAAQ,cAAc;IACjD,IAAI,EAAE,YAAY,CAAC;CACtB;AAQD;;;GAGG;AACH,qBAAa,eAAe;IAUpB,OAAO,CAAC,MAAM;IAEd,OAAO,CAAC,aAAa,CAAC;IAX1B,OAAO,CAAC,MAAM,CAA+B;IAC7C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAe;IAE7B;;;OAGG;gBAES,MAAM,EAAE,aAAa,EAC7B,MAAM,CAAC,EAAE,MAAM,EACP,aAAa,CAAC,EAAE,IAAI,CAAC,eAAe,EAAE,aAAa,CAAC,YAAA;YAYlD,UAAU;IAcxB;;OAEG;IACH,eAAe,IAAI,YAAY;IAI/B;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAMjC;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAK5B;;OAEG;IACH,SAAS,IAAI,cAAc;IAO3B;;OAEG;IACG,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC;IAQ3F;;OAEG;IACG,WAAW,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,MAAM,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAclF;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC;QAAE,MAAM,EAAE,IAAI,GAAG,OAAO,CAAC;QAAC,SAAS,EAAE,IAAI,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAa1F;;OAEG;IACH,OAAO,IAAI,OAAO;CAGrB"}
|
|
@@ -1,46 +1,44 @@
|
|
|
1
1
|
import { createLogger } from '@groundbrick/logger';
|
|
2
|
+
/** Driver package and exported factory of each database type. */
|
|
3
|
+
const DRIVERS = {
|
|
4
|
+
postgresql: { label: 'PostgreSQL', packageName: '@groundbrick/db-postgres', factory: 'PostgresFactory' },
|
|
5
|
+
mysql: { label: 'MySQL', packageName: '@groundbrick/db-mysql', factory: 'MysqlFactory' }
|
|
6
|
+
};
|
|
2
7
|
/**
|
|
3
|
-
* Database Adapter that provides a unified interface for both PostgreSQL and MySQL
|
|
4
|
-
*
|
|
8
|
+
* Database Adapter that provides a unified interface for both PostgreSQL and MySQL.
|
|
9
|
+
* The client is created by initialize().
|
|
5
10
|
*/
|
|
6
11
|
export class DatabaseAdapter {
|
|
7
|
-
|
|
12
|
+
config;
|
|
13
|
+
driverFactory;
|
|
14
|
+
client = null;
|
|
8
15
|
logger;
|
|
9
16
|
dbType;
|
|
10
|
-
|
|
17
|
+
/**
|
|
18
|
+
* @param driverFactory - Factory that creates the client. By default, the one
|
|
19
|
+
* exported by the driver package of `config.type`, loaded by initialize().
|
|
20
|
+
*/
|
|
21
|
+
constructor(config, logger, driverFactory) {
|
|
22
|
+
this.config = config;
|
|
23
|
+
this.driverFactory = driverFactory;
|
|
11
24
|
this.logger = logger || createLogger({ context: 'database-adapter' });
|
|
12
25
|
this.dbType = config.type;
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
case 'postgresql':
|
|
16
|
-
this.client = this.createPostgresClient(config);
|
|
17
|
-
break;
|
|
18
|
-
case 'mysql':
|
|
19
|
-
this.client = this.createMySQLClient(config);
|
|
20
|
-
break;
|
|
21
|
-
default:
|
|
22
|
-
throw new Error(`Unsupported database type: ${config.type}`);
|
|
26
|
+
if (!DRIVERS[config.type]) {
|
|
27
|
+
throw new Error(`Unsupported database type: ${config.type}`);
|
|
23
28
|
}
|
|
24
29
|
this.logger.info('Database adapter created', { type: config.type });
|
|
25
30
|
}
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const { PostgresFactory } = require('@groundbrick/db-postgres');
|
|
30
|
-
return PostgresFactory.getInstance(config, this.logger);
|
|
31
|
+
async loadClient() {
|
|
32
|
+
if (this.driverFactory) {
|
|
33
|
+
return this.driverFactory.getInstance(this.config, this.logger);
|
|
31
34
|
}
|
|
32
|
-
|
|
33
|
-
throw new Error(`Failed to load PostgreSQL driver: ${error instanceof Error ? error.message : 'Unknown error'}. Make sure @groundbrick/db-postgres is installed.`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
createMySQLClient(config) {
|
|
35
|
+
const { label, packageName, factory } = DRIVERS[this.dbType];
|
|
37
36
|
try {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
return MySQLFactory.getInstance(config, this.logger);
|
|
37
|
+
const driver = await import(packageName);
|
|
38
|
+
return driver[factory].getInstance(this.config, this.logger);
|
|
41
39
|
}
|
|
42
40
|
catch (error) {
|
|
43
|
-
throw new Error(`Failed to load
|
|
41
|
+
throw new Error(`Failed to load ${label} driver: ${error instanceof Error ? error.message : 'Unknown error'}. Make sure ${packageName} is installed.`);
|
|
44
42
|
}
|
|
45
43
|
}
|
|
46
44
|
/**
|
|
@@ -50,9 +48,10 @@ export class DatabaseAdapter {
|
|
|
50
48
|
return this.dbType;
|
|
51
49
|
}
|
|
52
50
|
/**
|
|
53
|
-
*
|
|
51
|
+
* Load the driver and initialize the database connection
|
|
54
52
|
*/
|
|
55
53
|
async initialize() {
|
|
54
|
+
this.client ??= await this.loadClient();
|
|
56
55
|
await this.client.initialize();
|
|
57
56
|
this.logger.info('Database adapter initialized');
|
|
58
57
|
}
|
|
@@ -60,21 +59,23 @@ export class DatabaseAdapter {
|
|
|
60
59
|
* Close the database connection
|
|
61
60
|
*/
|
|
62
61
|
async close() {
|
|
63
|
-
await this.client
|
|
62
|
+
await this.client?.close();
|
|
64
63
|
this.logger.info('Database adapter closed');
|
|
65
64
|
}
|
|
66
65
|
/**
|
|
67
|
-
* Get the underlying database client
|
|
68
|
-
* This allows access to all database-specific methods
|
|
66
|
+
* Get the underlying database client. Throws before initialize().
|
|
69
67
|
*/
|
|
70
68
|
getClient() {
|
|
69
|
+
if (!this.client) {
|
|
70
|
+
throw new Error('Database adapter not initialized');
|
|
71
|
+
}
|
|
71
72
|
return this.client;
|
|
72
73
|
}
|
|
73
74
|
/**
|
|
74
75
|
* Execute a database-agnostic query
|
|
75
76
|
*/
|
|
76
77
|
async query(sql, params) {
|
|
77
|
-
const result = await this.
|
|
78
|
+
const result = await this.getClient().query(sql, params);
|
|
78
79
|
return {
|
|
79
80
|
rows: result.rows,
|
|
80
81
|
rowCount: result.rowCount ?? 0
|
|
@@ -84,10 +85,11 @@ export class DatabaseAdapter {
|
|
|
84
85
|
* Execute a transaction with unified interface
|
|
85
86
|
*/
|
|
86
87
|
async transaction(callback) {
|
|
87
|
-
|
|
88
|
+
const client = this.getClient();
|
|
89
|
+
return await client.transaction(async (trx) => {
|
|
88
90
|
// Create a wrapper that looks like a DatabaseClient but uses the transaction
|
|
89
91
|
const transactionClient = {
|
|
90
|
-
...
|
|
92
|
+
...client,
|
|
91
93
|
query: trx.query.bind(trx),
|
|
92
94
|
transaction: () => Promise.reject(new Error('Nested transactions not supported'))
|
|
93
95
|
};
|
|
@@ -99,7 +101,7 @@ export class DatabaseAdapter {
|
|
|
99
101
|
*/
|
|
100
102
|
async healthCheck() {
|
|
101
103
|
try {
|
|
102
|
-
await this.
|
|
104
|
+
await this.getClient().query('SELECT 1');
|
|
103
105
|
return { status: 'ok', timestamp: new Date() };
|
|
104
106
|
}
|
|
105
107
|
catch (error) {
|
|
@@ -111,7 +113,7 @@ export class DatabaseAdapter {
|
|
|
111
113
|
}
|
|
112
114
|
}
|
|
113
115
|
/**
|
|
114
|
-
* Check if
|
|
116
|
+
* Check if the driver is loaded
|
|
115
117
|
*/
|
|
116
118
|
isReady() {
|
|
117
119
|
return !!this.client;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseAdapter.js","sourceRoot":"","sources":["../../src/adapters/DatabaseAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAU,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"DatabaseAdapter.js","sourceRoot":"","sources":["../../src/adapters/DatabaseAdapter.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAU,MAAM,qBAAqB,CAAC;AAU3D,iEAAiE;AACjE,MAAM,OAAO,GAAkF;IAC3F,UAAU,EAAE,EAAE,KAAK,EAAE,YAAY,EAAE,WAAW,EAAE,0BAA0B,EAAE,OAAO,EAAE,iBAAiB,EAAE;IACxG,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,uBAAuB,EAAE,OAAO,EAAE,cAAc,EAAE;CAC3F,CAAC;AAEF;;;GAGG;AACH,MAAM,OAAO,eAAe;IAUZ;IAEA;IAXJ,MAAM,GAA0B,IAAI,CAAC;IACrC,MAAM,CAAS;IACf,MAAM,CAAe;IAE7B;;;OAGG;IACH,YACY,MAAqB,EAC7B,MAAe,EACP,aAAoD;QAFpD,WAAM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AAC,IAAI,KAAK,CAAC,mCAAmC,CAAC,CAAC;aACpF,CAAC;YAEF,OAAO,MAAM,QAAQ,CAAC,iBAAiB,CAAC,CAAC;QAC7C,CAAC,CAAC,CAAC;IACP,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,WAAW;QACb,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC;YACzC,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC;QACnD,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,OAAO;gBACH,MAAM,EAAE,OAAO;gBACf,SAAS,EAAE,IAAI,IAAI,EAAE;gBACrB,MAAM,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe;aACnE,CAAC;QACN,CAAC;IACL,CAAC;IAED;;OAEG;IACH,OAAO;QACH,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC;IACzB,CAAC;CACJ"}
|
|
@@ -3,7 +3,6 @@ import { QueryResult } from '../interfaces/QueryResult.js';
|
|
|
3
3
|
import { Logger } from '@groundbrick/logger';
|
|
4
4
|
/**
|
|
5
5
|
* Base transaction class that provides common transaction logic with database type awareness
|
|
6
|
-
* This ensures consistent behavior across different database implementations
|
|
7
6
|
*/
|
|
8
7
|
export declare abstract class BaseTransaction implements DatabaseTransaction {
|
|
9
8
|
protected readonly logger: Logger;
|
|
@@ -13,23 +12,23 @@ export declare abstract class BaseTransaction implements DatabaseTransaction {
|
|
|
13
12
|
constructor(logger: Logger, dbType: 'postgresql' | 'mysql');
|
|
14
13
|
abstract query<T = any>(text: string, params?: any[]): Promise<QueryResult<T>>;
|
|
15
14
|
/**
|
|
16
|
-
*
|
|
15
|
+
* Get the database type for this transaction
|
|
17
16
|
*/
|
|
18
17
|
getDatabaseType(): 'postgresql' | 'mysql';
|
|
19
18
|
/**
|
|
20
|
-
*
|
|
19
|
+
* Check if this database supports RETURNING clause
|
|
21
20
|
*/
|
|
22
21
|
supportsReturning(): boolean;
|
|
23
22
|
/**
|
|
24
|
-
*
|
|
23
|
+
* Adapt SQL query for database-specific syntax
|
|
25
24
|
*/
|
|
26
25
|
adaptSql(sql: string): string;
|
|
27
26
|
/**
|
|
28
|
-
*
|
|
27
|
+
* Create database-specific INSERT SQL
|
|
29
28
|
*/
|
|
30
29
|
createInsertSql(tableName: string, columns: string[]): string;
|
|
31
30
|
/**
|
|
32
|
-
*
|
|
31
|
+
* Create database-specific UPDATE SQL
|
|
33
32
|
*/
|
|
34
33
|
createUpdateSql(tableName: string, columns: string[]): string;
|
|
35
34
|
/**
|
|
@@ -57,15 +56,13 @@ export declare abstract class BaseTransaction implements DatabaseTransaction {
|
|
|
57
56
|
/**
|
|
58
57
|
* Database-specific cleanup (connection release, etc.).
|
|
59
58
|
* @param erro - The error thrown by doCommit()/doRollback() itself, if any.
|
|
60
|
-
* Drivers may use it to discard
|
|
61
|
-
*
|
|
62
|
-
* nothing here: that connection is fine.
|
|
59
|
+
* Drivers may use it to discard the connection. A transaction that failed
|
|
60
|
+
* but rolled back cleanly passes nothing here.
|
|
63
61
|
*/
|
|
64
62
|
protected abstract doCleanup(erro?: unknown): Promise<void>;
|
|
65
63
|
/**
|
|
66
64
|
* Ensure cleanup happens in both success and error cases.
|
|
67
|
-
* Idempotent: commit() followed by rollback() releases the connection once
|
|
68
|
-
* and a second release on the same pool client is an error in most drivers.
|
|
65
|
+
* Idempotent: commit() followed by rollback() releases the connection once.
|
|
69
66
|
*/
|
|
70
67
|
protected ensureCleanup(erro?: unknown): Promise<void>;
|
|
71
68
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseTransaction.d.ts","sourceRoot":"","sources":["../../src/base/BaseTransaction.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AA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C,IAAI,CAAC;IA2B/B;;OAEG;IACH,WAAW,IAAI,OAAO;IAItB;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;IAE5C;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAE9C;;;;;OAKG;IACH,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;IAE3D;;;OAGG;cACa,aAAa,CAAC,IAAI,CAAC,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAgB/D"}
|
|
@@ -2,32 +2,30 @@ import { TransactionError } from '../error-handling/TransactionError.js';
|
|
|
2
2
|
import { quoteIdentifier } from '../sql/quoteIdentifier.js';
|
|
3
3
|
/**
|
|
4
4
|
* Base transaction class that provides common transaction logic with database type awareness
|
|
5
|
-
* This ensures consistent behavior across different database implementations
|
|
6
5
|
*/
|
|
7
6
|
export class BaseTransaction {
|
|
8
7
|
logger;
|
|
9
8
|
dbType;
|
|
10
9
|
completed = false;
|
|
11
10
|
cleanedUp = false;
|
|
12
|
-
constructor(logger, dbType
|
|
13
|
-
) {
|
|
11
|
+
constructor(logger, dbType) {
|
|
14
12
|
this.logger = logger;
|
|
15
13
|
this.dbType = dbType;
|
|
16
14
|
}
|
|
17
15
|
/**
|
|
18
|
-
*
|
|
16
|
+
* Get the database type for this transaction
|
|
19
17
|
*/
|
|
20
18
|
getDatabaseType() {
|
|
21
19
|
return this.dbType;
|
|
22
20
|
}
|
|
23
21
|
/**
|
|
24
|
-
*
|
|
22
|
+
* Check if this database supports RETURNING clause
|
|
25
23
|
*/
|
|
26
24
|
supportsReturning() {
|
|
27
25
|
return this.dbType === 'postgresql';
|
|
28
26
|
}
|
|
29
27
|
/**
|
|
30
|
-
*
|
|
28
|
+
* Adapt SQL query for database-specific syntax
|
|
31
29
|
*/
|
|
32
30
|
adaptSql(sql) {
|
|
33
31
|
if (this.dbType === 'postgresql') {
|
|
@@ -39,7 +37,7 @@ export class BaseTransaction {
|
|
|
39
37
|
return sql;
|
|
40
38
|
}
|
|
41
39
|
/**
|
|
42
|
-
*
|
|
40
|
+
* Create database-specific INSERT SQL
|
|
43
41
|
*/
|
|
44
42
|
createInsertSql(tableName, columns) {
|
|
45
43
|
const placeholders = columns.map((_, index) => {
|
|
@@ -53,7 +51,7 @@ export class BaseTransaction {
|
|
|
53
51
|
return sql;
|
|
54
52
|
}
|
|
55
53
|
/**
|
|
56
|
-
*
|
|
54
|
+
* Create database-specific UPDATE SQL
|
|
57
55
|
*/
|
|
58
56
|
createUpdateSql(tableName, columns) {
|
|
59
57
|
const setParts = columns.map((col, index) => {
|
|
@@ -90,11 +88,6 @@ export class BaseTransaction {
|
|
|
90
88
|
throw new TransactionError(`Failed to commit transaction: ${error.message}`, error);
|
|
91
89
|
}
|
|
92
90
|
finally {
|
|
93
|
-
// Cleanup lives here, not inside doCommit(): a COMMIT that throws
|
|
94
|
-
// must still return the connection. The transaction is marked
|
|
95
|
-
// completed either way — a failed COMMIT ends it just as surely as
|
|
96
|
-
// a successful one, and calling rollback() on it afterwards would
|
|
97
|
-
// only reach a connection that is already back in the pool.
|
|
98
91
|
this.completed = true;
|
|
99
92
|
await this.ensureCleanup(falha);
|
|
100
93
|
}
|
|
@@ -123,8 +116,6 @@ export class BaseTransaction {
|
|
|
123
116
|
throw new TransactionError(`Failed to rollback transaction: ${error.message}`, error);
|
|
124
117
|
}
|
|
125
118
|
finally {
|
|
126
|
-
// A ROLLBACK that throws (a dead connection, say) must still release,
|
|
127
|
-
// otherwise the failure leaks the very connection it was cleaning up.
|
|
128
119
|
this.completed = true;
|
|
129
120
|
await this.ensureCleanup(falha);
|
|
130
121
|
}
|
|
@@ -137,8 +128,7 @@ export class BaseTransaction {
|
|
|
137
128
|
}
|
|
138
129
|
/**
|
|
139
130
|
* Ensure cleanup happens in both success and error cases.
|
|
140
|
-
* Idempotent: commit() followed by rollback() releases the connection once
|
|
141
|
-
* and a second release on the same pool client is an error in most drivers.
|
|
131
|
+
* Idempotent: commit() followed by rollback() releases the connection once.
|
|
142
132
|
*/
|
|
143
133
|
async ensureCleanup(erro) {
|
|
144
134
|
if (this.cleanedUp) {
|
|
@@ -149,7 +139,7 @@ export class BaseTransaction {
|
|
|
149
139
|
await this.doCleanup(erro);
|
|
150
140
|
}
|
|
151
141
|
catch (error) {
|
|
152
|
-
//
|
|
142
|
+
// Cleanup errors are logged, not thrown.
|
|
153
143
|
this.logger.error('Failed to cleanup transaction resources', error instanceof Error ? error : new Error(String(error)), {
|
|
154
144
|
error,
|
|
155
145
|
dbType: this.dbType
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BaseTransaction.js","sourceRoot":"","sources":["../../src/base/BaseTransaction.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5D
|
|
1
|
+
{"version":3,"file":"BaseTransaction.js","sourceRoot":"","sources":["../../src/base/BaseTransaction.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,gBAAgB,EAAE,MAAM,uCAAuC,CAAC;AACzE,OAAO,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAG5D;;GAEG;AACH,MAAM,OAAgB,eAAe;IAKV;IACA;IALb,SAAS,GAAG,KAAK,CAAC;IACpB,SAAS,GAAG,KAAK,CAAC;IAE1B,YACuB,MAAc,EACd,MAA8B;QAD9B,WAAM,GAAN,MAAM,CAAQ;QACd,WAAM,GAAN,MAAM,CAAwB;IACjD,CAAC;IAIL;;OAEG;IACH,eAAe;QACX,OAAO,IAAI,CAAC,MAAM,CAAC;IACvB,CAAC;IAED;;OAEG;IACH,iBAAiB;QACb,OAAO,IAAI,CAAC,MAAM,KAAK,YAAY,CAAC;IACxC,CAAC;IAED;;OAE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CACjB,CAAC;QACN,CAAC;gBAAS,CAAC;YACP,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;YACtB,MAAM,IAAI,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QACpC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,WAAW;QACP,OAAO,IAAI,CAAC,SAAS,CAAC;IAC1B,CAAC;IAoBD;;;OAGG;IACO,KAAK,CAAC,aAAa,CAAC,IAAc;QACxC,IAAI,IAAI,CAAC,SAAS,EAAE,CAAC;YACjB,OAAO;QACX,CAAC;QACD,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC;QAEtB,IAAI,CAAC;YACD,MAAM,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAC/B,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACb,yCAAyC;YACzC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,yCAAyC,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE;gBACpH,KAAK;gBACL,MAAM,EAAE,IAAI,CAAC,MAAM;aACtB,CAAC,CAAC;QACP,CAAC;IACL,CAAC;CACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MigrationRecord.d.ts","sourceRoot":"","sources":["../../src/custom-types/MigrationRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;
|
|
1
|
+
{"version":3,"file":"MigrationRecord.d.ts","sourceRoot":"","sources":["../../src/custom-types/MigrationRecord.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,kCAAkC,CAAC;AAGnE;;GAEG;AACH,MAAM,MAAM,eAAe,GAAG,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Transaction.d.ts","sourceRoot":"","sources":["../../src/custom-types/Transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"Transaction.d.ts","sourceRoot":"","sources":["../../src/custom-types/Transaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAE,MAAM,sCAAsC,CAAC;AAG3E;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,mBAAmB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryError.d.ts","sourceRoot":"","sources":["../../src/error-handling/QueryError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,qBAAa,UAAW,SAAQ,aAAa;gBAErC,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,GAAG,EAAE,EACd,aAAa,CAAC,EAAE,KAAK;
|
|
1
|
+
{"version":3,"file":"QueryError.d.ts","sourceRoot":"","sources":["../../src/error-handling/QueryError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,qBAAa,UAAW,SAAQ,aAAa;gBAErC,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,MAAM,EACd,MAAM,CAAC,EAAE,GAAG,EAAE,EACd,aAAa,CAAC,EAAE,KAAK;CAa5B"}
|
|
@@ -8,11 +8,9 @@ export class QueryError extends DatabaseError {
|
|
|
8
8
|
cause: originalError,
|
|
9
9
|
code: 'QUERY_ERROR',
|
|
10
10
|
severity: 'ERROR',
|
|
11
|
-
// Name of the violated constraint, when the driver reports one
|
|
12
|
-
// does), so callers can tell violations apart without unwrapping `cause`.
|
|
11
|
+
// Name of the violated constraint, when the driver reports one.
|
|
13
12
|
constraint: originalError?.constraint,
|
|
14
|
-
//
|
|
15
|
-
// this error ends up in logs and error trackers.
|
|
13
|
+
// Contains the query and the parameter count, never the parameter values.
|
|
16
14
|
detail: `Query error occurred${query ? ` for query: ${query}` : ''}` + (params ? ` with ${params.length} params` : '')
|
|
17
15
|
});
|
|
18
16
|
this.name = 'QueryError';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryError.js","sourceRoot":"","sources":["../../src/error-handling/QueryError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,aAAa;IACzC,YACI,OAAe,EACf,KAAc,EACd,MAAc,EACd,aAAqB;QAErB,KAAK,CAAC,OAAO,EAAE;YACX,KAAK,EAAE,aAAa;YACpB,IAAI,EAAE,aAAa;YACnB,QAAQ,EAAE,OAAO;YACjB,
|
|
1
|
+
{"version":3,"file":"QueryError.js","sourceRoot":"","sources":["../../src/error-handling/QueryError.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;GAEG;AACH,MAAM,OAAO,UAAW,SAAQ,aAAa;IACzC,YACI,OAAe,EACf,KAAc,EACd,MAAc,EACd,aAAqB;QAErB,KAAK,CAAC,OAAO,EAAE;YACX,KAAK,EAAE,aAAa;YACpB,IAAI,EAAE,aAAa;YACnB,QAAQ,EAAE,OAAO;YACjB,gEAAgE;YAChE,UAAU,EAAG,aAAqD,EAAE,UAAU;YAC9E,0EAA0E;YAC1E,MAAM,EAAE,uBAAuB,KAAK,CAAC,CAAC,CAAC,eAAe,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC;SACzH,CAAC,CAAC;QACH,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC7B,CAAC;CACJ"}
|
package/dist/index.d.ts
CHANGED
|
@@ -6,12 +6,10 @@ import { TransactionError } from './error-handling/TransactionError.js';
|
|
|
6
6
|
import { DatabaseConfig } from './interfaces/DatabaseConfig.js';
|
|
7
7
|
/**
|
|
8
8
|
* Core database client interface that all database implementations must follow.
|
|
9
|
-
* This ensures consistency between PostgreSQL, MySQL, and future database types.
|
|
10
9
|
*/
|
|
11
10
|
export type { DatabaseClient } from './interfaces/DatabaseClient.js';
|
|
12
11
|
/**
|
|
13
12
|
* SQL adapter interface for adapting SQL queries to specific database types.
|
|
14
|
-
* This allows for consistent query handling across different databases.
|
|
15
13
|
*/
|
|
16
14
|
export type { SqlAdapter } from './interfaces/SqlAdapter.js';
|
|
17
15
|
/**
|
|
@@ -19,7 +17,7 @@ export type { SqlAdapter } from './interfaces/SqlAdapter.js';
|
|
|
19
17
|
*/
|
|
20
18
|
export type { DatabaseTransaction } from './interfaces/DatabaseTransaction.js';
|
|
21
19
|
/**
|
|
22
|
-
* Alias for DatabaseTransaction
|
|
20
|
+
* Alias for DatabaseTransaction
|
|
23
21
|
*/
|
|
24
22
|
export type { DatabaseTransaction as Transaction } from './interfaces/DatabaseTransaction.js';
|
|
25
23
|
/**
|
|
@@ -65,7 +63,7 @@ export type { Migration } from './interfaces/Migration.js';
|
|
|
65
63
|
*/
|
|
66
64
|
export type { MigrationStatus } from './interfaces/MigrationStatus.js';
|
|
67
65
|
/**
|
|
68
|
-
* Alias for MigrationStatus
|
|
66
|
+
* Alias for MigrationStatus
|
|
69
67
|
*/
|
|
70
68
|
export type { MigrationStatus as MigrationRecord } from './interfaces/MigrationStatus.js';
|
|
71
69
|
/**
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAA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AAK,IAAI,cAEtD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,sBAAsB,GAAI,QAAQ,GAAG,KAAG,MAAM,IAAI,cAS9D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,cAAc,KAAG,MAE5D,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,wBAAwB,GAAI,QAAQ,cAAc,KAAG,OAAO,CAAC,cAAc,CAGvF,CAAC;AAMF;;GAEG;AACH,eAAO,MAAM,mBAAmB;;;;;;;CAOtB,CAAC;AAEX;;GAEG;AACH,eAAO,MAAM,sBAAsB,QAAwB,CAAC;AAE5D;;GAEG;AACH,MAAM,MAAM,kBAAkB,GAAG,YAAY,GAAG,OAAO,CAAC;AACxD;;GAEG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D;;GAEG;AACH,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,+EAA+E;AAE/E,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,gBAAgB,EAAE,MAAM,sCAAsC,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,+EAA+E;AAE/E,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAClE,OAAO,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,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M,0BAA0B,CAAC;AAC3D;;GAEG;AACH,OAAO,EAAE,0BAA0B,EAAE,MAAM,iCAAiC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DatabaseTransaction.d.ts","sourceRoot":"","sources":["../../src/interfaces/DatabaseTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C
|
|
1
|
+
{"version":3,"file":"DatabaseTransaction.d.ts","sourceRoot":"","sources":["../../src/interfaces/DatabaseTransaction.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAE/C;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAChC;;OAEG;IACH,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,EAAE,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAEtE;;;OAGG;IACH,MAAM,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAExB;;;OAGG;IACH,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAE1B;;OAEG;IACH,WAAW,IAAI,OAAO,CAAC;IAEvB,eAAe,IAAI,YAAY,GAAG,OAAO,CAAC;IAC1C,iBAAiB,IAAI,OAAO,CAAC;IAC7B,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAAC;IAC9B,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;IAC9D,eAAe,CAAC,SAAS,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;CACjE"}
|
|
@@ -6,8 +6,6 @@ export interface QueryResult<T = any> {
|
|
|
6
6
|
rowCount: number | null;
|
|
7
7
|
/**
|
|
8
8
|
* Id generated by an INSERT on engines without RETURNING (MySQL).
|
|
9
|
-
* Comes from the same statement, so it is safe under concurrency, unlike a
|
|
10
|
-
* separate `SELECT LAST_INSERT_ID()` sent through the pool.
|
|
11
9
|
*/
|
|
12
10
|
insertId?: number;
|
|
13
11
|
fields?: Array<{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"QueryResult.d.ts","sourceRoot":"","sources":["../../src/interfaces/QueryResult.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAChC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB
|
|
1
|
+
{"version":3,"file":"QueryResult.d.ts","sourceRoot":"","sources":["../../src/interfaces/QueryResult.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,WAAW,CAAC,CAAC,GAAG,GAAG;IAChC,IAAI,EAAE,CAAC,EAAE,CAAC;IACV,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,KAAK,CAAC;QACX,IAAI,EAAE,MAAM,CAAC;QACb,UAAU,CAAC,EAAE,MAAM,CAAC;QACpB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,gBAAgB,CAAC,EAAE,MAAM,CAAC;KAC7B,CAAC,CAAC;CACN"}
|
|
@@ -1,14 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Log level for a transaction that rolled back because its callback threw.
|
|
3
3
|
*
|
|
4
|
-
* -
|
|
5
|
-
*
|
|
6
|
-
* -
|
|
7
|
-
* of work: logging it as ERROR floods the error log and alerts with ordinary
|
|
8
|
-
* 404s. Matched by name, since db-core cannot depend on service-base. A mere
|
|
9
|
-
* string `code` is not enough: Node system errors (ECONNRESET) and raw driver
|
|
10
|
-
* errors carry one too, and those are real failures.
|
|
11
|
-
* - Anything else is unexpected (a TypeError, a bug, the network) and stays an error.
|
|
4
|
+
* - DatabaseError: `warn`.
|
|
5
|
+
* - Error whose `name` is `BusinessError`: `debug`.
|
|
6
|
+
* - Anything else, including system and raw driver errors that carry a `code`: `error`.
|
|
12
7
|
*/
|
|
13
8
|
export declare function transactionFailureLogLevel(error: unknown): 'debug' | 'warn' | 'error';
|
|
14
9
|
//# sourceMappingURL=transactionFailure.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactionFailure.d.ts","sourceRoot":"","sources":["../../src/logging/transactionFailure.ts"],"names":[],"mappings":"AAEA
|
|
1
|
+
{"version":3,"file":"transactionFailure.d.ts","sourceRoot":"","sources":["../../src/logging/transactionFailure.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,OAAO,CAQrF"}
|
|
@@ -2,14 +2,9 @@ import { DatabaseError } from '../error-handling/DatabaseError.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Log level for a transaction that rolled back because its callback threw.
|
|
4
4
|
*
|
|
5
|
-
* -
|
|
6
|
-
*
|
|
7
|
-
* -
|
|
8
|
-
* of work: logging it as ERROR floods the error log and alerts with ordinary
|
|
9
|
-
* 404s. Matched by name, since db-core cannot depend on service-base. A mere
|
|
10
|
-
* string `code` is not enough: Node system errors (ECONNRESET) and raw driver
|
|
11
|
-
* errors carry one too, and those are real failures.
|
|
12
|
-
* - Anything else is unexpected (a TypeError, a bug, the network) and stays an error.
|
|
5
|
+
* - DatabaseError: `warn`.
|
|
6
|
+
* - Error whose `name` is `BusinessError`: `debug`.
|
|
7
|
+
* - Anything else, including system and raw driver errors that carry a `code`: `error`.
|
|
13
8
|
*/
|
|
14
9
|
export function transactionFailureLogLevel(error) {
|
|
15
10
|
if (error instanceof DatabaseError) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transactionFailure.js","sourceRoot":"","sources":["../../src/logging/transactionFailure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAEnE
|
|
1
|
+
{"version":3,"file":"transactionFailure.js","sourceRoot":"","sources":["../../src/logging/transactionFailure.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oCAAoC,CAAC;AAEnE;;;;;;GAMG;AACH,MAAM,UAAU,0BAA0B,CAAC,KAAc;IACrD,IAAI,KAAK,YAAY,aAAa,EAAE,CAAC;QACjC,OAAO,MAAM,CAAC;IAClB,CAAC;IACD,IAAI,KAAK,YAAY,KAAK,IAAI,KAAK,CAAC,IAAI,KAAK,eAAe,EAAE,CAAC;QAC3D,OAAO,OAAO,CAAC;IACnB,CAAC;IACD,OAAO,OAAO,CAAC;AACnB,CAAC"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Quote a table or column name for the given database
|
|
3
|
-
* (`order`, `user`, `group`...)
|
|
2
|
+
* Quote a table or column name for the given database. Reserved words
|
|
3
|
+
* (`order`, `user`, `group`...) are accepted.
|
|
4
4
|
*
|
|
5
5
|
* Dotted names are quoted part by part (`schema.table` -> `"schema"."table"`)
|
|
6
|
-
* and `*` is left as is. Embedded quote characters are doubled
|
|
7
|
-
* keeps a caller-supplied name (a sort column, say) from breaking out of the
|
|
8
|
-
* identifier.
|
|
6
|
+
* and `*` is left as is. Embedded quote characters are doubled.
|
|
9
7
|
*
|
|
10
8
|
* Postgres treats a quoted identifier as case-sensitive: pass names exactly
|
|
11
|
-
* as they were created
|
|
9
|
+
* as they were created.
|
|
12
10
|
*/
|
|
13
11
|
export declare function quoteIdentifier(name: string, dbType: 'postgresql' | 'mysql'): string;
|
|
14
12
|
//# sourceMappingURL=quoteIdentifier.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quoteIdentifier.d.ts","sourceRoot":"","sources":["../../src/sql/quoteIdentifier.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quoteIdentifier.d.ts","sourceRoot":"","sources":["../../src/sql/quoteIdentifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,YAAY,GAAG,OAAO,GAAG,MAAM,CAMpF"}
|
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Quote a table or column name for the given database
|
|
3
|
-
* (`order`, `user`, `group`...)
|
|
2
|
+
* Quote a table or column name for the given database. Reserved words
|
|
3
|
+
* (`order`, `user`, `group`...) are accepted.
|
|
4
4
|
*
|
|
5
5
|
* Dotted names are quoted part by part (`schema.table` -> `"schema"."table"`)
|
|
6
|
-
* and `*` is left as is. Embedded quote characters are doubled
|
|
7
|
-
* keeps a caller-supplied name (a sort column, say) from breaking out of the
|
|
8
|
-
* identifier.
|
|
6
|
+
* and `*` is left as is. Embedded quote characters are doubled.
|
|
9
7
|
*
|
|
10
8
|
* Postgres treats a quoted identifier as case-sensitive: pass names exactly
|
|
11
|
-
* as they were created
|
|
9
|
+
* as they were created.
|
|
12
10
|
*/
|
|
13
11
|
export function quoteIdentifier(name, dbType) {
|
|
14
12
|
const quote = dbType === 'mysql' ? '`' : '"';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"quoteIdentifier.js","sourceRoot":"","sources":["../../src/sql/quoteIdentifier.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"quoteIdentifier.js","sourceRoot":"","sources":["../../src/sql/quoteIdentifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY,EAAE,MAA8B;IACxE,MAAM,KAAK,GAAG,MAAM,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAC7C,OAAO,IAAI;SACN,KAAK,CAAC,GAAG,CAAC;SACV,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;SAC/F,IAAI,CAAC,GAAG,CAAC,CAAC;AACnB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@groundbrick/db-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Core database interfaces and types for the TypeScript microframework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -30,11 +30,11 @@
|
|
|
30
30
|
"license": "MIT",
|
|
31
31
|
"repository": {
|
|
32
32
|
"type": "git",
|
|
33
|
-
"url": "git+https://github.com/200Systems/
|
|
33
|
+
"url": "git+https://github.com/200Systems/groundbrick.git",
|
|
34
34
|
"directory": "packages/db-core"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@groundbrick/logger": "^0.
|
|
37
|
+
"@groundbrick/logger": "^0.6.0"
|
|
38
38
|
},
|
|
39
39
|
"devDependencies": {
|
|
40
40
|
"@types/node": "^20.10.0",
|