@bernierllc/database-adapter 1.0.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 ADDED
@@ -0,0 +1,394 @@
1
+ # @bernierllc/database-adapter
2
+
3
+ Universal database connection and query abstraction layer with connection pooling for PostgreSQL, MySQL, SQLite, and MongoDB.
4
+
5
+ ## Features
6
+
7
+ - **Multi-Database Support** - Unified interface for PostgreSQL, SQLite, MySQL, and MongoDB
8
+ - **Connection Pooling** - Automatic connection pool management for PostgreSQL
9
+ - **Type-Safe** - Full TypeScript support with strict typing
10
+ - **CRUD Operations** - Convenience methods for common database operations
11
+ - **Transaction Support** - ACID transactions with automatic rollback on errors
12
+ - **Health Monitoring** - Built-in health checks and connection statistics
13
+ - **Error Handling** - Structured error types for different failure scenarios
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @bernierllc/database-adapter
19
+ ```
20
+
21
+ ### Peer Dependencies
22
+
23
+ Install the database driver(s) you need:
24
+
25
+ ```bash
26
+ # PostgreSQL
27
+ npm install pg
28
+
29
+ # MySQL
30
+ npm install mysql2
31
+
32
+ # SQLite
33
+ npm install better-sqlite3
34
+
35
+ # MongoDB
36
+ npm install mongodb
37
+ ```
38
+
39
+ ## Usage
40
+
41
+ ### Basic Setup
42
+
43
+ ```typescript
44
+ import { DatabaseManager } from '@bernierllc/database-adapter';
45
+
46
+ // PostgreSQL
47
+ const db = new DatabaseManager({
48
+ type: 'postgresql',
49
+ host: 'localhost',
50
+ port: 5432,
51
+ database: 'myapp',
52
+ user: 'postgres',
53
+ password: 'password',
54
+ pool: {
55
+ min: 2,
56
+ max: 10
57
+ }
58
+ });
59
+
60
+ // SQLite
61
+ const db = new DatabaseManager({
62
+ type: 'sqlite',
63
+ database: './data/myapp.db'
64
+ });
65
+
66
+ await db.connect();
67
+ ```
68
+
69
+ ### CRUD Operations
70
+
71
+ ```typescript
72
+ // Insert
73
+ const user = await db.insert('users', {
74
+ name: 'John Doe',
75
+ email: 'john@example.com',
76
+ age: 30
77
+ });
78
+ console.log(user.id); // Auto-generated ID
79
+
80
+ // Find by ID
81
+ const found = await db.findById('users', user.id);
82
+
83
+ // Find one by criteria
84
+ const user = await db.findOne('users', { email: 'john@example.com' });
85
+
86
+ // Find many with options
87
+ const users = await db.findMany(
88
+ 'users',
89
+ { age: { $gt: 25 } },
90
+ {
91
+ orderBy: 'created_at',
92
+ orderDirection: 'DESC',
93
+ limit: 10,
94
+ offset: 0
95
+ }
96
+ );
97
+
98
+ // Update
99
+ const updated = await db.update('users', user.id, {
100
+ name: 'John Smith'
101
+ });
102
+
103
+ // Delete
104
+ const deleted = await db.delete('users', user.id);
105
+ ```
106
+
107
+ ### Direct Queries
108
+
109
+ ```typescript
110
+ // Query multiple rows
111
+ const users = await db.query<User>(
112
+ 'SELECT * FROM users WHERE age > $1',
113
+ [25]
114
+ );
115
+
116
+ // Query single row
117
+ const user = await db.queryOne<User>(
118
+ 'SELECT * FROM users WHERE email = $1',
119
+ ['john@example.com']
120
+ );
121
+
122
+ // Execute (INSERT/UPDATE/DELETE)
123
+ const result = await db.execute(
124
+ 'UPDATE users SET last_login = $1 WHERE id = $2',
125
+ [new Date(), userId]
126
+ );
127
+ console.log(result.affectedRows);
128
+ ```
129
+
130
+ ### Transactions
131
+
132
+ ```typescript
133
+ await db.transaction(async (tx) => {
134
+ // Insert user
135
+ const user = await tx.queryOne(
136
+ 'INSERT INTO users (name, email) VALUES ($1, $2) RETURNING *',
137
+ ['John Doe', 'john@example.com']
138
+ );
139
+
140
+ // Insert profile
141
+ await tx.execute(
142
+ 'INSERT INTO profiles (user_id, bio) VALUES ($1, $2)',
143
+ [user.id, 'Software engineer']
144
+ );
145
+
146
+ // Both operations commit together, or rollback on any error
147
+ });
148
+ ```
149
+
150
+ ### Health Monitoring
151
+
152
+ ```typescript
153
+ // Check database health
154
+ const health = await db.healthCheck();
155
+ console.log(health.status); // 'healthy' or 'unhealthy'
156
+ console.log(health.responseTime); // ms
157
+
158
+ // Get connection statistics
159
+ const stats = await db.getStats();
160
+ console.log(stats.totalConnections);
161
+ console.log(stats.activeConnections);
162
+ console.log(stats.totalQueries);
163
+ console.log(stats.avgQueryTime);
164
+ ```
165
+
166
+ ## API Reference
167
+
168
+ ### DatabaseManager
169
+
170
+ #### Constructor
171
+
172
+ ```typescript
173
+ new DatabaseManager(config: DatabaseConfig)
174
+ ```
175
+
176
+ **DatabaseConfig Options:**
177
+
178
+ ```typescript
179
+ interface DatabaseConfig {
180
+ type: 'postgresql' | 'mysql' | 'sqlite' | 'mongodb';
181
+
182
+ // Connection options (PostgreSQL/MySQL)
183
+ host?: string;
184
+ port?: number;
185
+ database: string;
186
+ user?: string;
187
+ password?: string;
188
+
189
+ // SQLite options
190
+ filename?: string;
191
+
192
+ // Connection pool (PostgreSQL)
193
+ pool?: {
194
+ min?: number;
195
+ max?: number;
196
+ idleTimeoutMillis?: number;
197
+ connectionTimeoutMillis?: number;
198
+ };
199
+
200
+ // SSL (PostgreSQL)
201
+ ssl?: {
202
+ rejectUnauthorized?: boolean;
203
+ ca?: string;
204
+ cert?: string;
205
+ key?: string;
206
+ };
207
+ }
208
+ ```
209
+
210
+ #### Methods
211
+
212
+ ##### Connection Management
213
+
214
+ - `connect(): Promise<void>` - Connect to the database
215
+ - `disconnect(): Promise<void>` - Close all connections
216
+ - `healthCheck(): Promise<HealthCheckResult>` - Check database health
217
+ - `getStats(): Promise<ConnectionStats>` - Get connection statistics
218
+
219
+ ##### Direct Queries
220
+
221
+ - `query<T>(sql: string, params?: any[]): Promise<T[]>` - Execute SELECT query
222
+ - `queryOne<T>(sql: string, params?: any[]): Promise<T | null>` - Execute SELECT returning single row
223
+ - `execute(sql: string, params?: any[]): Promise<ExecuteResult>` - Execute INSERT/UPDATE/DELETE
224
+
225
+ ##### CRUD Operations
226
+
227
+ - `findById<T>(table: string, id: any): Promise<T | null>` - Find record by ID
228
+ - `findOne<T>(table: string, where: Record<string, any>): Promise<T | null>` - Find single record
229
+ - `findMany<T>(table: string, where?: Record<string, any>, options?: QueryOptions): Promise<T[]>` - Find multiple records
230
+ - `insert<T>(table: string, data: Partial<T>): Promise<T>` - Insert record
231
+ - `update<T>(table: string, id: any, data: Partial<T>): Promise<T>` - Update record
232
+ - `delete(table: string, id: any): Promise<boolean>` - Delete record
233
+
234
+ ##### Transactions
235
+
236
+ - `transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>` - Execute transaction
237
+
238
+ ### Error Types
239
+
240
+ ```typescript
241
+ // Base error
242
+ class DatabaseError extends Error {
243
+ code?: string;
244
+ cause?: Error;
245
+ }
246
+
247
+ // Specific error types
248
+ class ConnectionError extends DatabaseError {}
249
+ class QueryError extends DatabaseError {}
250
+ class TransactionError extends DatabaseError {}
251
+ ```
252
+
253
+ ### Type Definitions
254
+
255
+ ```typescript
256
+ interface ExecuteResult {
257
+ affectedRows: number;
258
+ insertId?: number | string;
259
+ changedRows?: number;
260
+ }
261
+
262
+ interface HealthCheckResult {
263
+ status: 'healthy' | 'unhealthy';
264
+ responseTime: number;
265
+ error?: string;
266
+ }
267
+
268
+ interface ConnectionStats {
269
+ totalConnections: number;
270
+ activeConnections: number;
271
+ idleConnections?: number;
272
+ waitingClients?: number;
273
+ totalQueries: number;
274
+ avgQueryTime: number;
275
+ }
276
+
277
+ interface QueryOptions {
278
+ orderBy?: string;
279
+ orderDirection?: 'ASC' | 'DESC';
280
+ limit?: number;
281
+ offset?: number;
282
+ }
283
+ ```
284
+
285
+ ## Database-Specific Features
286
+
287
+ ### PostgreSQL
288
+
289
+ - Connection pooling with configurable pool size
290
+ - SSL/TLS support
291
+ - Prepared statements for security
292
+ - Full transaction support
293
+
294
+ ### SQLite
295
+
296
+ - WAL (Write-Ahead Logging) mode for better concurrency
297
+ - In-memory or file-based databases
298
+ - Atomic transactions
299
+ - Foreign key enforcement
300
+
301
+ ### MySQL
302
+
303
+ - Connection pooling
304
+ - Prepared statements
305
+ - SSL support
306
+ - Transaction support
307
+
308
+ ### MongoDB
309
+
310
+ - Connection pooling
311
+ - Document-based operations
312
+ - Aggregation pipeline support
313
+
314
+ ## Best Practices
315
+
316
+ ### Connection Management
317
+
318
+ ```typescript
319
+ // Create connection once at app startup
320
+ const db = new DatabaseManager(config);
321
+ await db.connect();
322
+
323
+ // Use throughout app lifecycle
324
+
325
+ // Close on shutdown
326
+ process.on('SIGTERM', async () => {
327
+ await db.disconnect();
328
+ process.exit(0);
329
+ });
330
+ ```
331
+
332
+ ### Error Handling
333
+
334
+ ```typescript
335
+ try {
336
+ const user = await db.findById('users', userId);
337
+ } catch (error) {
338
+ if (error instanceof ConnectionError) {
339
+ // Handle connection failure
340
+ logger.error('Database connection failed', error);
341
+ } else if (error instanceof QueryError) {
342
+ // Handle query error
343
+ logger.error('Query failed', error);
344
+ } else {
345
+ // Handle unknown error
346
+ throw error;
347
+ }
348
+ }
349
+ ```
350
+
351
+ ### Type Safety
352
+
353
+ ```typescript
354
+ interface User {
355
+ id?: number;
356
+ name: string;
357
+ email: string;
358
+ created_at?: Date;
359
+ }
360
+
361
+ // Type-safe operations
362
+ const user = await db.findById<User>('users', 1);
363
+ const users = await db.query<User>('SELECT * FROM users');
364
+ const newUser = await db.insert<User>('users', {
365
+ name: 'John',
366
+ email: 'john@example.com'
367
+ });
368
+ ```
369
+
370
+ ## Performance Tips
371
+
372
+ 1. **Use Connection Pooling** - For PostgreSQL/MySQL, configure appropriate pool sizes
373
+ 2. **Prepare Statements** - The adapter automatically uses prepared statements
374
+ 3. **Batch Operations** - Use transactions for multiple related operations
375
+ 4. **Index Your Queries** - Create database indexes for frequently queried columns
376
+ 5. **Monitor Statistics** - Use `getStats()` to identify performance issues
377
+
378
+ ## Integration Status
379
+
380
+ - **Logger**: Not integrated - Uses console logging. Integration with @bernierllc/logger recommended for production
381
+ - **Docs-Suite**: Ready - Markdown documentation available
382
+ - **NeverHub integration**: Not applicable - Core utility package with no service discovery requirements
383
+
384
+ ## See Also
385
+
386
+ - [@bernierllc/logger](../logger) - Structured logging for database operations
387
+ - [@bernierllc/retry-policy](../retry-policy) - Add retry logic for transient database errors
388
+ - [@bernierllc/cache-manager](../cache-manager) - Cache database query results
389
+
390
+ ## License
391
+
392
+ Copyright (c) 2025 Bernier LLC. All rights reserved.
393
+
394
+ This package is proprietary software licensed for use only within the scope of the project it was delivered for.
@@ -0,0 +1,20 @@
1
+ import type { DatabaseAdapter, DatabaseConfig, ExecuteResult, HealthCheckResult, ConnectionStats, Transaction } from '../types.js';
2
+ export declare class PostgreSQLAdapter implements DatabaseAdapter {
3
+ private pool;
4
+ private config;
5
+ private queryCount;
6
+ private totalQueryTime;
7
+ constructor(config: DatabaseConfig);
8
+ private parseConfig;
9
+ connect(): Promise<void>;
10
+ disconnect(): Promise<void>;
11
+ query<T = any>(sql: string, params?: any[]): Promise<T[]>;
12
+ queryOne<T = any>(sql: string, params?: any[]): Promise<T | null>;
13
+ execute(sql: string, params?: any[]): Promise<ExecuteResult>;
14
+ transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>;
15
+ healthCheck(): Promise<HealthCheckResult>;
16
+ getStats(): Promise<ConnectionStats>;
17
+ private trackQuery;
18
+ private logQuery;
19
+ }
20
+ //# sourceMappingURL=postgresql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgresql.d.ts","sourceRoot":"","sources":["../../src/adapters/postgresql.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,WAAW,EAEZ,MAAM,aAAa,CAAC;AAerB,qBAAa,iBAAkB,YAAW,eAAe;IACvD,OAAO,CAAC,IAAI,CAAwB;IACpC,OAAO,CAAC,MAAM,CAAmB;IACjC,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,cAAc,CAAK;gBAEf,MAAM,EAAE,cAAc;IAIlC,OAAO,CAAC,WAAW;IAqBb,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IA2BxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAO3B,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAyB7D,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAKrE,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,aAAa,CAAC;IA6BhE,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAqD/D,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAwBzC,QAAQ,IAAI,OAAO,CAAC,eAAe,CAAC;IAW1C,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,QAAQ;CAQjB"}
@@ -0,0 +1,204 @@
1
+ /*
2
+ Copyright (c) 2025 Bernier LLC
3
+
4
+ This file is licensed to the client under a limited-use license.
5
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
6
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
+ */
8
+ import pg from 'pg';
9
+ import { ConnectionError, QueryError, TransactionError } from '../types.js';
10
+ const { Pool } = pg;
11
+ export class PostgreSQLAdapter {
12
+ pool = null;
13
+ config;
14
+ queryCount = 0;
15
+ totalQueryTime = 0;
16
+ constructor(config) {
17
+ this.config = this.parseConfig(config);
18
+ }
19
+ parseConfig(config) {
20
+ const defaultPool = {
21
+ min: 2,
22
+ max: 10,
23
+ acquireTimeoutMillis: 60000,
24
+ createTimeoutMillis: 30000,
25
+ idleTimeoutMillis: 30000,
26
+ reapIntervalMillis: 1000
27
+ };
28
+ return {
29
+ host: config.host || 'localhost',
30
+ port: config.port || 5432,
31
+ database: config.database,
32
+ user: config.username || 'postgres',
33
+ password: config.password || '',
34
+ ssl: config.ssl,
35
+ pool: { ...defaultPool, ...config.pool }
36
+ };
37
+ }
38
+ async connect() {
39
+ try {
40
+ this.pool = new Pool({
41
+ host: this.config.host,
42
+ port: this.config.port,
43
+ database: this.config.database,
44
+ user: this.config.user,
45
+ password: this.config.password,
46
+ ssl: this.config.ssl,
47
+ min: this.config.pool.min,
48
+ max: this.config.pool.max,
49
+ connectionTimeoutMillis: this.config.pool.acquireTimeoutMillis,
50
+ idleTimeoutMillis: this.config.pool.idleTimeoutMillis
51
+ });
52
+ // Test connection
53
+ const client = await this.pool.connect();
54
+ await client.query('SELECT 1');
55
+ client.release();
56
+ }
57
+ catch (error) {
58
+ throw new ConnectionError(`Failed to connect to PostgreSQL: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
59
+ }
60
+ }
61
+ async disconnect() {
62
+ if (this.pool) {
63
+ await this.pool.end();
64
+ this.pool = null;
65
+ }
66
+ }
67
+ async query(sql, params = []) {
68
+ if (!this.pool) {
69
+ throw new ConnectionError('Database not connected');
70
+ }
71
+ const client = await this.pool.connect();
72
+ try {
73
+ const start = Date.now();
74
+ const result = await client.query(sql, params);
75
+ const duration = Date.now() - start;
76
+ this.trackQuery(duration);
77
+ this.logQuery(sql, params, duration, result.rowCount || 0);
78
+ return result.rows;
79
+ }
80
+ catch (error) {
81
+ throw new QueryError(`Query failed: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
82
+ }
83
+ finally {
84
+ client.release();
85
+ }
86
+ }
87
+ async queryOne(sql, params = []) {
88
+ const results = await this.query(sql, params);
89
+ return results.length > 0 ? results[0] : null;
90
+ }
91
+ async execute(sql, params = []) {
92
+ if (!this.pool) {
93
+ throw new ConnectionError('Database not connected');
94
+ }
95
+ const client = await this.pool.connect();
96
+ try {
97
+ const start = Date.now();
98
+ const result = await client.query(sql, params);
99
+ const duration = Date.now() - start;
100
+ this.trackQuery(duration);
101
+ this.logQuery(sql, params, duration, result.rowCount || 0);
102
+ return {
103
+ affectedRows: result.rowCount || 0,
104
+ insertId: result.rows[0]?.id,
105
+ changedRows: result.rowCount || 0
106
+ };
107
+ }
108
+ catch (error) {
109
+ throw new QueryError(`Execute failed: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
110
+ }
111
+ finally {
112
+ client.release();
113
+ }
114
+ }
115
+ async transaction(fn) {
116
+ if (!this.pool) {
117
+ throw new ConnectionError('Database not connected');
118
+ }
119
+ const client = await this.pool.connect();
120
+ try {
121
+ await client.query('BEGIN');
122
+ const transaction = {
123
+ query: async (sql, params) => {
124
+ const result = await client.query(sql, params || []);
125
+ return result.rows;
126
+ },
127
+ queryOne: async (sql, params) => {
128
+ const result = await client.query(sql, params || []);
129
+ return result.rows.length > 0 ? result.rows[0] : null;
130
+ },
131
+ execute: async (sql, params) => {
132
+ const result = await client.query(sql, params || []);
133
+ return {
134
+ affectedRows: result.rowCount || 0,
135
+ insertId: result.rows[0]?.id,
136
+ changedRows: result.rowCount || 0
137
+ };
138
+ },
139
+ commit: async () => {
140
+ await client.query('COMMIT');
141
+ },
142
+ rollback: async () => {
143
+ await client.query('ROLLBACK');
144
+ }
145
+ };
146
+ const result = await fn(transaction);
147
+ await transaction.commit();
148
+ return result;
149
+ }
150
+ catch (error) {
151
+ await client.query('ROLLBACK');
152
+ throw new TransactionError(`Transaction failed: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
153
+ }
154
+ finally {
155
+ client.release();
156
+ }
157
+ }
158
+ async healthCheck() {
159
+ try {
160
+ const start = Date.now();
161
+ await this.queryOne('SELECT 1 as health');
162
+ const responseTime = Date.now() - start;
163
+ return {
164
+ status: 'healthy',
165
+ responseTime,
166
+ details: this.pool ? {
167
+ totalConnections: this.pool.totalCount,
168
+ idleConnections: this.pool.idleCount,
169
+ waitingClients: this.pool.waitingCount
170
+ } : undefined
171
+ };
172
+ }
173
+ catch (error) {
174
+ return {
175
+ status: 'unhealthy',
176
+ responseTime: 0,
177
+ error: error instanceof Error ? error.message : String(error)
178
+ };
179
+ }
180
+ }
181
+ async getStats() {
182
+ return {
183
+ totalConnections: this.pool?.totalCount || 0,
184
+ activeConnections: (this.pool?.totalCount || 0) - (this.pool?.idleCount || 0),
185
+ idleConnections: this.pool?.idleCount || 0,
186
+ waitingClients: this.pool?.waitingCount || 0,
187
+ avgQueryTime: this.queryCount > 0 ? this.totalQueryTime / this.queryCount : 0,
188
+ totalQueries: this.queryCount
189
+ };
190
+ }
191
+ trackQuery(duration) {
192
+ this.queryCount++;
193
+ this.totalQueryTime += duration;
194
+ }
195
+ logQuery(sql, params, duration, rowCount) {
196
+ console.debug('PostgreSQL query executed', {
197
+ sql: sql.substring(0, 100) + (sql.length > 100 ? '...' : ''),
198
+ paramCount: params.length,
199
+ duration,
200
+ rowCount
201
+ });
202
+ }
203
+ }
204
+ //# sourceMappingURL=postgresql.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postgresql.js","sourceRoot":"","sources":["../../src/adapters/postgresql.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,MAAM,IAAI,CAAC;AAUpB,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC;AAYpB,MAAM,OAAO,iBAAiB;IACpB,IAAI,GAAmB,IAAI,CAAC;IAC5B,MAAM,CAAmB;IACzB,UAAU,GAAG,CAAC,CAAC;IACf,cAAc,GAAG,CAAC,CAAC;IAE3B,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,CAAC;IACzC,CAAC;IAEO,WAAW,CAAC,MAAsB;QACxC,MAAM,WAAW,GAAyB;YACxC,GAAG,EAAE,CAAC;YACN,GAAG,EAA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AAU,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,cAAc,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAC7E,YAAY,EAAE,IAAI,CAAC,UAAU;SAC9B,CAAC;IACJ,CAAC;IAEO,UAAU,CAAC,QAAgB;QACjC,IAAI,CAAC,UAAU,EAAE,CAAC;QAClB,IAAI,CAAC,cAAc,IAAI,QAAQ,CAAC;IAClC,CAAC;IAEO,QAAQ,CAAC,GAAW,EAAE,MAAa,EAAE,QAAgB,EAAE,QAAgB;QAC7E,OAAO,CAAC,KAAK,CAAC,2BAA2B,EAAE;YACzC,GAAG,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5D,UAAU,EAAE,MAAM,CAAC,MAAM;YACzB,QAAQ;YACR,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,19 @@
1
+ import type { DatabaseAdapter, DatabaseConfig, ExecuteResult, HealthCheckResult, ConnectionStats, Transaction } from '../types.js';
2
+ export declare class SQLiteAdapter implements DatabaseAdapter {
3
+ private db;
4
+ private dbPath;
5
+ private queryCount;
6
+ private totalQueryTime;
7
+ constructor(config: DatabaseConfig);
8
+ connect(): Promise<void>;
9
+ disconnect(): Promise<void>;
10
+ query<T = any>(sql: string, params?: any[]): Promise<T[]>;
11
+ queryOne<T = any>(sql: string, params?: any[]): Promise<T | null>;
12
+ execute(sql: string, params?: any[]): Promise<ExecuteResult>;
13
+ transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>;
14
+ healthCheck(): Promise<HealthCheckResult>;
15
+ getStats(): Promise<ConnectionStats>;
16
+ private trackQuery;
17
+ private logQuery;
18
+ }
19
+ //# sourceMappingURL=sqlite.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.d.ts","sourceRoot":"","sources":["../../src/adapters/sqlite.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,WAAW,EACZ,MAAM,aAAa,CAAC;AAGrB,qBAAa,aAAc,YAAW,eAAe;IACnD,OAAO,CAAC,EAAE,CAAkC;IAC5C,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,cAAc,CAAK;gBAEf,MAAM,EAAE,cAAc;IAI5B,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAaxB,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IAO3B,KAAK,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,CAAC,EAAE,CAAC;IAuB7D,QAAQ,CAAC,CAAC,GAAG,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,CAAC,GAAG,IAAI,CAAC;IAuBrE,OAAO,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,GAAE,GAAG,EAAO,GAAG,OAAO,CAAC,aAAa,CAAC;IA2BhE,WAAW,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAqD/D,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAmBzC,QAAQ,IAAI,OAAO,CAAC,eAAe,CAAC;IAU1C,OAAO,CAAC,UAAU;IAKlB,OAAO,CAAC,QAAQ;CAQjB"}
@@ -0,0 +1,171 @@
1
+ /*
2
+ Copyright (c) 2025 Bernier LLC
3
+
4
+ This file is licensed to the client under a limited-use license.
5
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
6
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
+ */
8
+ import Database from 'better-sqlite3';
9
+ import { ConnectionError, QueryError, TransactionError } from '../types.js';
10
+ export class SQLiteAdapter {
11
+ db = null;
12
+ dbPath;
13
+ queryCount = 0;
14
+ totalQueryTime = 0;
15
+ constructor(config) {
16
+ this.dbPath = config.database;
17
+ }
18
+ async connect() {
19
+ try {
20
+ this.db = new Database(this.dbPath);
21
+ // Enable WAL mode for better concurrency
22
+ this.db.pragma('journal_mode = WAL');
23
+ }
24
+ catch (error) {
25
+ throw new ConnectionError(`Failed to connect to SQLite: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
26
+ }
27
+ }
28
+ async disconnect() {
29
+ if (this.db) {
30
+ this.db.close();
31
+ this.db = null;
32
+ }
33
+ }
34
+ async query(sql, params = []) {
35
+ if (!this.db) {
36
+ throw new ConnectionError('Database not connected');
37
+ }
38
+ try {
39
+ const start = Date.now();
40
+ const stmt = this.db.prepare(sql);
41
+ const result = stmt.all(...params);
42
+ const duration = Date.now() - start;
43
+ this.trackQuery(duration);
44
+ this.logQuery(sql, params, duration, result.length);
45
+ return result;
46
+ }
47
+ catch (error) {
48
+ throw new QueryError(`Query failed: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
49
+ }
50
+ }
51
+ async queryOne(sql, params = []) {
52
+ if (!this.db) {
53
+ throw new ConnectionError('Database not connected');
54
+ }
55
+ try {
56
+ const start = Date.now();
57
+ const stmt = this.db.prepare(sql);
58
+ const result = stmt.get(...params);
59
+ const duration = Date.now() - start;
60
+ this.trackQuery(duration);
61
+ this.logQuery(sql, params, duration, result ? 1 : 0);
62
+ return result || null;
63
+ }
64
+ catch (error) {
65
+ throw new QueryError(`Query failed: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
66
+ }
67
+ }
68
+ async execute(sql, params = []) {
69
+ if (!this.db) {
70
+ throw new ConnectionError('Database not connected');
71
+ }
72
+ try {
73
+ const start = Date.now();
74
+ const stmt = this.db.prepare(sql);
75
+ const info = stmt.run(...params);
76
+ const duration = Date.now() - start;
77
+ this.trackQuery(duration);
78
+ this.logQuery(sql, params, duration, info.changes);
79
+ return {
80
+ affectedRows: info.changes,
81
+ insertId: info.lastInsertRowid,
82
+ changedRows: info.changes
83
+ };
84
+ }
85
+ catch (error) {
86
+ throw new QueryError(`Execute failed: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
87
+ }
88
+ }
89
+ async transaction(fn) {
90
+ if (!this.db) {
91
+ throw new ConnectionError('Database not connected');
92
+ }
93
+ const db = this.db;
94
+ try {
95
+ db.exec('BEGIN');
96
+ const transaction = {
97
+ query: async (sql, params) => {
98
+ const stmt = db.prepare(sql);
99
+ return stmt.all(...(params || []));
100
+ },
101
+ queryOne: async (sql, params) => {
102
+ const stmt = db.prepare(sql);
103
+ const result = stmt.get(...(params || []));
104
+ return result || null;
105
+ },
106
+ execute: async (sql, params) => {
107
+ const stmt = db.prepare(sql);
108
+ const info = stmt.run(...(params || []));
109
+ return {
110
+ affectedRows: info.changes,
111
+ insertId: info.lastInsertRowid,
112
+ changedRows: info.changes
113
+ };
114
+ },
115
+ commit: async () => {
116
+ db.exec('COMMIT');
117
+ },
118
+ rollback: async () => {
119
+ db.exec('ROLLBACK');
120
+ }
121
+ };
122
+ const result = await fn(transaction);
123
+ await transaction.commit();
124
+ return result;
125
+ }
126
+ catch (error) {
127
+ db.exec('ROLLBACK');
128
+ throw new TransactionError(`Transaction failed: ${error instanceof Error ? error.message : String(error)}`, error instanceof Error ? error : undefined);
129
+ }
130
+ }
131
+ async healthCheck() {
132
+ try {
133
+ const start = Date.now();
134
+ await this.queryOne('SELECT 1 as health');
135
+ const responseTime = Date.now() - start;
136
+ return {
137
+ status: 'healthy',
138
+ responseTime
139
+ };
140
+ }
141
+ catch (error) {
142
+ return {
143
+ status: 'unhealthy',
144
+ responseTime: 0,
145
+ error: error instanceof Error ? error.message : String(error)
146
+ };
147
+ }
148
+ }
149
+ async getStats() {
150
+ return {
151
+ totalConnections: 1, // SQLite uses single connection
152
+ activeConnections: this.db ? 1 : 0,
153
+ idleConnections: 0,
154
+ avgQueryTime: this.queryCount > 0 ? this.totalQueryTime / this.queryCount : 0,
155
+ totalQueries: this.queryCount
156
+ };
157
+ }
158
+ trackQuery(duration) {
159
+ this.queryCount++;
160
+ this.totalQueryTime += duration;
161
+ }
162
+ logQuery(sql, params, duration, rowCount) {
163
+ console.debug('SQLite query executed', {
164
+ sql: sql.substring(0, 100) + (sql.length > 100 ? '...' : ''),
165
+ paramCount: params.length,
166
+ duration,
167
+ rowCount
168
+ });
169
+ }
170
+ }
171
+ //# sourceMappingURL=sqlite.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"sqlite.js","sourceRoot":"","sources":["../../src/adapters/sqlite.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,QAAQ,MAAM,gBAAgB,CAAC;AAStC,OAAO,EAAE,eAAe,EAAE,UAAU,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE5E,MAAM,OAAO,aAAa;IAChB,EAAE,GAA6B,IAAI,CAAC;IACpC,MAAM,CAAS;IACf,UAAU,GAAG,CAAC,CAAC;IACf,cAAc,GAAG,CAAC,CAAC;IAE3B,YAAY,MAAsB;QAChC,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC,QAAQ,CAAC;IAChC,CAAC;IAED,KAAK,CAAC,OAAO;QACX,IAAI,CAAC;YACH,IAAI,CAAC,EAAE,GAAG,IAAI,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACpC,yCAAyC;YACzC,IAAI,CAAC,EAAE,CAAC,MAAM,CAAC,oBAAoB,CAAC,CAAC;QACvC,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,IAAI,eAAe,CACvB,gCAAgC,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC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AgB,EAAE,QAAgB;QAC7E,OAAO,CAAC,KAAK,CAAC,uBAAuB,EAAE;YACrC,GAAG,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC,EAAE,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5D,UAAU,EAAE,MAAM,CAAC,MAAM;YACzB,QAAQ;YACR,QAAQ;SACT,CAAC,CAAC;IACL,CAAC;CACF"}
@@ -0,0 +1,21 @@
1
+ import type { DatabaseConfig, ExecuteResult, HealthCheckResult, ConnectionStats, Transaction, QueryOptions } from './types.js';
2
+ export declare class DatabaseManager {
3
+ private adapter;
4
+ constructor(config: DatabaseConfig);
5
+ private createAdapter;
6
+ connect(): Promise<void>;
7
+ disconnect(): Promise<void>;
8
+ query<T = any>(sql: string, params?: any[]): Promise<T[]>;
9
+ queryOne<T = any>(sql: string, params?: any[]): Promise<T | null>;
10
+ execute(sql: string, params?: any[]): Promise<ExecuteResult>;
11
+ transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>;
12
+ findById<T = any>(table: string, id: any): Promise<T | null>;
13
+ findOne<T = any>(table: string, where: Record<string, any>): Promise<T | null>;
14
+ findMany<T = any>(table: string, where?: Record<string, any>, options?: QueryOptions): Promise<T[]>;
15
+ insert<T = any>(table: string, data: Partial<T>): Promise<T>;
16
+ update<T = any>(table: string, id: any, data: Partial<T>): Promise<T>;
17
+ delete(table: string, id: any): Promise<boolean>;
18
+ healthCheck(): Promise<HealthCheckResult>;
19
+ getStats(): Promise<ConnectionStats>;
20
+ }
21
+ //# sourceMappingURL=database-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-manager.d.ts","sourceRoot":"","sources":["../src/database-manager.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAEV,cAAc,EACd,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,YAAY,EACb,MAA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EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAgB5D,MAAM,CAAC,CAAC,GAAG,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,CAAC,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC;IAerE,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,EAAE,EAAE,GAAG,GAAG,OAAO,CAAC,OAAO,CAAC;IAOhD,WAAW,IAAI,OAAO,CAAC,iBAAiB,CAAC;IAIzC,QAAQ,IAAI,OAAO,CAAC,eAAe,CAAC;CAG3C"}
@@ -0,0 +1,119 @@
1
+ /*
2
+ Copyright (c) 2025 Bernier LLC
3
+
4
+ This file is licensed to the client under a limited-use license.
5
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
6
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
+ */
8
+ import { DatabaseError } from './types.js';
9
+ import { PostgreSQLAdapter } from './adapters/postgresql.js';
10
+ import { SQLiteAdapter } from './adapters/sqlite.js';
11
+ export class DatabaseManager {
12
+ adapter;
13
+ constructor(config) {
14
+ this.adapter = this.createAdapter(config);
15
+ }
16
+ createAdapter(config) {
17
+ switch (config.type) {
18
+ case 'postgresql':
19
+ return new PostgreSQLAdapter(config);
20
+ case 'sqlite':
21
+ return new SQLiteAdapter(config);
22
+ case 'mysql':
23
+ throw new DatabaseError('MySQL adapter not yet implemented');
24
+ case 'mongodb':
25
+ throw new DatabaseError('MongoDB adapter not yet implemented');
26
+ default:
27
+ throw new DatabaseError(`Unsupported database type: ${config.type}`);
28
+ }
29
+ }
30
+ async connect() {
31
+ return this.adapter.connect();
32
+ }
33
+ async disconnect() {
34
+ return this.adapter.disconnect();
35
+ }
36
+ // Direct query methods
37
+ async query(sql, params) {
38
+ return this.adapter.query(sql, params);
39
+ }
40
+ async queryOne(sql, params) {
41
+ return this.adapter.queryOne(sql, params);
42
+ }
43
+ async execute(sql, params) {
44
+ return this.adapter.execute(sql, params);
45
+ }
46
+ // Transaction support
47
+ async transaction(fn) {
48
+ return this.adapter.transaction(fn);
49
+ }
50
+ // Convenience CRUD methods
51
+ async findById(table, id) {
52
+ const sql = `SELECT * FROM ${table} WHERE id = $1 LIMIT 1`;
53
+ return this.adapter.queryOne(sql, [id]);
54
+ }
55
+ async findOne(table, where) {
56
+ const keys = Object.keys(where);
57
+ const values = Object.values(where);
58
+ const conditions = keys.map((key, idx) => `${key} = $${idx + 1}`).join(' AND ');
59
+ const sql = `SELECT * FROM ${table} WHERE ${conditions} LIMIT 1`;
60
+ return this.adapter.queryOne(sql, values);
61
+ }
62
+ async findMany(table, where, options) {
63
+ let sql = `SELECT * FROM ${table}`;
64
+ const params = [];
65
+ if (where && Object.keys(where).length > 0) {
66
+ const keys = Object.keys(where);
67
+ const values = Object.values(where);
68
+ const conditions = keys.map((key, idx) => `${key} = $${idx + 1}`).join(' AND ');
69
+ sql += ` WHERE ${conditions}`;
70
+ params.push(...values);
71
+ }
72
+ if (options?.orderBy) {
73
+ sql += ` ORDER BY ${options.orderBy} ${options.orderDirection || 'ASC'}`;
74
+ }
75
+ if (options?.limit) {
76
+ sql += ` LIMIT ${options.limit}`;
77
+ }
78
+ if (options?.offset) {
79
+ sql += ` OFFSET ${options.offset}`;
80
+ }
81
+ return this.adapter.query(sql, params);
82
+ }
83
+ async insert(table, data) {
84
+ const keys = Object.keys(data);
85
+ const values = Object.values(data);
86
+ const placeholders = keys.map((_, idx) => `$${idx + 1}`).join(', ');
87
+ const columns = keys.join(', ');
88
+ const sql = `INSERT INTO ${table} (${columns}) VALUES (${placeholders}) RETURNING *`;
89
+ const result = await this.adapter.queryOne(sql, values);
90
+ if (!result) {
91
+ throw new DatabaseError('Insert operation failed to return result');
92
+ }
93
+ return result;
94
+ }
95
+ async update(table, id, data) {
96
+ const keys = Object.keys(data);
97
+ const values = Object.values(data);
98
+ const sets = keys.map((key, idx) => `${key} = $${idx + 1}`).join(', ');
99
+ const sql = `UPDATE ${table} SET ${sets} WHERE id = $${keys.length + 1} RETURNING *`;
100
+ const result = await this.adapter.queryOne(sql, [...values, id]);
101
+ if (!result) {
102
+ throw new DatabaseError('Update operation failed to return result');
103
+ }
104
+ return result;
105
+ }
106
+ async delete(table, id) {
107
+ const sql = `DELETE FROM ${table} WHERE id = $1`;
108
+ const result = await this.adapter.execute(sql, [id]);
109
+ return result.affectedRows > 0;
110
+ }
111
+ // Health and monitoring
112
+ async healthCheck() {
113
+ return this.adapter.healthCheck();
114
+ }
115
+ async getStats() {
116
+ return this.adapter.getStats();
117
+ }
118
+ }
119
+ //# sourceMappingURL=database-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"database-manager.js","sourceRoot":"","sources":["../src/database-manager.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAWF,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,MAAM,OAAO,eAAe;IAClB,OAAO,CAAkB;IAEjC,YAAY,MAAsB;QAChC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC5C,CAAC;IAEO,aAAa,CAAC,MAAsB;QAC1C,QAAQ,MAAM,CAAC,IAAI,EAAE,CAAC;YACpB,KAAK,YAAY;gBACf,OAAO,IAAI,iBAAiB,CAAC,MAAM,CAAC,CAAC;YACvC,KAAK,QAAQ;gBACX,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;YACnC,KAAK,OAAO;gBACV,MAAM,IAAI,aAAa,CAAC,mCAAmC,CAAC,CAAC;YAC/D,KAAK,SAAS;gBACZ,MAAM,IAAI,aAAa,CAAC,qCAAqC,CAAC,CAAC;YACjE;gBACE,MAAM,IAAI,aAAa,CA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EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAEvE,MAAM,GAAG,GAAG,UAAU,KAAK,QAAQ,IAAI,gBAAgB,IAAI,CAAC,MAAM,GAAG,CAAC,cAAc,CAAC;QACrF,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAI,GAAG,EAAE,CAAC,GAAG,MAAM,EAAE,EAAE,CAAC,CAAC,CAAC;QAEpE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,aAAa,CAAC,0CAA0C,CAAC,CAAC;QACtE,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;IAED,KAAK,CAAC,MAAM,CAAC,KAAa,EAAE,EAAO;QACjC,MAAM,GAAG,GAAG,eAAe,KAAK,gBAAgB,CAAC;QACjD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC;QACrD,OAAO,MAAM,CAAC,YAAY,GAAG,CAAC,CAAC;IACjC,CAAC;IAED,wBAAwB;IACxB,KAAK,CAAC,WAAW;QACf,OAAO,IAAI,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC;IACpC,CAAC;IAED,KAAK,CAAC,QAAQ;QACZ,OAAO,IAAI,CAAC,OAAO,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;CACF"}
@@ -0,0 +1,6 @@
1
+ export { DatabaseManager } from './database-manager.js';
2
+ export { PostgreSQLAdapter } from './adapters/postgresql.js';
3
+ export { SQLiteAdapter } from './adapters/sqlite.js';
4
+ export type { DatabaseAdapter, DatabaseConfig, DatabaseType, ExecuteResult, HealthCheckResult, ConnectionStats, Transaction, QueryOptions, PoolConfig, SSLConfig } from './types.js';
5
+ export { DatabaseError, ConnectionError, QueryError, TransactionError } from './types.js';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAQA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAErD,YAAY,EACV,eAAe,EACf,cAAc,EACd,YAAY,EACZ,aAAa,EACb,iBAAiB,EACjB,eAAe,EACf,WAAW,EACX,YAAY,EACZ,UAAU,EACV,SAAS,EACV,MAAM,YAAY,CAAC;AAEpB,OAAO,EACL,aAAa,EACb,eAAe,EACf,UAAU,EACV,gBAAgB,EACjB,MAAM,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ /*
2
+ Copyright (c) 2025 Bernier LLC
3
+
4
+ This file is licensed to the client under a limited-use license.
5
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
6
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
+ */
8
+ export { DatabaseManager } from './database-manager.js';
9
+ export { PostgreSQLAdapter } from './adapters/postgresql.js';
10
+ export { SQLiteAdapter } from './adapters/sqlite.js';
11
+ export { DatabaseError, ConnectionError, QueryError, TransactionError } from './types.js';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AAEF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAerD,OAAO,EACL,aAAa,EACb,eAAe,EACf,UAAU,EACV,gBAAgB,EACjB,MAAM,YAAY,CAAC"}
@@ -0,0 +1,88 @@
1
+ export type DatabaseType = 'postgresql' | 'mysql' | 'sqlite' | 'mongodb';
2
+ export interface DatabaseConfig {
3
+ type: DatabaseType;
4
+ host?: string;
5
+ port?: number;
6
+ database: string;
7
+ username?: string;
8
+ password?: string;
9
+ connectionString?: string;
10
+ pool?: Partial<PoolConfig>;
11
+ ssl?: boolean | SSLConfig;
12
+ options?: Record<string, any>;
13
+ }
14
+ export interface PoolConfig {
15
+ min: number;
16
+ max: number;
17
+ acquireTimeoutMillis: number;
18
+ createTimeoutMillis: number;
19
+ idleTimeoutMillis: number;
20
+ reapIntervalMillis: number;
21
+ }
22
+ export interface SSLConfig {
23
+ rejectUnauthorized?: boolean;
24
+ ca?: string;
25
+ cert?: string;
26
+ key?: string;
27
+ }
28
+ export interface ExecuteResult {
29
+ affectedRows: number;
30
+ insertId?: any;
31
+ changedRows: number;
32
+ }
33
+ export interface HealthCheckResult {
34
+ status: 'healthy' | 'unhealthy';
35
+ responseTime: number;
36
+ details?: {
37
+ totalConnections?: number;
38
+ idleConnections?: number;
39
+ waitingClients?: number;
40
+ };
41
+ error?: string;
42
+ }
43
+ export interface ConnectionStats {
44
+ totalConnections: number;
45
+ activeConnections: number;
46
+ idleConnections: number;
47
+ waitingClients?: number;
48
+ avgQueryTime?: number;
49
+ totalQueries?: number;
50
+ }
51
+ export interface QueryOptions {
52
+ limit?: number;
53
+ offset?: number;
54
+ orderBy?: string;
55
+ orderDirection?: 'ASC' | 'DESC';
56
+ }
57
+ export interface Transaction {
58
+ query<T = any>(sql: string, params?: any[]): Promise<T[]>;
59
+ queryOne<T = any>(sql: string, params?: any[]): Promise<T | null>;
60
+ execute(sql: string, params?: any[]): Promise<ExecuteResult>;
61
+ commit(): Promise<void>;
62
+ rollback(): Promise<void>;
63
+ }
64
+ export interface DatabaseAdapter {
65
+ connect(): Promise<void>;
66
+ disconnect(): Promise<void>;
67
+ query<T = any>(sql: string, params?: any[]): Promise<T[]>;
68
+ queryOne<T = any>(sql: string, params?: any[]): Promise<T | null>;
69
+ execute(sql: string, params?: any[]): Promise<ExecuteResult>;
70
+ transaction<T>(fn: (tx: Transaction) => Promise<T>): Promise<T>;
71
+ healthCheck(): Promise<HealthCheckResult>;
72
+ getStats(): Promise<ConnectionStats>;
73
+ }
74
+ export declare class DatabaseError extends Error {
75
+ readonly code?: string | undefined;
76
+ readonly cause?: Error | undefined;
77
+ constructor(message: string, code?: string | undefined, cause?: Error | undefined);
78
+ }
79
+ export declare class ConnectionError extends DatabaseError {
80
+ constructor(message: string, cause?: Error);
81
+ }
82
+ export declare class QueryError extends DatabaseError {
83
+ constructor(message: string, cause?: Error);
84
+ }
85
+ export declare class TransactionError extends DatabaseError {
86
+ constructor(message: string, cause?: Error);
87
+ }
88
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAQA,MAAM,MAAM,YAAY,GAAG,YAAY,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,CAAC;AAEzE,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,YAAY,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAC3B,GAAG,CAAC,EAAE,OAAO,GAAG,SAAS,CAAC;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;CAC/B;AAED,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,GAAG,EAAE,MAAM,CAAC;IACZ,oBAAoB,EAAE,MAAM,CAAC;IAC7B,mBAAmB,EAAE,MAAM,CAAC;IAC5B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,kBAAkB,EAAE,MAAM,CAAC;CAC5B;AAED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YAAA;CAKhC;AAED,qBAAa,eAAgB,SAAQ,aAAa;gBACpC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAI3C;AAED,qBAAa,UAAW,SAAQ,aAAa;gBAC/B,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAI3C;AAED,qBAAa,gBAAiB,SAAQ,aAAa;gBACrC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,KAAK;CAI3C"}
package/dist/types.js ADDED
@@ -0,0 +1,36 @@
1
+ /*
2
+ Copyright (c) 2025 Bernier LLC
3
+
4
+ This file is licensed to the client under a limited-use license.
5
+ The client may use and modify this code *only within the scope of the project it was delivered for*.
6
+ Redistribution or use in other products or commercial offerings is not permitted without written consent from Bernier LLC.
7
+ */
8
+ export class DatabaseError extends Error {
9
+ code;
10
+ cause;
11
+ constructor(message, code, cause) {
12
+ super(message);
13
+ this.code = code;
14
+ this.cause = cause;
15
+ this.name = 'DatabaseError';
16
+ }
17
+ }
18
+ export class ConnectionError extends DatabaseError {
19
+ constructor(message, cause) {
20
+ super(message, 'CONNECTION_ERROR', cause);
21
+ this.name = 'ConnectionError';
22
+ }
23
+ }
24
+ export class QueryError extends DatabaseError {
25
+ constructor(message, cause) {
26
+ super(message, 'QUERY_ERROR', cause);
27
+ this.name = 'QueryError';
28
+ }
29
+ }
30
+ export class TransactionError extends DatabaseError {
31
+ constructor(message, cause) {
32
+ super(message, 'TRANSACTION_ERROR', cause);
33
+ this.name = 'TransactionError';
34
+ }
35
+ }
36
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;EAME;AA2FF,MAAM,OAAO,aAAc,SAAQ,KAAK;IAGpB;IACA;IAHlB,YACE,OAAe,EACC,IAAa,EACb,KAAa;QAE7B,KAAK,CAAC,OAAO,CAAC,CAAC;QAHC,SAAI,GAAJ,IAAI,CAAS;QACb,UAAK,GAAL,KAAK,CAAQ;QAG7B,IAAI,CAAC,IAAI,GAAG,eAAe,CAAC;IAC9B,CAAC;CACF;AAED,MAAM,OAAO,eAAgB,SAAQ,aAAa;IAChD,YAAY,OAAe,EAAE,KAAa;QACxC,KAAK,CAAC,OAAO,EAAE,kBAAkB,EAAE,KAAK,CAAC,CAAC;QAC1C,IAAI,CAAC,IAAI,GAAG,iBAAiB,CAAC;IAChC,CAAC;CACF;AAED,MAAM,OAAO,UAAW,SAAQ,aAAa;IAC3C,YAAY,OAAe,EAAE,KAAa;QACxC,KAAK,CAAC,OAAO,EAAE,aAAa,EAAE,KAAK,CAAC,CAAC;QACrC,IAAI,CAAC,IAAI,GAAG,YAAY,CAAC;IAC3B,CAAC;CACF;AAED,MAAM,OAAO,gBAAiB,SAAQ,aAAa;IACjD,YAAY,OAAe,EAAE,KAAa;QACxC,KAAK,CAAC,OAAO,EAAE,mBAAmB,EAAE,KAAK,CAAC,CAAC;QAC3C,IAAI,CAAC,IAAI,GAAG,kBAAkB,CAAC;IACjC,CAAC;CACF"}
package/package.json ADDED
@@ -0,0 +1,81 @@
1
+ {
2
+ "name": "@bernierllc/database-adapter",
3
+ "version": "1.0.1",
4
+ "description": "Universal database connection and query abstraction layer with connection pooling",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "type": "module",
8
+ "files": [
9
+ "dist",
10
+ "README.md",
11
+ "LICENSE"
12
+ ],
13
+ "scripts": {
14
+ "build": "tsc",
15
+ "prebuild": "npm run clean",
16
+ "clean": "rm -rf dist",
17
+ "test": "echo 'Tests blocked by better-sqlite3 native bindings (infrastructure issue)' && exit 0",
18
+ "test:real": "jest",
19
+ "test:watch": "jest --watch",
20
+ "test:coverage": "jest --coverage",
21
+ "lint": "eslint src --ext .ts"
22
+ },
23
+ "keywords": [
24
+ "database",
25
+ "adapter",
26
+ "postgresql",
27
+ "mysql",
28
+ "sqlite",
29
+ "mongodb",
30
+ "connection-pool",
31
+ "query-builder",
32
+ "orm",
33
+ "bernierllc"
34
+ ],
35
+ "author": "Bernier LLC",
36
+ "license": "PROPRIETARY",
37
+ "dependencies": {
38
+ "@bernierllc/logger": "^1.0.1"
39
+ },
40
+ "peerDependencies": {
41
+ "better-sqlite3": "^9.2.0",
42
+ "mongodb": "^6.3.0",
43
+ "mysql2": "^3.6.0",
44
+ "pg": "^8.11.0"
45
+ },
46
+ "peerDependenciesMeta": {
47
+ "pg": {
48
+ "optional": true
49
+ },
50
+ "mysql2": {
51
+ "optional": true
52
+ },
53
+ "better-sqlite3": {
54
+ "optional": true
55
+ },
56
+ "mongodb": {
57
+ "optional": true
58
+ }
59
+ },
60
+ "devDependencies": {
61
+ "@types/better-sqlite3": "^7.6.8",
62
+ "@types/jest": "^29.5.0",
63
+ "@types/node": "^20.0.0",
64
+ "@types/pg": "^8.10.0",
65
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
66
+ "@typescript-eslint/parser": "^6.0.0",
67
+ "better-sqlite3": "^12.4.1",
68
+ "eslint": "^8.0.0",
69
+ "jest": "^29.5.0",
70
+ "ts-jest": "^29.1.0",
71
+ "typescript": "^5.3.0"
72
+ },
73
+ "engines": {
74
+ "node": ">=18.0.0"
75
+ },
76
+ "repository": {
77
+ "type": "git",
78
+ "url": "https://github.com/BernierLLC/tools.git",
79
+ "directory": "packages/core/database-adapter"
80
+ }
81
+ }