nanodb-orm 0.0.3 → 0.0.5
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 +506 -333
- package/dist/cli.d.ts +96 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +348 -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 +16 -31
- package/dist/core/connection.d.ts.map +1 -1
- package/dist/core/connection.js +42 -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 +235 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +252 -35
- package/dist/index.js.map +1 -1
- package/dist/init.d.ts +127 -18
- package/dist/init.d.ts.map +1 -1
- package/dist/init.js +280 -47
- 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 +268 -4
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +5 -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 +220 -422
- 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 +125 -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 +108 -186
- 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 +78 -172
- package/dist/utils/sync.js.map +1 -1
- package/dist/utils/transactions.d.ts +61 -44
- package/dist/utils/transactions.d.ts.map +1 -1
- package/dist/utils/transactions.js +103 -137
- 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/index.js
CHANGED
|
@@ -1,41 +1,258 @@
|
|
|
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
|
+
* // Default import (recommended)
|
|
8
|
+
* import nanodb from 'nanodb-orm';
|
|
9
|
+
*
|
|
10
|
+
* const users = nanodb.schema.table('users', {
|
|
11
|
+
* id: nanodb.schema.integer('id').primaryKey({ autoIncrement: true }),
|
|
12
|
+
* name: nanodb.schema.text('name').notNull(),
|
|
13
|
+
* });
|
|
14
|
+
*
|
|
15
|
+
* const db = await nanodb.createDatabase({ tables: { users } });
|
|
16
|
+
* const adults = await db.select().from(users).where(nanodb.query.gte(users.age, 18));
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```ts
|
|
21
|
+
* // Named imports
|
|
22
|
+
* import { createDatabase, schema, query } from 'nanodb-orm';
|
|
23
|
+
* ```
|
|
9
24
|
*/
|
|
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
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
-
exports.
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
//
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
26
|
+
exports.isNotNull = exports.isNull = exports.notInArray = exports.inArray = exports.between = exports.not = exports.or = exports.and = exports.notLike = exports.ilike = 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.runValidate = exports.getStatus = exports.runReset = exports.runSetup = exports.launchStudio = exports.recreateTable = exports.batch = 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 = exports.cli = exports.errors = exports.query = exports.schema = void 0;
|
|
27
|
+
exports.sql = exports.max = exports.min = exports.avg = exports.sum = exports.count = exports.asc = exports.desc = void 0;
|
|
28
|
+
const sqlite_core_1 = require("drizzle-orm/sqlite-core");
|
|
29
|
+
Object.defineProperty(exports, "sqliteTable", { enumerable: true, get: function () { return sqlite_core_1.sqliteTable; } });
|
|
30
|
+
const drizzle_orm_1 = require("drizzle-orm");
|
|
31
|
+
// =============================================================================
|
|
32
|
+
// GROUPED EXPORTS (Recommended for cleaner imports)
|
|
33
|
+
// =============================================================================
|
|
34
|
+
/**
|
|
35
|
+
* Schema building utilities.
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```ts
|
|
39
|
+
* import { schema } from 'nanodb-orm';
|
|
40
|
+
*
|
|
41
|
+
* const users = schema.table('users', {
|
|
42
|
+
* id: schema.integer('id').primaryKey({ autoIncrement: true }),
|
|
43
|
+
* name: schema.text('name').notNull(),
|
|
44
|
+
* email: schema.text('email').unique(),
|
|
45
|
+
* });
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
exports.schema = {
|
|
49
|
+
table: sqlite_core_1.sqliteTable,
|
|
50
|
+
integer: sqlite_core_1.integer,
|
|
51
|
+
text: sqlite_core_1.text,
|
|
52
|
+
real: sqlite_core_1.real,
|
|
53
|
+
blob: sqlite_core_1.blob,
|
|
54
|
+
};
|
|
55
|
+
/**
|
|
56
|
+
* Query operators for WHERE clauses and expressions.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* import { query } from 'nanodb-orm';
|
|
61
|
+
*
|
|
62
|
+
* await db.select().from(users).where(
|
|
63
|
+
* query.and(
|
|
64
|
+
* query.gte(users.age, 18),
|
|
65
|
+
* query.like(users.name, 'A%')
|
|
66
|
+
* )
|
|
67
|
+
* );
|
|
68
|
+
* ```
|
|
69
|
+
*/
|
|
70
|
+
exports.query = {
|
|
71
|
+
// Comparison
|
|
72
|
+
eq: drizzle_orm_1.eq,
|
|
73
|
+
ne: drizzle_orm_1.ne,
|
|
74
|
+
gt: drizzle_orm_1.gt,
|
|
75
|
+
gte: drizzle_orm_1.gte,
|
|
76
|
+
lt: drizzle_orm_1.lt,
|
|
77
|
+
lte: drizzle_orm_1.lte,
|
|
78
|
+
like: drizzle_orm_1.like,
|
|
79
|
+
ilike: drizzle_orm_1.ilike,
|
|
80
|
+
notLike: drizzle_orm_1.notLike,
|
|
81
|
+
// Logical
|
|
82
|
+
and: drizzle_orm_1.and,
|
|
83
|
+
or: drizzle_orm_1.or,
|
|
84
|
+
not: drizzle_orm_1.not,
|
|
85
|
+
// Range
|
|
86
|
+
between: drizzle_orm_1.between,
|
|
87
|
+
inArray: drizzle_orm_1.inArray,
|
|
88
|
+
notInArray: drizzle_orm_1.notInArray,
|
|
89
|
+
isNull: drizzle_orm_1.isNull,
|
|
90
|
+
isNotNull: drizzle_orm_1.isNotNull,
|
|
91
|
+
// Ordering
|
|
92
|
+
desc: drizzle_orm_1.desc,
|
|
93
|
+
asc: drizzle_orm_1.asc,
|
|
94
|
+
// Aggregates
|
|
95
|
+
count: drizzle_orm_1.count,
|
|
96
|
+
sum: drizzle_orm_1.sum,
|
|
97
|
+
avg: drizzle_orm_1.avg,
|
|
98
|
+
min: drizzle_orm_1.min,
|
|
99
|
+
max: drizzle_orm_1.max,
|
|
100
|
+
// Raw SQL
|
|
101
|
+
sql: drizzle_orm_1.sql,
|
|
102
|
+
};
|
|
103
|
+
/**
|
|
104
|
+
* Error classes and utilities.
|
|
105
|
+
*
|
|
106
|
+
* @example
|
|
107
|
+
* ```ts
|
|
108
|
+
* import { errors } from 'nanodb-orm';
|
|
109
|
+
*
|
|
110
|
+
* try {
|
|
111
|
+
* await db.insert(users).values({ ... });
|
|
112
|
+
* } catch (e) {
|
|
113
|
+
* if (e instanceof errors.DatabaseError) {
|
|
114
|
+
* console.log(e.message, e.table);
|
|
115
|
+
* }
|
|
116
|
+
* const parsed = errors.parse(e, { table: 'users' });
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
119
|
+
*/
|
|
120
|
+
const errors_1 = require("./types/errors");
|
|
121
|
+
exports.errors = {
|
|
122
|
+
DatabaseError: errors_1.DatabaseError,
|
|
123
|
+
SchemaError: errors_1.SchemaError,
|
|
124
|
+
ConnectionError: errors_1.ConnectionError,
|
|
125
|
+
MigrationError: errors_1.MigrationError,
|
|
126
|
+
SeedError: errors_1.SeedError,
|
|
127
|
+
parse: errors_1.parseDbError,
|
|
128
|
+
};
|
|
129
|
+
/**
|
|
130
|
+
* CLI functions for programmatic access.
|
|
131
|
+
*
|
|
132
|
+
* @example
|
|
133
|
+
* ```ts
|
|
134
|
+
* import { cli } from 'nanodb-orm';
|
|
135
|
+
*
|
|
136
|
+
* await cli.setup();
|
|
137
|
+
* const status = await cli.status(true);
|
|
138
|
+
* await cli.studio({ port: 3000 });
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
const cli_1 = require("./cli");
|
|
142
|
+
exports.cli = {
|
|
143
|
+
studio: cli_1.launchStudio,
|
|
144
|
+
setup: cli_1.runSetup,
|
|
145
|
+
reset: cli_1.runReset,
|
|
146
|
+
status: cli_1.getStatus,
|
|
147
|
+
validate: cli_1.runValidate,
|
|
148
|
+
};
|
|
149
|
+
// =============================================================================
|
|
150
|
+
// MAIN API
|
|
151
|
+
// =============================================================================
|
|
152
|
+
var init_1 = require("./init");
|
|
153
|
+
Object.defineProperty(exports, "createDatabase", { enumerable: true, get: function () { return init_1.createDatabase; } });
|
|
154
|
+
Object.defineProperty(exports, "initializeDatabase", { enumerable: true, get: function () { return init_1.initializeDatabase; } });
|
|
155
|
+
// =============================================================================
|
|
156
|
+
// INDIVIDUAL EXPORTS (for tree-shaking or preference)
|
|
157
|
+
// =============================================================================
|
|
158
|
+
// Errors (individual)
|
|
159
|
+
var errors_2 = require("./types/errors");
|
|
160
|
+
Object.defineProperty(exports, "DatabaseError", { enumerable: true, get: function () { return errors_2.DatabaseError; } });
|
|
161
|
+
Object.defineProperty(exports, "SchemaError", { enumerable: true, get: function () { return errors_2.SchemaError; } });
|
|
162
|
+
Object.defineProperty(exports, "ConnectionError", { enumerable: true, get: function () { return errors_2.ConnectionError; } });
|
|
163
|
+
Object.defineProperty(exports, "MigrationError", { enumerable: true, get: function () { return errors_2.MigrationError; } });
|
|
164
|
+
Object.defineProperty(exports, "SeedError", { enumerable: true, get: function () { return errors_2.SeedError; } });
|
|
165
|
+
Object.defineProperty(exports, "parseDbError", { enumerable: true, get: function () { return errors_2.parseDbError; } });
|
|
166
|
+
// Utilities
|
|
167
|
+
var connection_1 = require("./core/connection");
|
|
168
|
+
Object.defineProperty(exports, "DatabaseConnection", { enumerable: true, get: function () { return connection_1.DatabaseConnection; } });
|
|
169
|
+
var config_1 = require("./core/config");
|
|
170
|
+
Object.defineProperty(exports, "getDatabaseConfig", { enumerable: true, get: function () { return config_1.getDatabaseConfig; } });
|
|
171
|
+
var sync_1 = require("./utils/sync");
|
|
172
|
+
Object.defineProperty(exports, "DatabaseSync", { enumerable: true, get: function () { return sync_1.DatabaseSync; } });
|
|
173
|
+
var migrations_1 = require("./utils/migrations");
|
|
174
|
+
Object.defineProperty(exports, "DatabaseMigrations", { enumerable: true, get: function () { return migrations_1.DatabaseMigrations; } });
|
|
175
|
+
var seeds_1 = require("./utils/seeds");
|
|
176
|
+
Object.defineProperty(exports, "DatabaseSeeds", { enumerable: true, get: function () { return seeds_1.DatabaseSeeds; } });
|
|
177
|
+
var schema_introspection_1 = require("./utils/schema-introspection");
|
|
178
|
+
Object.defineProperty(exports, "SchemaIntrospection", { enumerable: true, get: function () { return schema_introspection_1.SchemaIntrospection; } });
|
|
179
|
+
var transactions_1 = require("./utils/transactions");
|
|
180
|
+
Object.defineProperty(exports, "transaction", { enumerable: true, get: function () { return transactions_1.transaction; } });
|
|
181
|
+
Object.defineProperty(exports, "batch", { enumerable: true, get: function () { return transactions_1.batch; } });
|
|
182
|
+
Object.defineProperty(exports, "recreateTable", { enumerable: true, get: function () { return transactions_1.recreateTable; } });
|
|
183
|
+
// CLI (individual)
|
|
184
|
+
var cli_2 = require("./cli");
|
|
185
|
+
Object.defineProperty(exports, "launchStudio", { enumerable: true, get: function () { return cli_2.launchStudio; } });
|
|
186
|
+
Object.defineProperty(exports, "runSetup", { enumerable: true, get: function () { return cli_2.runSetup; } });
|
|
187
|
+
Object.defineProperty(exports, "runReset", { enumerable: true, get: function () { return cli_2.runReset; } });
|
|
188
|
+
Object.defineProperty(exports, "getStatus", { enumerable: true, get: function () { return cli_2.getStatus; } });
|
|
189
|
+
Object.defineProperty(exports, "runValidate", { enumerable: true, get: function () { return cli_2.runValidate; } });
|
|
190
|
+
// Schema building (individual)
|
|
191
|
+
exports.table = sqlite_core_1.sqliteTable;
|
|
192
|
+
exports.integer = sqlite_core_1.integer;
|
|
193
|
+
exports.text = sqlite_core_1.text;
|
|
194
|
+
exports.real = sqlite_core_1.real;
|
|
195
|
+
exports.blob = sqlite_core_1.blob;
|
|
196
|
+
exports.column = exports.schema; // Alias
|
|
197
|
+
// Query operators (individual)
|
|
198
|
+
var drizzle_orm_2 = require("drizzle-orm");
|
|
199
|
+
Object.defineProperty(exports, "eq", { enumerable: true, get: function () { return drizzle_orm_2.eq; } });
|
|
200
|
+
Object.defineProperty(exports, "ne", { enumerable: true, get: function () { return drizzle_orm_2.ne; } });
|
|
201
|
+
Object.defineProperty(exports, "gt", { enumerable: true, get: function () { return drizzle_orm_2.gt; } });
|
|
202
|
+
Object.defineProperty(exports, "gte", { enumerable: true, get: function () { return drizzle_orm_2.gte; } });
|
|
203
|
+
Object.defineProperty(exports, "lt", { enumerable: true, get: function () { return drizzle_orm_2.lt; } });
|
|
204
|
+
Object.defineProperty(exports, "lte", { enumerable: true, get: function () { return drizzle_orm_2.lte; } });
|
|
205
|
+
Object.defineProperty(exports, "like", { enumerable: true, get: function () { return drizzle_orm_2.like; } });
|
|
206
|
+
Object.defineProperty(exports, "ilike", { enumerable: true, get: function () { return drizzle_orm_2.ilike; } });
|
|
207
|
+
Object.defineProperty(exports, "notLike", { enumerable: true, get: function () { return drizzle_orm_2.notLike; } });
|
|
208
|
+
Object.defineProperty(exports, "and", { enumerable: true, get: function () { return drizzle_orm_2.and; } });
|
|
209
|
+
Object.defineProperty(exports, "or", { enumerable: true, get: function () { return drizzle_orm_2.or; } });
|
|
210
|
+
Object.defineProperty(exports, "not", { enumerable: true, get: function () { return drizzle_orm_2.not; } });
|
|
211
|
+
Object.defineProperty(exports, "between", { enumerable: true, get: function () { return drizzle_orm_2.between; } });
|
|
212
|
+
Object.defineProperty(exports, "inArray", { enumerable: true, get: function () { return drizzle_orm_2.inArray; } });
|
|
213
|
+
Object.defineProperty(exports, "notInArray", { enumerable: true, get: function () { return drizzle_orm_2.notInArray; } });
|
|
214
|
+
Object.defineProperty(exports, "isNull", { enumerable: true, get: function () { return drizzle_orm_2.isNull; } });
|
|
215
|
+
Object.defineProperty(exports, "isNotNull", { enumerable: true, get: function () { return drizzle_orm_2.isNotNull; } });
|
|
216
|
+
Object.defineProperty(exports, "desc", { enumerable: true, get: function () { return drizzle_orm_2.desc; } });
|
|
217
|
+
Object.defineProperty(exports, "asc", { enumerable: true, get: function () { return drizzle_orm_2.asc; } });
|
|
218
|
+
Object.defineProperty(exports, "count", { enumerable: true, get: function () { return drizzle_orm_2.count; } });
|
|
219
|
+
Object.defineProperty(exports, "sum", { enumerable: true, get: function () { return drizzle_orm_2.sum; } });
|
|
220
|
+
Object.defineProperty(exports, "avg", { enumerable: true, get: function () { return drizzle_orm_2.avg; } });
|
|
221
|
+
Object.defineProperty(exports, "min", { enumerable: true, get: function () { return drizzle_orm_2.min; } });
|
|
222
|
+
Object.defineProperty(exports, "max", { enumerable: true, get: function () { return drizzle_orm_2.max; } });
|
|
223
|
+
Object.defineProperty(exports, "sql", { enumerable: true, get: function () { return drizzle_orm_2.sql; } });
|
|
224
|
+
// =============================================================================
|
|
225
|
+
// DEFAULT EXPORT
|
|
226
|
+
// =============================================================================
|
|
227
|
+
const init_2 = require("./init");
|
|
228
|
+
const transactions_2 = require("./utils/transactions");
|
|
229
|
+
/**
|
|
230
|
+
* Default export with all nanodb-orm functionality.
|
|
231
|
+
*
|
|
232
|
+
* @example
|
|
233
|
+
* ```ts
|
|
234
|
+
* import nanodb from 'nanodb-orm';
|
|
235
|
+
*
|
|
236
|
+
* const users = nanodb.schema.table('users', {
|
|
237
|
+
* id: nanodb.schema.integer('id').primaryKey({ autoIncrement: true }),
|
|
238
|
+
* name: nanodb.schema.text('name').notNull(),
|
|
239
|
+
* });
|
|
240
|
+
*
|
|
241
|
+
* const db = await nanodb.createDatabase({ tables: { users } });
|
|
242
|
+
* await db.select().from(users).where(nanodb.query.eq(users.id, 1));
|
|
243
|
+
* ```
|
|
244
|
+
*/
|
|
245
|
+
const nanodb = {
|
|
246
|
+
// Main API
|
|
247
|
+
createDatabase: init_2.createDatabase,
|
|
248
|
+
initializeDatabase: init_2.initializeDatabase,
|
|
249
|
+
transaction: transactions_2.transaction,
|
|
250
|
+
batch: transactions_2.batch,
|
|
251
|
+
// Grouped utilities
|
|
252
|
+
schema: exports.schema,
|
|
253
|
+
query: exports.query,
|
|
254
|
+
errors: exports.errors,
|
|
255
|
+
cli: exports.cli,
|
|
256
|
+
};
|
|
257
|
+
exports.default = nanodb;
|
|
41
258
|
//# 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;;;;;;;;;;;;;;;;;;;;;;GAsBG;;;;AAEH,yDAMiC;AAoRxB,4FAzRP,yBAAW,OAyRO;AAlRpB,6CA0BqB;AAErB,gFAAgF;AAChF,oDAAoD;AACpD,gFAAgF;AAEhF;;;;;;;;;;;;;GAaG;AACU,QAAA,MAAM,GAAG;IACpB,KAAK,EAAE,yBAAW;IAClB,OAAO,EAAE,qBAAc;IACvB,IAAI,EAAE,kBAAW;IACjB,IAAI,EAAE,kBAAW;IACjB,IAAI,EAAE,kBAAW;CAClB,CAAC;AAEF;;;;;;;;;;;;;;GAcG;AACU,QAAA,KAAK,GAAG;IACnB,aAAa;IACb,EAAE,EAAE,gBAAS;IACb,EAAE,EAAE,gBAAS;IACb,EAAE,EAAE,gBAAS;IACb,GAAG,EAAE,iBAAU;IACf,EAAE,EAAE,gBAAS;IACb,GAAG,EAAE,iBAAU;IACf,IAAI,EAAE,kBAAW;IACjB,KAAK,EAAE,mBAAY;IACnB,OAAO,EAAE,qBAAc;IACvB,UAAU;IACV,GAAG,EAAE,iBAAU;IACf,EAAE,EAAE,gBAAS;IACb,GAAG,EAAE,iBAAU;IACf,QAAQ;IACR,OAAO,EAAE,qBAAc;IACvB,OAAO,EAAE,qBAAc;IACvB,UAAU,EAAE,wBAAiB;IAC7B,MAAM,EAAE,oBAAa;IACrB,SAAS,EAAE,uBAAgB;IAC3B,WAAW;IACX,IAAI,EAAE,kBAAW;IACjB,GAAG,EAAE,iBAAU;IACf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AACH,MAAM,MAAM,GAAG;IACb,WAAW;IACX,cAAc,EAAd,qBAAc;IACd,kBAAkB,EAAlB,yBAAkB;IAClB,WAAW,EAAX,0BAAW;IACX,KAAK,EAAL,oBAAK;IAEL,oBAAoB;IACpB,MAAM,EAAN,cAAM;IACN,KAAK,EAAL,aAAK;IACL,MAAM,EAAN,cAAM;IACN,GAAG,EAAH,WAAG;CACJ,CAAC;AAEF,kBAAe,MAAM,CAAC"}
|
package/dist/init.d.ts
CHANGED
|
@@ -1,28 +1,137 @@
|
|
|
1
|
+
import type { Schema, SchemaData, MigrationConfig, NanoPlugin, HealthCheck, SyncResult, SchemaValidation, TableMetadata } from './types';
|
|
2
|
+
import type { LibSQLDatabase } from 'drizzle-orm/libsql';
|
|
3
|
+
export type { SchemaData, MigrationConfig, NanoPlugin };
|
|
1
4
|
/**
|
|
2
|
-
*
|
|
3
|
-
* Initializes the db package with schema data to work as an npm package
|
|
5
|
+
* Hook system attached to the database instance.
|
|
4
6
|
*/
|
|
5
|
-
export interface
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
export interface Hooks {
|
|
8
|
+
beforeInsert: <T>(table: string, data: T) => T;
|
|
9
|
+
afterInsert: <T, R>(table: string, data: T, result: R) => T;
|
|
10
|
+
beforeUpdate: <T>(table: string, data: T) => T;
|
|
11
|
+
afterUpdate: <T, R>(table: string, data: T, result: R) => T;
|
|
12
|
+
beforeDelete: <T>(table: string, data: T) => T;
|
|
13
|
+
afterDelete: <T, R>(table: string, data: T, result: R) => T;
|
|
14
|
+
beforeQuery: <T>(table: string, data: T) => T;
|
|
15
|
+
afterQuery: <T, R>(table: string, data: T, result: R) => T;
|
|
16
|
+
onError: (error: Error, operation: string, table?: string) => void;
|
|
17
|
+
onReady: (db: unknown) => void;
|
|
18
|
+
has: (type: HookType) => boolean;
|
|
9
19
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Schema introspection utilities.
|
|
22
|
+
*/
|
|
23
|
+
export interface SchemaUtils<S extends Schema> {
|
|
24
|
+
/** Get all table names */
|
|
25
|
+
tables: () => (keyof S)[];
|
|
26
|
+
/** Get metadata for a specific table */
|
|
27
|
+
getTable: (name: keyof S) => TableMetadata;
|
|
28
|
+
/** Get column names for a table */
|
|
29
|
+
getColumns: (name: keyof S) => string[];
|
|
30
|
+
/** Validate schema against database */
|
|
31
|
+
validate: () => Promise<SchemaValidation>;
|
|
32
|
+
/** Get schema statistics */
|
|
33
|
+
stats: () => {
|
|
34
|
+
totalTables: number;
|
|
35
|
+
tableNames: string[];
|
|
36
|
+
tableDetails: TableMetadata[];
|
|
37
|
+
};
|
|
38
|
+
/** Get all foreign key relationships */
|
|
39
|
+
relationships: () => Array<{
|
|
40
|
+
fromTable: string;
|
|
41
|
+
fromColumn: string;
|
|
42
|
+
toTable: string;
|
|
43
|
+
toColumn: string;
|
|
44
|
+
}>;
|
|
14
45
|
}
|
|
15
46
|
/**
|
|
16
|
-
*
|
|
17
|
-
* This allows the db package to work independently without direct imports
|
|
47
|
+
* Migration utilities.
|
|
18
48
|
*/
|
|
19
|
-
export
|
|
49
|
+
export interface MigrationUtils {
|
|
50
|
+
/** Run migrations */
|
|
51
|
+
run: () => Promise<void>;
|
|
52
|
+
/** Validate schema against database */
|
|
53
|
+
validate: () => Promise<SchemaValidation>;
|
|
54
|
+
/** Check which tables exist */
|
|
55
|
+
checkTables: () => Promise<Record<string, boolean>>;
|
|
56
|
+
}
|
|
20
57
|
/**
|
|
21
|
-
*
|
|
58
|
+
* Plugin utilities.
|
|
22
59
|
*/
|
|
23
|
-
export
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
60
|
+
export interface PluginUtils {
|
|
61
|
+
/** List installed plugin names */
|
|
62
|
+
list: () => string[];
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* The enhanced database instance returned by createDatabase.
|
|
66
|
+
* Extends the Drizzle database with additional utilities while preserving
|
|
67
|
+
* full type safety for all table operations.
|
|
68
|
+
*/
|
|
69
|
+
export type NanoDatabase<S extends Schema> = LibSQLDatabase<S> & {
|
|
70
|
+
/** Health check */
|
|
71
|
+
healthCheck: () => Promise<HealthCheck>;
|
|
72
|
+
/** Check if database is ready */
|
|
73
|
+
isReady: () => Promise<boolean>;
|
|
74
|
+
/** Sync with remote (Turso) */
|
|
75
|
+
sync: () => Promise<SyncResult>;
|
|
76
|
+
/** Reset database (drop, recreate, seed) */
|
|
77
|
+
reset: () => Promise<void>;
|
|
78
|
+
/** Re-seed database */
|
|
79
|
+
seed: () => Promise<void>;
|
|
80
|
+
/** Clear all data */
|
|
81
|
+
clearData: () => Promise<void>;
|
|
82
|
+
/** Schema introspection utilities */
|
|
83
|
+
schema: SchemaUtils<S>;
|
|
84
|
+
/** Migration utilities */
|
|
85
|
+
migrations: MigrationUtils;
|
|
86
|
+
/** Installed plugins */
|
|
87
|
+
plugins: PluginUtils;
|
|
88
|
+
/** Hook system */
|
|
89
|
+
hooks: Hooks;
|
|
27
90
|
};
|
|
91
|
+
/**
|
|
92
|
+
* Configuration for createDatabase().
|
|
93
|
+
*/
|
|
94
|
+
export interface CreateDatabaseConfig<S extends Schema = Schema> extends SchemaData<S> {
|
|
95
|
+
/** Plugins to extend database functionality */
|
|
96
|
+
plugins?: NanoPlugin[];
|
|
97
|
+
}
|
|
98
|
+
declare const HOOK_TYPES: readonly ["beforeInsert", "afterInsert", "beforeUpdate", "afterUpdate", "beforeDelete", "afterDelete", "beforeQuery", "afterQuery"];
|
|
99
|
+
type HookType = typeof HOOK_TYPES[number];
|
|
100
|
+
/**
|
|
101
|
+
* Create and initialize the database with schema, migrations, seeds, and plugins.
|
|
102
|
+
* This is the main entry point for nanodb-orm.
|
|
103
|
+
*
|
|
104
|
+
* The returned database instance is fully type-safe - all queries, inserts, and
|
|
105
|
+
* updates will have proper TypeScript types inferred from your schema.
|
|
106
|
+
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```ts
|
|
109
|
+
* import { createDatabase, table, integer, text } from 'nanodb-orm';
|
|
110
|
+
*
|
|
111
|
+
* const users = table('users', {
|
|
112
|
+
* id: integer('id').primaryKey({ autoIncrement: true }),
|
|
113
|
+
* name: text('name').notNull(),
|
|
114
|
+
* email: text('email').notNull(),
|
|
115
|
+
* });
|
|
116
|
+
*
|
|
117
|
+
* const db = await createDatabase({
|
|
118
|
+
* tables: { users },
|
|
119
|
+
* seedData: { users: [{ name: 'Alice', email: 'alice@example.com' }] },
|
|
120
|
+
* });
|
|
121
|
+
*
|
|
122
|
+
* // Fully typed! `allUsers` is User[]
|
|
123
|
+
* const allUsers = await db.select().from(users);
|
|
124
|
+
*
|
|
125
|
+
* // Type error if you try to insert invalid data
|
|
126
|
+
* await db.insert(users).values({ name: 'Bob', email: 'bob@example.com' });
|
|
127
|
+
* ```
|
|
128
|
+
*/
|
|
129
|
+
export declare function createDatabase<S extends Schema>(config: CreateDatabaseConfig<S>): Promise<NanoDatabase<S>>;
|
|
130
|
+
/**
|
|
131
|
+
* Initialize internal modules with schema data.
|
|
132
|
+
* Prefer `createDatabase()` which calls this automatically.
|
|
133
|
+
*
|
|
134
|
+
* @internal
|
|
135
|
+
*/
|
|
136
|
+
export declare function initializeDatabase<S extends Schema>(schemaData: SchemaData<S>): void;
|
|
28
137
|
//# 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,EACV,MAAM,EAEN,UAAU,EACV,eAAe,EACf,UAAU,EAIV,WAAW,EACX,UAAU,EACV,gBAAgB,EAChB,aAAa,EACd,MAAM,SAAS,CAAC;AACjB,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAEzD,YAA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