nanodb-orm 0.0.2 → 0.0.3

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.
Files changed (41) hide show
  1. package/README.md +71 -2
  2. package/dist/core/connection.d.ts +14 -2
  3. package/dist/core/connection.d.ts.map +1 -1
  4. package/dist/core/connection.js +36 -4
  5. package/dist/core/connection.js.map +1 -1
  6. package/dist/types/database.d.ts +74 -0
  7. package/dist/types/database.d.ts.map +1 -0
  8. package/dist/types/database.js +6 -0
  9. package/dist/types/database.js.map +1 -0
  10. package/dist/types/index.d.ts +1 -0
  11. package/dist/types/index.d.ts.map +1 -1
  12. package/dist/types/index.js +1 -0
  13. package/dist/types/index.js.map +1 -1
  14. package/dist/utils/error-handler.d.ts +36 -0
  15. package/dist/utils/error-handler.d.ts.map +1 -0
  16. package/dist/utils/error-handler.js +93 -0
  17. package/dist/utils/error-handler.js.map +1 -0
  18. package/dist/utils/index.d.ts +2 -0
  19. package/dist/utils/index.d.ts.map +1 -1
  20. package/dist/utils/index.js +5 -1
  21. package/dist/utils/index.js.map +1 -1
  22. package/dist/utils/migrations.d.ts.map +1 -1
  23. package/dist/utils/migrations.js +63 -46
  24. package/dist/utils/migrations.js.map +1 -1
  25. package/dist/utils/schema-introspection.d.ts +2 -6
  26. package/dist/utils/schema-introspection.d.ts.map +1 -1
  27. package/dist/utils/schema-introspection.js +7 -4
  28. package/dist/utils/schema-introspection.js.map +1 -1
  29. package/dist/utils/seeds.d.ts.map +1 -1
  30. package/dist/utils/seeds.js +6 -3
  31. package/dist/utils/seeds.js.map +1 -1
  32. package/dist/utils/sync.d.ts +3 -16
  33. package/dist/utils/sync.d.ts.map +1 -1
  34. package/dist/utils/sync.js +9 -8
  35. package/dist/utils/sync.js.map +1 -1
  36. package/dist/utils/transactions.d.ts +55 -0
  37. package/dist/utils/transactions.d.ts.map +1 -0
  38. package/dist/utils/transactions.js +159 -0
  39. package/dist/utils/transactions.js.map +1 -0
  40. package/llm.txt +72 -4
  41. package/package.json +1 -1
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Transaction utilities for atomic database operations
3
+ */
4
+ import { DatabaseClient } from '../types/database';
5
+ export interface TransactionOptions {
6
+ isolationLevel?: 'READ_UNCOMMITTED' | 'READ_COMMITTED' | 'REPEATABLE_READ' | 'SERIALIZABLE';
7
+ timeout?: number;
8
+ }
9
+ export interface TransactionResult<T> {
10
+ success: boolean;
11
+ result?: T;
12
+ error?: Error;
13
+ rollbackError?: Error;
14
+ }
15
+ /**
16
+ * Transaction management utilities
17
+ */
18
+ export declare class TransactionManager {
19
+ /**
20
+ * Execute a function within a database transaction
21
+ */
22
+ static execute<T>(operation: (db: DatabaseClient) => Promise<T>, options?: TransactionOptions): Promise<TransactionResult<T>>;
23
+ /**
24
+ * Execute multiple operations in a single transaction
25
+ */
26
+ static executeBatch<T>(operations: Array<(db: DatabaseClient) => Promise<T>>, options?: TransactionOptions): Promise<TransactionResult<T[]>>;
27
+ /**
28
+ * Execute a migration operation with transaction support
29
+ */
30
+ static executeMigration(migrationOperation: (db: DatabaseClient) => Promise<void>, options?: TransactionOptions): Promise<TransactionResult<void>>;
31
+ /**
32
+ * Execute table recreation with transaction support
33
+ */
34
+ static recreateTable(tableName: string, createOperation: (db: DatabaseClient) => Promise<void>, options?: TransactionOptions): Promise<TransactionResult<void>>;
35
+ /**
36
+ * Execute data seeding with transaction support
37
+ */
38
+ static seedData(seedOperation: (db: DatabaseClient) => Promise<void>, options?: TransactionOptions): Promise<TransactionResult<void>>;
39
+ /**
40
+ * Execute database reset with transaction support
41
+ */
42
+ static resetDatabase(resetOperation: (db: DatabaseClient) => Promise<void>, options?: TransactionOptions): Promise<TransactionResult<void>>;
43
+ /**
44
+ * Check if the database supports transactions
45
+ */
46
+ static supportsTransactions(): Promise<boolean>;
47
+ /**
48
+ * Get transaction status
49
+ */
50
+ static getTransactionStatus(): Promise<{
51
+ inTransaction: boolean;
52
+ supportsTransactions: boolean;
53
+ }>;
54
+ }
55
+ //# sourceMappingURL=transactions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactions.d.ts","sourceRoot":"","sources":["../../utils/transactions.ts"],"names":[],"mappings":"AAAA;;GAEG;AAMH,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAEnD,MAAM,WAAW,kBAAkB;IACjC,cAAc,CAAC,EAAE,kBAAkB,GAAG,gBAAgB,GAAG,iBAAiB,GAAG,cAAc,CAAC;IAC5F,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC;IAClC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,CAAC,EAAE,CAAC,CAAC;IACX,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,aAAa,CAAC,EAAE,KAAK,CAAC;CACvB;AAED;;GAEG;AACH,qBAAa,kBAAkB;IAC7B;;OAEG;WACU,OAAO,CAAC,CAAC,EACpB,SAAS,EAAE,CAAC,EAAE,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,EAC7C,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC;IAgDhC;;OAEG;WACU,YAAY,CAAC,CAAC,EACzB,UAAU,EAAE,KAAK,CAAC,CAAC,EAAE,EAAE,cAAc,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC,EACrD,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC,CAAC,EAAE,CAAC,CAAC;IAalC;;OAEG;WACU,gBAAgB,CAC3B,kBAAkB,EAAE,CAAC,EAAE,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,EACzD,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAQnC;;OAEG;WACU,aAAa,CACxB,SAAS,EAAE,MAAM,EACjB,eAAe,EAAE,CAAC,EAAE,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,EACtD,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAgBnC;;OAEG;WACU,QAAQ,CACnB,aAAa,EAAE,CAAC,EAAE,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,EACpD,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAQnC;;OAEG;WACU,aAAa,CACxB,cAAc,EAAE,CAAC,EAAE,EAAE,cAAc,KAAK,OAAO,CAAC,IAAI,CAAC,EACrD,OAAO,GAAE,kBAAuB,GAC/B,OAAO,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAC;IAQnC;;OAEG;WACU,oBAAoB,IAAI,OAAO,CAAC,OAAO,CAAC;IAgBrD;;OAEG;WACU,oBAAoB,IAAI,OAAO,CAAC;QAC3C,aAAa,EAAE,OAAO,CAAC;QACvB,oBAAoB,EAAE,OAAO,CAAC;KAC/B,CAAC;CAuBH"}
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+ /**
3
+ * Transaction utilities for atomic database operations
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TransactionManager = void 0;
7
+ const connection_1 = require("../core/connection");
8
+ const logger_1 = require("./logger");
9
+ const error_handler_1 = require("./error-handler");
10
+ /**
11
+ * Transaction management utilities
12
+ */
13
+ class TransactionManager {
14
+ /**
15
+ * Execute a function within a database transaction
16
+ */
17
+ static async execute(operation, options = {}) {
18
+ const db = await connection_1.DatabaseConnection.getInstance();
19
+ const client = db;
20
+ try {
21
+ logger_1.logger.debug('Starting database transaction');
22
+ // Begin transaction
23
+ await client.run('BEGIN TRANSACTION');
24
+ // Set isolation level if specified
25
+ if (options.isolationLevel) {
26
+ await client.run(`SET TRANSACTION ISOLATION LEVEL ${options.isolationLevel}`);
27
+ }
28
+ // Execute the operation
29
+ const result = await operation(client);
30
+ // Commit transaction
31
+ await client.run('COMMIT');
32
+ logger_1.logger.debug('Transaction committed successfully');
33
+ return {
34
+ success: true,
35
+ result
36
+ };
37
+ }
38
+ catch (error) {
39
+ logger_1.logger.error('Transaction failed, attempting rollback:', error);
40
+ try {
41
+ await client.run('ROLLBACK');
42
+ logger_1.logger.debug('Transaction rolled back successfully');
43
+ }
44
+ catch (rollbackError) {
45
+ logger_1.logger.error('Failed to rollback transaction:', rollbackError);
46
+ return {
47
+ success: false,
48
+ error: error instanceof Error ? error : new Error(String(error)),
49
+ rollbackError: rollbackError instanceof Error ? rollbackError : new Error(String(rollbackError))
50
+ };
51
+ }
52
+ return {
53
+ success: false,
54
+ error: error instanceof Error ? error : new Error(String(error))
55
+ };
56
+ }
57
+ }
58
+ /**
59
+ * Execute multiple operations in a single transaction
60
+ */
61
+ static async executeBatch(operations, options = {}) {
62
+ return this.execute(async (db) => {
63
+ const results = [];
64
+ for (const operation of operations) {
65
+ const result = await operation(db);
66
+ results.push(result);
67
+ }
68
+ return results;
69
+ }, options);
70
+ }
71
+ /**
72
+ * Execute a migration operation with transaction support
73
+ */
74
+ static async executeMigration(migrationOperation, options = {}) {
75
+ return this.execute(async (db) => {
76
+ logger_1.logger.info('Executing migration within transaction');
77
+ await migrationOperation(db);
78
+ logger_1.logger.info('Migration completed successfully');
79
+ }, options);
80
+ }
81
+ /**
82
+ * Execute table recreation with transaction support
83
+ */
84
+ static async recreateTable(tableName, createOperation, options = {}) {
85
+ return this.execute(async (db) => {
86
+ logger_1.logger.info(`Recreating table ${tableName} within transaction`);
87
+ // Drop table if exists
88
+ await db.run(`DROP TABLE IF EXISTS ${tableName}`);
89
+ logger_1.logger.debug(`Dropped table ${tableName}`);
90
+ // Create new table
91
+ await createOperation(db);
92
+ logger_1.logger.debug(`Created table ${tableName}`);
93
+ logger_1.logger.info(`Table ${tableName} recreated successfully`);
94
+ }, options);
95
+ }
96
+ /**
97
+ * Execute data seeding with transaction support
98
+ */
99
+ static async seedData(seedOperation, options = {}) {
100
+ return this.execute(async (db) => {
101
+ logger_1.logger.info('Seeding data within transaction');
102
+ await seedOperation(db);
103
+ logger_1.logger.info('Data seeding completed successfully');
104
+ }, options);
105
+ }
106
+ /**
107
+ * Execute database reset with transaction support
108
+ */
109
+ static async resetDatabase(resetOperation, options = {}) {
110
+ return this.execute(async (db) => {
111
+ logger_1.logger.warn('Resetting database within transaction');
112
+ await resetOperation(db);
113
+ logger_1.logger.info('Database reset completed successfully');
114
+ }, options);
115
+ }
116
+ /**
117
+ * Check if the database supports transactions
118
+ */
119
+ static async supportsTransactions() {
120
+ try {
121
+ const db = await connection_1.DatabaseConnection.getInstance();
122
+ const client = db;
123
+ // Try to start a transaction
124
+ await client.run('BEGIN TRANSACTION');
125
+ await client.run('ROLLBACK');
126
+ return true;
127
+ }
128
+ catch (error) {
129
+ error_handler_1.ErrorHandler.handleOptionalError(error, 'check-transaction-support', 'Database does not support transactions');
130
+ return false;
131
+ }
132
+ }
133
+ /**
134
+ * Get transaction status
135
+ */
136
+ static async getTransactionStatus() {
137
+ try {
138
+ const db = await connection_1.DatabaseConnection.getInstance();
139
+ const client = db;
140
+ // Check if we're in a transaction
141
+ const result = await client.run('SELECT * FROM pragma_transaction_state');
142
+ const inTransaction = result.rows.length > 0 && result.rows[0].state === 'active';
143
+ const supportsTransactions = await this.supportsTransactions();
144
+ return {
145
+ inTransaction,
146
+ supportsTransactions
147
+ };
148
+ }
149
+ catch (error) {
150
+ error_handler_1.ErrorHandler.handleNonThrowingError(error, 'get-transaction-status', 'Failed to get transaction status');
151
+ return {
152
+ inTransaction: false,
153
+ supportsTransactions: false
154
+ };
155
+ }
156
+ }
157
+ }
158
+ exports.TransactionManager = TransactionManager;
159
+ //# sourceMappingURL=transactions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transactions.js","sourceRoot":"","sources":["../../utils/transactions.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,mDAAwD;AACxD,qCAAkC;AAElC,mDAA+C;AAe/C;;GAEG;AAC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 +5,7 @@ nanodb-orm is a generic, flexible database package built on top of Drizzle ORM.
5
5
 
