nanodb-orm 0.0.3 → 0.0.4
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 +211 -378
- package/dist/cli.d.ts +13 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +270 -0
- package/dist/cli.js.map +1 -0
- package/dist/constants/index.d.ts +7 -54
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +9 -61
- package/dist/constants/index.js.map +1 -1
- package/dist/core/config.d.ts +3 -13
- package/dist/core/config.d.ts.map +1 -1
- package/dist/core/config.js +5 -27
- package/dist/core/config.js.map +1 -1
- package/dist/core/connection.d.ts +10 -31
- package/dist/core/connection.d.ts.map +1 -1
- package/dist/core/connection.js +28 -78
- package/dist/core/connection.js.map +1 -1
- package/dist/core/index.d.ts +2 -3
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +3 -18
- package/dist/core/index.js.map +1 -1
- package/dist/index.d.ts +40 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +76 -31
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +79 -22
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +246 -48
- package/dist/init.js.map +1 -1
- package/dist/jest.setup.d.ts +4 -0
- package/dist/jest.setup.d.ts.map +1 -0
- package/dist/jest.setup.js +40 -0
- package/dist/jest.setup.js.map +1 -0
- package/dist/types/errors.d.ts +30 -12
- package/dist/types/errors.d.ts.map +1 -1
- package/dist/types/errors.js +98 -23
- package/dist/types/errors.js.map +1 -1
- package/dist/types/index.d.ts +130 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -4
- package/dist/types/index.js.map +1 -1
- package/dist/utils/error-handler.d.ts +6 -31
- package/dist/utils/error-handler.d.ts.map +1 -1
- package/dist/utils/error-handler.js +24 -81
- package/dist/utils/error-handler.js.map +1 -1
- package/dist/utils/index.d.ts +1 -3
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +4 -6
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/logger.d.ts +6 -25
- package/dist/utils/logger.d.ts.map +1 -1
- package/dist/utils/logger.js +20 -38
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/migrations.d.ts +16 -90
- package/dist/utils/migrations.d.ts.map +1 -1
- package/dist/utils/migrations.js +216 -423
- package/dist/utils/migrations.js.map +1 -1
- package/dist/utils/schema-introspection.d.ts +30 -169
- package/dist/utils/schema-introspection.d.ts.map +1 -1
- package/dist/utils/schema-introspection.js +128 -462
- package/dist/utils/schema-introspection.js.map +1 -1
- package/dist/utils/seeds.d.ts +15 -48
- package/dist/utils/seeds.d.ts.map +1 -1
- package/dist/utils/seeds.js +101 -188
- package/dist/utils/seeds.js.map +1 -1
- package/dist/utils/sync.d.ts +16 -41
- package/dist/utils/sync.d.ts.map +1 -1
- package/dist/utils/sync.js +69 -172
- package/dist/utils/sync.js.map +1 -1
- package/dist/utils/transactions.d.ts +8 -47
- package/dist/utils/transactions.d.ts.map +1 -1
- package/dist/utils/transactions.js +32 -147
- package/dist/utils/transactions.js.map +1 -1
- package/package.json +29 -10
- package/dist/example.d.ts +0 -67
- package/dist/example.d.ts.map +0 -1
- package/dist/example.js +0 -86
- package/dist/example.js.map +0 -1
- package/dist/types/database.d.ts +0 -74
- package/dist/types/database.d.ts.map +0 -1
- package/dist/types/database.js +0 -6
- package/dist/types/database.js.map +0 -1
- package/dist/types/types.d.ts +0 -30
- package/dist/types/types.d.ts.map +0 -1
- package/dist/types/types.js +0 -6
- package/dist/types/types.js.map +0 -1
- package/llm.txt +0 -336
package/dist/core/connection.js
CHANGED
|
@@ -1,109 +1,59 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.DatabaseConnection = void 0;
|
|
4
4
|
const libsql_1 = require("drizzle-orm/libsql");
|
|
5
5
|
const client_1 = require("@libsql/client");
|
|
6
6
|
const config_1 = require("./config");
|
|
7
|
-
const errors_1 = require("../types/errors");
|
|
8
7
|
/**
|
|
9
|
-
*
|
|
10
|
-
*
|
|
8
|
+
* Thread-safe singleton database connection manager.
|
|
9
|
+
* Supports both Turso (remote) and local SQLite databases.
|
|
11
10
|
*/
|
|
12
11
|
class DatabaseConnection {
|
|
13
|
-
/**
|
|
14
|
-
* Get or create the database connection instance (thread-safe)
|
|
15
|
-
*/
|
|
12
|
+
/** Get the database connection instance (creates if needed) */
|
|
16
13
|
static async getInstance() {
|
|
17
|
-
if (this.instance)
|
|
14
|
+
if (this.instance)
|
|
18
15
|
return this.instance;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
this.isCreating = true;
|
|
24
|
-
this.creationPromise = this.createConnectionAsync();
|
|
16
|
+
if (this.pending)
|
|
17
|
+
return this.pending;
|
|
18
|
+
this.pending = this.createConnection();
|
|
25
19
|
try {
|
|
26
|
-
this.instance = await this.
|
|
20
|
+
this.instance = await this.pending;
|
|
27
21
|
return this.instance;
|
|
28
22
|
}
|
|
29
23
|
finally {
|
|
30
|
-
this.
|
|
31
|
-
this.creationPromise = null;
|
|
24
|
+
this.pending = null;
|
|
32
25
|
}
|
|
33
26
|
}
|
|
34
|
-
/**
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
this.instance = this.createConnection();
|
|
27
|
+
/** Create a new database connection */
|
|
28
|
+
static async createConnection() {
|
|
29
|
+
// Test environment: use isolated local database
|
|
30
|
+
if (process.env.NODE_ENV === 'test' || process.env.FORCE_LOCAL_DB === 'true') {
|
|
31
|
+
const dbName = process.env.JEST_WORKER_ID ? `test-${process.env.JEST_WORKER_ID}.db` : 'test.db';
|
|
32
|
+
return (0, libsql_1.drizzle)((0, client_1.createClient)({ url: `file:${dbName}` }));
|
|
41
33
|
}
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
/**
|
|
45
|
-
* Create a new database connection asynchronously
|
|
46
|
-
*/
|
|
47
|
-
static async createConnectionAsync() {
|
|
48
|
-
return this.createConnection();
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Create a new database connection
|
|
52
|
-
*/
|
|
53
|
-
static createConnection() {
|
|
34
|
+
// Production: try Turso first, fallback to local SQLite
|
|
54
35
|
try {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
const client = (0, client_1.createClient)({
|
|
61
|
-
url: `file:${testDbName}`,
|
|
62
|
-
});
|
|
63
|
-
return (0, libsql_1.drizzle)(client);
|
|
64
|
-
}
|
|
65
|
-
// Try to get Turso config first, fallback to local SQLite if not available
|
|
66
|
-
try {
|
|
67
|
-
const config = (0, config_1.getDatabaseConfig)();
|
|
68
|
-
const client = (0, client_1.createClient)({
|
|
69
|
-
url: config.connectionUrl,
|
|
70
|
-
authToken: config.authToken,
|
|
71
|
-
});
|
|
72
|
-
console.log('Connected to Turso database');
|
|
73
|
-
return (0, libsql_1.drizzle)(client);
|
|
74
|
-
}
|
|
75
|
-
catch (configError) {
|
|
76
|
-
// Fallback to local SQLite database
|
|
77
|
-
console.log('Turso config not found, using local SQLite database');
|
|
78
|
-
const client = (0, client_1.createClient)({
|
|
79
|
-
url: 'file:database.db',
|
|
80
|
-
});
|
|
81
|
-
return (0, libsql_1.drizzle)(client);
|
|
82
|
-
}
|
|
36
|
+
const config = (0, config_1.getDatabaseConfig)();
|
|
37
|
+
return (0, libsql_1.drizzle)((0, client_1.createClient)({
|
|
38
|
+
url: config.connectionUrl,
|
|
39
|
+
authToken: config.authToken,
|
|
40
|
+
}));
|
|
83
41
|
}
|
|
84
|
-
catch
|
|
85
|
-
|
|
42
|
+
catch {
|
|
43
|
+
return (0, libsql_1.drizzle)((0, client_1.createClient)({ url: 'file:database.db' }));
|
|
86
44
|
}
|
|
87
45
|
}
|
|
88
|
-
/**
|
|
89
|
-
* Reset the connection instance (useful for testing)
|
|
90
|
-
*/
|
|
46
|
+
/** Reset the connection (for testing) */
|
|
91
47
|
static reset() {
|
|
92
48
|
this.instance = null;
|
|
93
|
-
this.
|
|
94
|
-
this.creationPromise = null;
|
|
49
|
+
this.pending = null;
|
|
95
50
|
}
|
|
96
|
-
/**
|
|
97
|
-
* Check if connection is established
|
|
98
|
-
*/
|
|
51
|
+
/** Check if a connection exists */
|
|
99
52
|
static isConnected() {
|
|
100
53
|
return this.instance !== null;
|
|
101
54
|
}
|
|
102
55
|
}
|
|
103
56
|
exports.DatabaseConnection = DatabaseConnection;
|
|
104
57
|
DatabaseConnection.instance = null;
|
|
105
|
-
DatabaseConnection.
|
|
106
|
-
DatabaseConnection.creationPromise = null;
|
|
107
|
-
// Export the database instance for convenience (deprecated - use getInstance() instead)
|
|
108
|
-
exports.db = DatabaseConnection.getInstanceSync();
|
|
58
|
+
DatabaseConnection.pending = null;
|
|
109
59
|
//# sourceMappingURL=connection.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../core/connection.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAC7C,2CAA8C;AAC9C,qCAA6C;
|
|
1
|
+
{"version":3,"file":"connection.js","sourceRoot":"","sources":["../../core/connection.ts"],"names":[],"mappings":";;;AAAA,+CAA6C;AAC7C,2CAA8C;AAC9C,qCAA6C;AAK7C;;;GAGG;AACH,MAAa,kBAAkB;IAI7B,+DAA+D;IAC/D,MAAM,CAAC,KAAK,CAAC,WAAW;QACtB,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO,IAAI,CAAC,QAAQ,CAAC;QACxC,IAAI,IAAI,CAAC,OAAO;YAAE,OAAO,IAAI,CAAC,OAAO,CAAC;QAEtC,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAEvC,IAAI,CAAC;YACH,IAAI,CAAC,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAAC;YACnC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B,IAAI,CAAC;AACxC,0BAAO,GAAoC,IAAI,CAAC"}
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Core database functionality
|
|
3
|
-
* Essential database components: connection, schema, and configuration
|
|
4
3
|
*/
|
|
5
|
-
export {
|
|
6
|
-
export
|
|
4
|
+
export { DatabaseConnection } from './connection';
|
|
5
|
+
export { getDatabaseConfig } from './config';
|
|
7
6
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/core/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../core/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../core/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC"}
|
package/dist/core/index.js
CHANGED
|
@@ -1,26 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
3
|
* Core database functionality
|
|
4
|
-
* Essential database components: connection, schema, and configuration
|
|
5
4
|
*/
|
|
6
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
7
|
-
if (k2 === undefined) k2 = k;
|
|
8
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
9
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
10
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
11
|
-
}
|
|
12
|
-
Object.defineProperty(o, k2, desc);
|
|
13
|
-
}) : (function(o, m, k, k2) {
|
|
14
|
-
if (k2 === undefined) k2 = k;
|
|
15
|
-
o[k2] = m[k];
|
|
16
|
-
}));
|
|
17
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
18
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
19
|
-
};
|
|
20
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.
|
|
6
|
+
exports.getDatabaseConfig = exports.DatabaseConnection = void 0;
|
|
22
7
|
var connection_1 = require("./connection");
|
|
23
|
-
Object.defineProperty(exports, "db", { enumerable: true, get: function () { return connection_1.db; } });
|
|
24
8
|
Object.defineProperty(exports, "DatabaseConnection", { enumerable: true, get: function () { return connection_1.DatabaseConnection; } });
|
|
25
|
-
|
|
9
|
+
var config_1 = require("./config");
|
|
10
|
+
Object.defineProperty(exports, "getDatabaseConfig", { enumerable: true, get: function () { return config_1.getDatabaseConfig; } });
|
|
26
11
|
//# sourceMappingURL=index.js.map
|
package/dist/core/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../core/index.ts"],"names":[],"mappings":";AAAA;;;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../core/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2CAAkD;AAAzC,gHAAA,kBAAkB,OAAA;AAC3B,mCAA6C;AAApC,2GAAA,iBAAiB,OAAA"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,14 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Main entry point for all database-related functionality
|
|
2
|
+
* nanodb-orm - A lightweight ORM wrapper for Drizzle + SQLite/Turso
|
|
4
3
|
*
|
|
5
|
-
* @
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* import { createDatabase, table, integer, text, eq } from 'nanodb-orm';
|
|
7
|
+
*
|
|
8
|
+
* const users = table('users', {
|
|
9
|
+
* id: integer('id').primaryKey({ autoIncrement: true }),
|
|
10
|
+
* name: text('name').notNull(),
|
|
11
|
+
* });
|
|
12
|
+
*
|
|
13
|
+
* const db = await createDatabase({ tables: { users } });
|
|
14
|
+
* const allUsers = await db.select().from(users);
|
|
15
|
+
* ```
|
|
8
16
|
*/
|
|
9
|
-
export
|
|
10
|
-
export
|
|
11
|
-
export
|
|
12
|
-
export { DatabaseError, SchemaError,
|
|
13
|
-
export
|
|
17
|
+
export { createDatabase, initializeDatabase } from './init';
|
|
18
|
+
export type { CreateDatabaseConfig } from './init';
|
|
19
|
+
export type { NanoPlugin, HookFn, ErrorHookFn, LifecycleHookFn, SchemaData, MigrationConfig, DrizzleTable, DrizzleColumn, DatabaseClient, DatabaseConfig, DatabaseInfo, HealthCheck, SyncResult, SchemaValidation, ForeignKey, TableMetadata, QueryResult, } from './types';
|
|
20
|
+
export { DatabaseError, SchemaError, ConnectionError, MigrationError, SeedError, parseDbError, } from './types/errors';
|
|
21
|
+
export { DatabaseConnection } from './core/connection';
|
|
22
|
+
export { getDatabaseConfig } from './core/config';
|
|
23
|
+
export { DatabaseSync } from './utils/sync';
|
|
24
|
+
export { DatabaseMigrations } from './utils/migrations';
|
|
25
|
+
export { DatabaseSeeds } from './utils/seeds';
|
|
26
|
+
export { SchemaIntrospection } from './utils/schema-introspection';
|
|
27
|
+
export { transaction, recreateTable } from './utils/transactions';
|
|
28
|
+
import { sqliteTable, integer as drizzleInteger, text as drizzleText, real as drizzleReal, blob as drizzleBlob } from 'drizzle-orm/sqlite-core';
|
|
29
|
+
/** Define a SQLite table */
|
|
30
|
+
export declare const table: import("drizzle-orm/sqlite-core").SQLiteTableFn<undefined>;
|
|
31
|
+
export { sqliteTable };
|
|
32
|
+
/** Column type builders */
|
|
33
|
+
export declare const integer: typeof drizzleInteger;
|
|
34
|
+
export declare const text: typeof drizzleText;
|
|
35
|
+
export declare const real: typeof drizzleReal;
|
|
36
|
+
export declare const blob: typeof drizzleBlob;
|
|
37
|
+
export declare const column: {
|
|
38
|
+
integer: typeof drizzleInteger;
|
|
39
|
+
text: typeof drizzleText;
|
|
40
|
+
real: typeof drizzleReal;
|
|
41
|
+
blob: typeof drizzleBlob;
|
|
42
|
+
};
|
|
43
|
+
export { eq, ne, gt, gte, lt, lte, like, and, or, not, desc, asc, count, sql, } from 'drizzle-orm';
|
|
14
44
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAMH,OAAO,EAAE,cAAc,EAAE,kBAAkB,EAAE,MAAM,QAAQ,CAAC;AAC5D,YAAY,EAAE,oBAAoB,EAAE,MAAM,QAAQ,CAAC;AAMnD,YAAY,EAEV,UAAU,EACV,MAAM,EACN,WAAW,EACX,eAAe,EAGf,UAAU,EACV,eAAe,EACf,YAAY,EACZ,aAAa,EAGb,cAAc,EACd,cAAc,EACd,YAAY,EACZ,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,UAAU,EACV,aAAa,EACb,WAAW,GACZ,MAAM,SAAS,CAAC;AAMjB,OAAO,EACL,aAAa,EACb,WAAW,EACX,eAAe,EACf,cAAc,EACd,SAAS,EACT,YAAY,GACb,MAAM,gBAAgB,CAAC;AAMxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAMlE,OAAO,EACL,WAAW,EACX,OAAO,IAAI,cAAc,EACzB,IAAI,IAAI,WAAW,EACnB,IAAI,IAAI,WAAW,EACnB,IAAI,IAAI,WAAW,EACpB,MAAM,yBAAyB,CAAC;AAEjC,4BAA4B;AAC5B,eAAO,MAAM,KAAK,4DAAc,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,CAAC;AAEvB,2BAA2B;AAC3B,eAAO,MAAM,OAAO,uBAAiB,CAAC;AACtC,eAAO,MAAM,IAAI,oBAAc,CAAC;AAChC,eAAO,MAAM,IAAI,oBAAc,CAAC;AAChC,eAAO,MAAM,IAAI,oBAAc,CAAC;AAGhC,eAAO,MAAM,MAAM;;;;;CAAuF,CAAC;AAM3G,OAAO,EACL,EAAE,EAAE,EAAE,EAAE,EAAE,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,EAAE,IAAI,EAC9B,GAAG,EAAE,EAAE,EAAE,GAAG,EACZ,IAAI,EAAE,GAAG,EACT,KAAK,EAAE,GAAG,GACX,MAAM,aAAa,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,41 +1,86 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
* Main entry point for all database-related functionality
|
|
3
|
+
* nanodb-orm - A lightweight ORM wrapper for Drizzle + SQLite/Turso
|
|
5
4
|
*
|
|
6
|
-
* @
|
|
7
|
-
*
|
|
8
|
-
*
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* import { createDatabase, table, integer, text, eq } from 'nanodb-orm';
|
|
8
|
+
*
|
|
9
|
+
* const users = table('users', {
|
|
10
|
+
* id: integer('id').primaryKey({ autoIncrement: true }),
|
|
11
|
+
* name: text('name').notNull(),
|
|
12
|
+
* });
|
|
13
|
+
*
|
|
14
|
+
* const db = await createDatabase({ tables: { users } });
|
|
15
|
+
* const allUsers = await db.select().from(users);
|
|
16
|
+
* ```
|
|
9
17
|
*/
|
|
10
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
-
if (k2 === undefined) k2 = k;
|
|
12
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
15
|
-
}
|
|
16
|
-
Object.defineProperty(o, k2, desc);
|
|
17
|
-
}) : (function(o, m, k, k2) {
|
|
18
|
-
if (k2 === undefined) k2 = k;
|
|
19
|
-
o[k2] = m[k];
|
|
20
|
-
}));
|
|
21
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
-
};
|
|
24
18
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.
|
|
26
|
-
//
|
|
27
|
-
|
|
28
|
-
//
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
//
|
|
19
|
+
exports.sql = exports.count = exports.asc = exports.desc = exports.not = exports.or = exports.and = exports.like = exports.lte = exports.lt = exports.gte = exports.gt = exports.ne = exports.eq = exports.column = exports.blob = exports.real = exports.text = exports.integer = exports.sqliteTable = exports.table = exports.recreateTable = exports.transaction = exports.SchemaIntrospection = exports.DatabaseSeeds = exports.DatabaseMigrations = exports.DatabaseSync = exports.getDatabaseConfig = exports.DatabaseConnection = exports.parseDbError = exports.SeedError = exports.MigrationError = exports.ConnectionError = exports.SchemaError = exports.DatabaseError = exports.initializeDatabase = exports.createDatabase = void 0;
|
|
20
|
+
// -----------------------------------------------------------------------------
|
|
21
|
+
// Main API
|
|
22
|
+
// -----------------------------------------------------------------------------
|
|
23
|
+
var init_1 = require("./init");
|
|
24
|
+
Object.defineProperty(exports, "createDatabase", { enumerable: true, get: function () { return init_1.createDatabase; } });
|
|
25
|
+
Object.defineProperty(exports, "initializeDatabase", { enumerable: true, get: function () { return init_1.initializeDatabase; } });
|
|
26
|
+
// -----------------------------------------------------------------------------
|
|
27
|
+
// Errors
|
|
28
|
+
// -----------------------------------------------------------------------------
|
|
33
29
|
var errors_1 = require("./types/errors");
|
|
34
30
|
Object.defineProperty(exports, "DatabaseError", { enumerable: true, get: function () { return errors_1.DatabaseError; } });
|
|
35
31
|
Object.defineProperty(exports, "SchemaError", { enumerable: true, get: function () { return errors_1.SchemaError; } });
|
|
36
|
-
Object.defineProperty(exports, "SyncError", { enumerable: true, get: function () { return errors_1.SyncError; } });
|
|
37
32
|
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return errors_1.ConnectionError; } });
|
|
38
|
-
Object.defineProperty(exports, "
|
|
39
|
-
|
|
40
|
-
|
|
33
|
+
Object.defineProperty(exports, "MigrationError", { enumerable: true, get: function () { return errors_1.MigrationError; } });
|
|
34
|
+
Object.defineProperty(exports, "SeedError", { enumerable: true, get: function () { return errors_1.SeedError; } });
|
|
35
|
+
Object.defineProperty(exports, "parseDbError", { enumerable: true, get: function () { return errors_1.parseDbError; } });
|
|
36
|
+
// -----------------------------------------------------------------------------
|
|
37
|
+
// Utilities (for advanced use)
|
|
38
|
+
// -----------------------------------------------------------------------------
|
|
39
|
+
var connection_1 = require("./core/connection");
|
|
40
|
+
Object.defineProperty(exports, "DatabaseConnection", { enumerable: true, get: function () { return connection_1.DatabaseConnection; } });
|
|
41
|
+
var config_1 = require("./core/config");
|
|
42
|
+
Object.defineProperty(exports, "getDatabaseConfig", { enumerable: true, get: function () { return config_1.getDatabaseConfig; } });
|
|
43
|
+
var sync_1 = require("./utils/sync");
|
|
44
|
+
Object.defineProperty(exports, "DatabaseSync", { enumerable: true, get: function () { return sync_1.DatabaseSync; } });
|
|
45
|
+
var migrations_1 = require("./utils/migrations");
|
|
46
|
+
Object.defineProperty(exports, "DatabaseMigrations", { enumerable: true, get: function () { return migrations_1.DatabaseMigrations; } });
|
|
47
|
+
var seeds_1 = require("./utils/seeds");
|
|
48
|
+
Object.defineProperty(exports, "DatabaseSeeds", { enumerable: true, get: function () { return seeds_1.DatabaseSeeds; } });
|
|
49
|
+
var schema_introspection_1 = require("./utils/schema-introspection");
|
|
50
|
+
Object.defineProperty(exports, "SchemaIntrospection", { enumerable: true, get: function () { return schema_introspection_1.SchemaIntrospection; } });
|
|
51
|
+
var transactions_1 = require("./utils/transactions");
|
|
52
|
+
Object.defineProperty(exports, "transaction", { enumerable: true, get: function () { return transactions_1.transaction; } });
|
|
53
|
+
Object.defineProperty(exports, "recreateTable", { enumerable: true, get: function () { return transactions_1.recreateTable; } });
|
|
54
|
+
// -----------------------------------------------------------------------------
|
|
55
|
+
// Drizzle Re-exports (Schema Building)
|
|
56
|
+
// -----------------------------------------------------------------------------
|
|
57
|
+
const sqlite_core_1 = require("drizzle-orm/sqlite-core");
|
|
58
|
+
Object.defineProperty(exports, "sqliteTable", { enumerable: true, get: function () { return sqlite_core_1.sqliteTable; } });
|
|
59
|
+
/** Define a SQLite table */
|
|
60
|
+
exports.table = sqlite_core_1.sqliteTable;
|
|
61
|
+
/** Column type builders */
|
|
62
|
+
exports.integer = sqlite_core_1.integer;
|
|
63
|
+
exports.text = sqlite_core_1.text;
|
|
64
|
+
exports.real = sqlite_core_1.real;
|
|
65
|
+
exports.blob = sqlite_core_1.blob;
|
|
66
|
+
// Grouped column export for convenience
|
|
67
|
+
exports.column = { integer: sqlite_core_1.integer, text: sqlite_core_1.text, real: sqlite_core_1.real, blob: sqlite_core_1.blob };
|
|
68
|
+
// -----------------------------------------------------------------------------
|
|
69
|
+
// Drizzle Re-exports (Query Operators)
|
|
70
|
+
// -----------------------------------------------------------------------------
|
|
71
|
+
var drizzle_orm_1 = require("drizzle-orm");
|
|
72
|
+
Object.defineProperty(exports, "eq", { enumerable: true, get: function () { return drizzle_orm_1.eq; } });
|
|
73
|
+
Object.defineProperty(exports, "ne", { enumerable: true, get: function () { return drizzle_orm_1.ne; } });
|
|
74
|
+
Object.defineProperty(exports, "gt", { enumerable: true, get: function () { return drizzle_orm_1.gt; } });
|
|
75
|
+
Object.defineProperty(exports, "gte", { enumerable: true, get: function () { return drizzle_orm_1.gte; } });
|
|
76
|
+
Object.defineProperty(exports, "lt", { enumerable: true, get: function () { return drizzle_orm_1.lt; } });
|
|
77
|
+
Object.defineProperty(exports, "lte", { enumerable: true, get: function () { return drizzle_orm_1.lte; } });
|
|
78
|
+
Object.defineProperty(exports, "like", { enumerable: true, get: function () { return drizzle_orm_1.like; } });
|
|
79
|
+
Object.defineProperty(exports, "and", { enumerable: true, get: function () { return drizzle_orm_1.and; } });
|
|
80
|
+
Object.defineProperty(exports, "or", { enumerable: true, get: function () { return drizzle_orm_1.or; } });
|
|
81
|
+
Object.defineProperty(exports, "not", { enumerable: true, get: function () { return drizzle_orm_1.not; } });
|
|
82
|
+
Object.defineProperty(exports, "desc", { enumerable: true, get: function () { return drizzle_orm_1.desc; } });
|
|
83
|
+
Object.defineProperty(exports, "asc", { enumerable: true, get: function () { return drizzle_orm_1.asc; } });
|
|
84
|
+
Object.defineProperty(exports, "count", { enumerable: true, get: function () { return drizzle_orm_1.count; } });
|
|
85
|
+
Object.defineProperty(exports, "sql", { enumerable: true, get: function () { return drizzle_orm_1.sql; } });
|
|
41
86
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAAA
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;GAeG;;;AAEH,gFAAgF;AAChF,WAAW;AACX,gFAAgF;AAEhF,+BAA4D;AAAnD,sGAAA,cAAc,OAAA;AAAE,0GAAA,kBAAkB,OAAA;AAgC3C,gFAAgF;AAChF,SAAS;AACT,gFAAgF;AAEhF,yCAOwB;AANtB,uGAAA,aAAa,OAAA;AACb,qGAAA,WAAW,OAAA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OAAA;AACZ,mGAAA,IAAI,OAAA;AAAE,kGAAA,GAAG,OAAA;AACT,oGAAA,KAAK,OAAA;AAAE,kGAAA,GAAG,OAAA"}
|
package/dist/init.d.ts
CHANGED
|
@@ -1,28 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
autoMigrate?: boolean;
|
|
8
|
-
dropTables?: boolean;
|
|
9
|
-
}
|
|
10
|
-
export interface SchemaData {
|
|
11
|
-
tables: Record<string, any>;
|
|
12
|
-
seedData?: Record<string, any[]>;
|
|
13
|
-
migrationConfig?: MigrationConfig;
|
|
1
|
+
import type { SchemaData, MigrationConfig, NanoPlugin } from './types';
|
|
2
|
+
export type { SchemaData, MigrationConfig, NanoPlugin };
|
|
3
|
+
/** Configuration for createDatabase() */
|
|
4
|
+
export interface CreateDatabaseConfig extends SchemaData {
|
|
5
|
+
/** Plugins to extend database functionality */
|
|
6
|
+
plugins?: NanoPlugin[];
|
|
14
7
|
}
|
|
8
|
+
declare const HOOK_TYPES: readonly ["beforeInsert", "afterInsert", "beforeUpdate", "afterUpdate", "beforeDelete", "afterDelete", "beforeQuery", "afterQuery"];
|
|
9
|
+
type HookType = typeof HOOK_TYPES[number];
|
|
15
10
|
/**
|
|
16
|
-
*
|
|
17
|
-
* This
|
|
11
|
+
* Create and initialize the database with schema, migrations, seeds, and plugins.
|
|
12
|
+
* This is the main entry point for nanodb-orm.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```ts
|
|
16
|
+
* const db = await createDatabase({
|
|
17
|
+
* tables: { users, posts },
|
|
18
|
+
* seedData: { users: [{ name: 'Alice' }] },
|
|
19
|
+
* plugins: [auditPlugin],
|
|
20
|
+
* });
|
|
21
|
+
* ```
|
|
18
22
|
*/
|
|
19
|
-
export declare function
|
|
23
|
+
export declare function createDatabase(config: CreateDatabaseConfig): Promise<import("drizzle-orm/libsql").LibSQLDatabase<Record<string, unknown>> & {
|
|
24
|
+
$client: import("@libsql/core/api").Client;
|
|
25
|
+
} & {
|
|
26
|
+
select: {
|
|
27
|
+
(): import("drizzle-orm/sqlite-core").SQLiteSelectBuilder<undefined, "async", import("@libsql/core/api").ResultSet, "db">;
|
|
28
|
+
<TSelection extends import("drizzle-orm/sqlite-core").SelectedFields>(fields: TSelection): import("drizzle-orm/sqlite-core").SQLiteSelectBuilder<TSelection, "async", import("@libsql/core/api").ResultSet, "db">;
|
|
29
|
+
};
|
|
30
|
+
insert: (table: any) => import("drizzle-orm/sqlite-core").SQLiteInsertBuilder<any, "async", import("@libsql/core/api").ResultSet>;
|
|
31
|
+
update: (table: any) => import("drizzle-orm/sqlite-core").SQLiteUpdateBuilder<any, "async", import("@libsql/core/api").ResultSet>;
|
|
32
|
+
delete: (table: any) => any;
|
|
33
|
+
healthCheck: () => Promise<import("./types").HealthCheck>;
|
|
34
|
+
isReady: () => Promise<boolean>;
|
|
35
|
+
sync: () => Promise<import("./types").SyncResult>;
|
|
36
|
+
reset: () => Promise<void>;
|
|
37
|
+
seed: () => Promise<void>;
|
|
38
|
+
clearData: () => Promise<void>;
|
|
39
|
+
schema: {
|
|
40
|
+
tables: () => string[];
|
|
41
|
+
getTable: (name: string) => import("./types").TableMetadata;
|
|
42
|
+
getColumns: (name: string) => string[];
|
|
43
|
+
validate: () => Promise<import("./types").SchemaValidation>;
|
|
44
|
+
stats: () => {
|
|
45
|
+
totalTables: number;
|
|
46
|
+
tableNames: string[];
|
|
47
|
+
tableDetails: import("./types").TableMetadata[];
|
|
48
|
+
};
|
|
49
|
+
relationships: () => {
|
|
50
|
+
fromTable: string;
|
|
51
|
+
fromColumn: string;
|
|
52
|
+
toTable: string;
|
|
53
|
+
toColumn: string;
|
|
54
|
+
}[];
|
|
55
|
+
};
|
|
56
|
+
migrations: {
|
|
57
|
+
run: () => Promise<void>;
|
|
58
|
+
validate: () => Promise<import("./types").SchemaValidation>;
|
|
59
|
+
checkTables: () => Promise<Record<string, boolean>>;
|
|
60
|
+
};
|
|
61
|
+
plugins: {
|
|
62
|
+
list: () => string[];
|
|
63
|
+
};
|
|
64
|
+
hooks: {
|
|
65
|
+
beforeInsert: (t: string, d: any) => any;
|
|
66
|
+
afterInsert: (t: string, d: any, r: any) => any;
|
|
67
|
+
beforeUpdate: (t: string, d: any) => any;
|
|
68
|
+
afterUpdate: (t: string, d: any, r: any) => any;
|
|
69
|
+
beforeDelete: (t: string, d: any) => any;
|
|
70
|
+
afterDelete: (t: string, d: any, r: any) => any;
|
|
71
|
+
beforeQuery: (t: string, d: any) => any;
|
|
72
|
+
afterQuery: (t: string, d: any, r: any) => any;
|
|
73
|
+
onError: (e: Error, op: string, t?: string) => void;
|
|
74
|
+
onReady: (db: any) => void;
|
|
75
|
+
has: (type: HookType) => boolean;
|
|
76
|
+
};
|
|
77
|
+
}>;
|
|
20
78
|
/**
|
|
21
|
-
*
|
|
79
|
+
* Initialize internal modules with schema data.
|
|
80
|
+
* Prefer `createDatabase()` which calls this automatically.
|
|
81
|
+
*
|
|
82
|
+
* @internal
|
|
22
83
|
*/
|
|
23
|
-
export declare function
|
|
24
|
-
tableNames: string[];
|
|
25
|
-
tableCount: number;
|
|
26
|
-
seedDataTables: string[];
|
|
27
|
-
};
|
|
84
|
+
export declare function initializeDatabase(schemaData: SchemaData): void;
|
|
28
85
|
//# sourceMappingURL=init.d.ts.map
|
package/dist/init.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../init.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"init.d.ts","sourceRoot":"","sources":["../init.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAwC,MAAM,SAAS,CAAC;AAE7G,YAAY,EAAE,UAAU,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC;AAExD,yCAAyC;AACzC,MAAM,WAAW,oBAAqB,SAAQ,UAAU;IACtD,+CAA+C;IAC/C,OAAO,CAAC,EAAE,UAAU,EAAE,CAAC;CACxB;AAMD,QAAA,MAAM,UAAU,qIAKN,CAAC;AAEX,KAAK,QAAQ,GAAG,OAAO,UAAU,CAAC,MAAM,CAAC,CAAC;AA8D1C;;;;;;;;;;;;GAYG;AACH,wBAAsB,cAAc,CAAC,MAAM,EAAE,oBAAoB;;;;;;;oBA8DjC,GAAG;oBAoBH,GAAG;oBAkBH,GAAG;;;;;;;;;yBAyBZ,MAAM;2BACJ,MAAM;;;;;;;;;;;;;;;;;;;;;;;0BApKT,MAAM,KAAK,GAAG;yBACf,MAAM,KAAK,GAAG,KAAK,GAAG;0BACrB,MAAM,KAAK,GAAG;yBACf,MAAM,KAAK,GAAG,KAAK,GAAG;0BACrB,MAAM,KAAK,GAAG;yBACf,MAAM,KAAK,GAAG,KAAK,GAAG;yBACtB,MAAM,KAAK,GAAG;wBACf,MAAM,KAAK,GAAG,KAAK,GAAG;qBACzB,KAAK,MAAM,MAAM,MAAM,MAAM;sBAC5B,GAAG;oBACL,QAAQ;;GAwLvB;AAaD;;;;;GAKG;AACH,wBAAgB,kBAAkB,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI,CAuB/D"}
|