6
6
  ## Package Information
7
7
  - **Name**: nanodb-orm
8
- - **Version**: 0.0.2
8
+ - **Version**: 0.0.3
9
9
  - **License**: MIT
10
10
  - **Repository**: https://github.com/damilolaalao/nanodb-orm
11
11
  - **NPM**: https://www.npmjs.com/package/nanodb-orm
@@ -20,9 +20,13 @@ npm install nanodb-orm
20
20
  2. **Auto-Migrations**: Automatic schema creation and migration handling
21
21
  3. **Schema Introspection**: Dynamic schema analysis and validation
22
22
  4. **Multi-Database Support**: SQLite (local) and Turso (cloud) databases
23
- 5. **TypeScript Support**: Full TypeScript definitions and type safety
24
- 6. **Data Seeding**: Built-in seed data management
25
- 7. **Health Checks**: Database health monitoring and validation
23
+ 5. **Atomic Transactions**: Full transaction support with rollback protection
24
+ 6. **TypeScript Support**: Full TypeScript definitions and type safety
25
+ 7. **Data Seeding**: Built-in seed data management
26
+ 8. **Health Checks**: Database health monitoring and validation
27
+ 9. **Thread Safety**: Race condition fixes and concurrent access protection
28
+ 10. **Security**: SQL injection protection and input validation
29
+ 11. **Error Handling**: Standardized error handling and recovery
26
30
 
27
31
  ## Main Exports
28
32
  ```typescript
@@ -33,6 +37,8 @@ import {
33
37
  DatabaseMigrations, // Migration management
34
38
  DatabaseSeeds, // Seed data management
35
39
  DatabaseConnection, // Database connection management
40
+ TransactionManager, // NEW: Transaction management
41
+ ErrorHandler, // NEW: Standardized error handling
36
42
  logger // Logging utilities
37
43
  } from 'nanodb-orm';
38
44
  ```
@@ -139,6 +145,68 @@ The package automatically detects the environment and uses:
139
145
  - `seedDatabase()`: Seed database with sample data
140
146
  - `hasData()`: Check if database has existing data
141
147
 
148
+ ## NEW in v0.0.3: Transaction Support
149
+
150
+ ### TransactionManager
151
+ ```typescript
152
+ import { TransactionManager } from 'nanodb-orm';
153
+
154
+ // Atomic operations
155
+ await TransactionManager.execute(async (db) => {
156
+ await db.run('INSERT INTO users (name, email) VALUES (?, ?)', ['John', 'john@example.com']);
157
+ await db.run('INSERT INTO posts (title, content, userId) VALUES (?, ?, ?)', ['Hello', 'World', 1]);
158
+ // All operations succeed or all fail
159
+ });
160
+
161
+ // Batch operations
162
+ await TransactionManager.executeBatch([
163
+ async (db) => await db.run('INSERT INTO users ...'),
164
+ async (db) => await db.run('INSERT INTO posts ...')
165
+ ]);
166
+
167
+ // Table recreation with transactions
168
+ await TransactionManager.recreateTable('users', async (db) => {
169
+ await db.run('CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)');
170
+ });
171
+
172
+ // Check transaction support
173
+ const supportsTransactions = await TransactionManager.supportsTransactions();
174
+ const status = await TransactionManager.getTransactionStatus();
175
+ ```
176
+
177
+ ### Enhanced Error Handling
178
+ ```typescript
179
+ import { ErrorHandler, DatabaseError } from 'nanodb-orm';
180
+
181
+ // Standardized error handling
182
+ try {
183
+ await DatabaseSync.setup();
184
+ } catch (error) {
185
+ if (error instanceof DatabaseError) {
186
+ console.log('Operation:', error.operation);
187
+ console.log('Context:', error.message);
188
+ }
189
+ }
190
+
191
+ // Non-throwing error handling
192
+ const result = ErrorHandler.handleNonThrowingError(
193
+ someError,
194
+ 'optional-operation',
195
+ 'This operation is optional'
196
+ );
197
+ ```
198
+
199
+ ### Thread-Safe Connections
200
+ ```typescript
201
+ import { DatabaseConnection } from 'nanodb-orm';
202
+
203
+ // NEW: Async connection (recommended)
204
+ const db = await DatabaseConnection.getInstance();
205
+
206
+ // OLD: Synchronous connection (deprecated but still works)
207
+ const db = DatabaseConnection.getInstanceSync();
208
+ ```
209
+
142
210
  ## Error Handling
143
211
  The package provides custom error classes:
144
212
  - `DatabaseError`: Base database error
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nanodb-orm",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
4
4
  "description": "Generic database package with Drizzle ORM, auto-migrations, and schema introspection",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",