flint-orm 0.4.1 → 0.4.2
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/dist/config.d.ts +30 -0
- package/dist/drivers/better-sqlite3.d.ts +38 -0
- package/dist/drivers/bun-sqlite.d.ts +38 -0
- package/dist/drivers/libsql-web.d.ts +44 -0
- package/dist/drivers/libsql.d.ts +40 -0
- package/dist/drivers/turso-sync.d.ts +44 -0
- package/dist/drivers/turso.d.ts +38 -0
- package/dist/entries/better-sqlite3.d.ts +1 -0
- package/dist/entries/bun-sqlite.d.ts +1 -0
- package/dist/entries/config.d.ts +1 -0
- package/dist/entries/expressions.d.ts +5 -0
- package/dist/entries/libsql-web.d.ts +2 -0
- package/dist/entries/libsql.d.ts +2 -0
- package/dist/entries/table.d.ts +4 -0
- package/dist/entries/turso-sync.d.ts +2 -0
- package/dist/entries/turso.d.ts +1 -0
- package/dist/errors.d.ts +13 -0
- package/dist/executor.d.ts +16 -0
- package/dist/flint.d.ts +120 -0
- package/dist/index.d.ts +11 -0
- package/dist/migration/diff.d.ts +15 -0
- package/dist/migration/generate.d.ts +18 -0
- package/dist/migration/index.d.ts +11 -0
- package/dist/migration/migrate.d.ts +52 -0
- package/dist/migration/migration.d.ts +5 -0
- package/dist/migration/operations.d.ts +14 -0
- package/dist/migration/serialize.d.ts +3 -0
- package/dist/migration/sql.d.ts +2 -0
- package/dist/migration/types.d.ts +98 -0
- package/dist/query/aggregates.d.ts +47 -0
- package/dist/query/builder.d.ts +257 -0
- package/dist/query/conditions.d.ts +176 -0
- package/dist/schema/columns.d.ts +146 -0
- package/dist/schema/table.d.ts +74 -0
- package/dist/sqlite/introspect.d.ts +19 -0
- package/dist/src/cli.js +13744 -0
- package/dist/src/entries/better-sqlite3.js +2050 -0
- package/dist/src/entries/bun-sqlite.js +1284 -0
- package/dist/src/entries/config.js +55 -0
- package/dist/src/entries/expressions.js +1252 -0
- package/dist/src/entries/libsql-web.js +6065 -0
- package/dist/src/entries/libsql.js +7208 -0
- package/dist/src/entries/table.js +403 -0
- package/dist/src/entries/turso-sync.js +3504 -0
- package/dist/src/entries/turso.js +2379 -0
- package/dist/{index.js → src/index.js} +86 -22
- package/dist/src/migration/index.js +1066 -0
- package/package.json +1 -1
|
@@ -0,0 +1,403 @@
|
|
|
1
|
+
// @bun
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
function __accessProp(key) {
|
|
8
|
+
return this[key];
|
|
9
|
+
}
|
|
10
|
+
var __toESMCache_node;
|
|
11
|
+
var __toESMCache_esm;
|
|
12
|
+
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
+
var canCache = mod != null && typeof mod === "object";
|
|
14
|
+
if (canCache) {
|
|
15
|
+
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
+
var cached = cache.get(mod);
|
|
17
|
+
if (cached)
|
|
18
|
+
return cached;
|
|
19
|
+
}
|
|
20
|
+
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
+
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
+
for (let key of __getOwnPropNames(mod))
|
|
23
|
+
if (!__hasOwnProp.call(to, key))
|
|
24
|
+
__defProp(to, key, {
|
|
25
|
+
get: __accessProp.bind(mod, key),
|
|
26
|
+
enumerable: true
|
|
27
|
+
});
|
|
28
|
+
if (canCache)
|
|
29
|
+
cache.set(mod, to);
|
|
30
|
+
return to;
|
|
31
|
+
};
|
|
32
|
+
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
|
+
var __returnValue = (v) => v;
|
|
34
|
+
function __exportSetter(name, newValue) {
|
|
35
|
+
this[name] = __returnValue.bind(null, newValue);
|
|
36
|
+
}
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, {
|
|
40
|
+
get: all[name],
|
|
41
|
+
enumerable: true,
|
|
42
|
+
configurable: true,
|
|
43
|
+
set: __exportSetter.bind(all, name)
|
|
44
|
+
});
|
|
45
|
+
};
|
|
46
|
+
var __esm = (fn, res) => () => (fn && (res = fn(fn = 0)), res);
|
|
47
|
+
var __require = import.meta.require;
|
|
48
|
+
|
|
49
|
+
// src/schema/columns.ts
|
|
50
|
+
function nullCast() {
|
|
51
|
+
return null;
|
|
52
|
+
}
|
|
53
|
+
function makeColumn(config) {
|
|
54
|
+
const base = {
|
|
55
|
+
name: config.name,
|
|
56
|
+
__internal: {
|
|
57
|
+
_type: undefined,
|
|
58
|
+
sqlType: config.sqlType,
|
|
59
|
+
isPrimaryKey: false,
|
|
60
|
+
isNotNull: false,
|
|
61
|
+
isUnique: false,
|
|
62
|
+
hasDefault: false,
|
|
63
|
+
defaultValue: undefined,
|
|
64
|
+
defaultFn: undefined,
|
|
65
|
+
isAutoIncrement: false,
|
|
66
|
+
hasDefaultNow: false,
|
|
67
|
+
hasOnUpdate: false,
|
|
68
|
+
referencesTable: null,
|
|
69
|
+
referencesColumn: null,
|
|
70
|
+
onDelete: null,
|
|
71
|
+
onUpdate: null,
|
|
72
|
+
encode: config.encode,
|
|
73
|
+
decode: config.decode,
|
|
74
|
+
tableName: null
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
const col = {
|
|
78
|
+
...base,
|
|
79
|
+
primaryKey() {
|
|
80
|
+
return { ...this, __internal: { ...this.__internal, isPrimaryKey: true } };
|
|
81
|
+
},
|
|
82
|
+
notNull() {
|
|
83
|
+
return { ...this, __internal: { ...this.__internal, isNotNull: true } };
|
|
84
|
+
},
|
|
85
|
+
unique() {
|
|
86
|
+
return { ...this, __internal: { ...this.__internal, isUnique: true } };
|
|
87
|
+
},
|
|
88
|
+
default(value) {
|
|
89
|
+
return { ...this, __internal: { ...this.__internal, hasDefault: true, defaultValue: value } };
|
|
90
|
+
},
|
|
91
|
+
defaultFn(fn) {
|
|
92
|
+
return { ...this, __internal: { ...this.__internal, hasDefault: true, defaultFn: fn } };
|
|
93
|
+
},
|
|
94
|
+
references(target) {
|
|
95
|
+
return {
|
|
96
|
+
...this,
|
|
97
|
+
__internal: {
|
|
98
|
+
...this.__internal,
|
|
99
|
+
referencesTable: target.__internal.tableName,
|
|
100
|
+
referencesColumn: target.name
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
},
|
|
104
|
+
onDelete(action) {
|
|
105
|
+
return { ...this, __internal: { ...this.__internal, onDelete: action } };
|
|
106
|
+
},
|
|
107
|
+
onUpdate(action) {
|
|
108
|
+
return { ...this, __internal: { ...this.__internal, onUpdate: action } };
|
|
109
|
+
}
|
|
110
|
+
};
|
|
111
|
+
return col;
|
|
112
|
+
}
|
|
113
|
+
function text(name) {
|
|
114
|
+
return makeColumn({
|
|
115
|
+
name: name ?? "",
|
|
116
|
+
sqlType: "text",
|
|
117
|
+
encode: (v) => v,
|
|
118
|
+
decode: (v) => v == null ? nullCast() : v
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function integer(name) {
|
|
122
|
+
const base = makeColumn({
|
|
123
|
+
name: name ?? "",
|
|
124
|
+
sqlType: "integer",
|
|
125
|
+
encode: (v) => v,
|
|
126
|
+
decode: (v) => v == null ? nullCast() : Number(v)
|
|
127
|
+
});
|
|
128
|
+
const intCol = {
|
|
129
|
+
...base,
|
|
130
|
+
primaryKey() {
|
|
131
|
+
return {
|
|
132
|
+
...this,
|
|
133
|
+
__internal: { ...this.__internal, isPrimaryKey: true }
|
|
134
|
+
};
|
|
135
|
+
},
|
|
136
|
+
notNull() {
|
|
137
|
+
return {
|
|
138
|
+
...this,
|
|
139
|
+
__internal: { ...this.__internal, isNotNull: true }
|
|
140
|
+
};
|
|
141
|
+
},
|
|
142
|
+
unique() {
|
|
143
|
+
return {
|
|
144
|
+
...this,
|
|
145
|
+
__internal: { ...this.__internal, isUnique: true }
|
|
146
|
+
};
|
|
147
|
+
},
|
|
148
|
+
default(value) {
|
|
149
|
+
return {
|
|
150
|
+
...this,
|
|
151
|
+
__internal: { ...this.__internal, hasDefault: true, defaultValue: value }
|
|
152
|
+
};
|
|
153
|
+
},
|
|
154
|
+
defaultFn(fn) {
|
|
155
|
+
return {
|
|
156
|
+
...this,
|
|
157
|
+
__internal: { ...this.__internal, hasDefault: true, defaultFn: fn }
|
|
158
|
+
};
|
|
159
|
+
},
|
|
160
|
+
autoIncrement() {
|
|
161
|
+
return {
|
|
162
|
+
...this,
|
|
163
|
+
__internal: { ...this.__internal, isAutoIncrement: true }
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
return intCol;
|
|
168
|
+
}
|
|
169
|
+
function boolean(name) {
|
|
170
|
+
return makeColumn({
|
|
171
|
+
name: name ?? "",
|
|
172
|
+
sqlType: "integer",
|
|
173
|
+
encode: (v) => v ? 1 : 0,
|
|
174
|
+
decode: (v) => v == null ? nullCast() : Boolean(v)
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function json(name) {
|
|
178
|
+
return makeColumn({
|
|
179
|
+
name: name ?? "",
|
|
180
|
+
sqlType: "text",
|
|
181
|
+
encode: (v) => v == null ? null : JSON.stringify(v),
|
|
182
|
+
decode: (v) => v == null ? nullCast() : JSON.parse(v)
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
function date(name) {
|
|
186
|
+
const base = makeColumn({
|
|
187
|
+
name: name ?? "",
|
|
188
|
+
sqlType: "integer",
|
|
189
|
+
encode: (v) => v == null ? null : v.getTime(),
|
|
190
|
+
decode: (v) => v == null ? nullCast() : new Date(v)
|
|
191
|
+
});
|
|
192
|
+
const dateCol = {
|
|
193
|
+
...base,
|
|
194
|
+
primaryKey() {
|
|
195
|
+
return { ...this, __internal: { ...this.__internal, isPrimaryKey: true } };
|
|
196
|
+
},
|
|
197
|
+
notNull() {
|
|
198
|
+
return { ...this, __internal: { ...this.__internal, isNotNull: true } };
|
|
199
|
+
},
|
|
200
|
+
unique() {
|
|
201
|
+
return { ...this, __internal: { ...this.__internal, isUnique: true } };
|
|
202
|
+
},
|
|
203
|
+
default(value) {
|
|
204
|
+
return { ...this, __internal: { ...this.__internal, hasDefault: true, defaultValue: value } };
|
|
205
|
+
},
|
|
206
|
+
defaultFn(fn) {
|
|
207
|
+
return { ...this, __internal: { ...this.__internal, hasDefault: true, defaultFn: fn } };
|
|
208
|
+
},
|
|
209
|
+
defaultNow() {
|
|
210
|
+
return { ...this, __internal: { ...this.__internal, hasDefaultNow: true } };
|
|
211
|
+
},
|
|
212
|
+
onUpdateTimestamp() {
|
|
213
|
+
return { ...this, __internal: { ...this.__internal, hasOnUpdate: true } };
|
|
214
|
+
}
|
|
215
|
+
};
|
|
216
|
+
return dateCol;
|
|
217
|
+
}
|
|
218
|
+
function real(name) {
|
|
219
|
+
return makeColumn({
|
|
220
|
+
name: name ?? "",
|
|
221
|
+
sqlType: "real",
|
|
222
|
+
encode: (v) => v,
|
|
223
|
+
decode: (v) => v == null ? nullCast() : Number(v)
|
|
224
|
+
});
|
|
225
|
+
}
|
|
226
|
+
// src/schema/table.ts
|
|
227
|
+
function table(name, columns, indexFn) {
|
|
228
|
+
const stamped = Object.create(null);
|
|
229
|
+
for (const [key, col] of Object.entries(columns)) {
|
|
230
|
+
const columnName = col.name || key;
|
|
231
|
+
const stampedInternal = { ...col.__internal, name: columnName, tableName: name };
|
|
232
|
+
const stampedCol = {
|
|
233
|
+
name: columnName,
|
|
234
|
+
__internal: stampedInternal,
|
|
235
|
+
primaryKey() {
|
|
236
|
+
return { ...this, __internal: { ...stampedInternal, isPrimaryKey: true } };
|
|
237
|
+
},
|
|
238
|
+
notNull() {
|
|
239
|
+
return { ...this, __internal: { ...stampedInternal, isNotNull: true } };
|
|
240
|
+
},
|
|
241
|
+
unique() {
|
|
242
|
+
return { ...this, __internal: { ...stampedInternal, isUnique: true } };
|
|
243
|
+
},
|
|
244
|
+
default(value) {
|
|
245
|
+
return {
|
|
246
|
+
...this,
|
|
247
|
+
__internal: { ...stampedInternal, hasDefault: true, defaultValue: value }
|
|
248
|
+
};
|
|
249
|
+
},
|
|
250
|
+
defaultFn(fn) {
|
|
251
|
+
return { ...this, __internal: { ...stampedInternal, hasDefault: true, defaultFn: fn } };
|
|
252
|
+
},
|
|
253
|
+
references(target) {
|
|
254
|
+
return {
|
|
255
|
+
...this,
|
|
256
|
+
__internal: {
|
|
257
|
+
...stampedInternal,
|
|
258
|
+
referencesTable: target.__internal.tableName,
|
|
259
|
+
referencesColumn: target.name
|
|
260
|
+
}
|
|
261
|
+
};
|
|
262
|
+
},
|
|
263
|
+
onDelete(action) {
|
|
264
|
+
return { ...this, __internal: { ...stampedInternal, onDelete: action } };
|
|
265
|
+
},
|
|
266
|
+
onUpdate(action) {
|
|
267
|
+
return { ...this, __internal: { ...stampedInternal, onUpdate: action } };
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
if ("autoIncrement" in col) {
|
|
271
|
+
stampedCol.autoIncrement = function() {
|
|
272
|
+
return { ...this, __internal: { ...stampedInternal, isAutoIncrement: true } };
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
if ("defaultNow" in col) {
|
|
276
|
+
stampedCol.defaultNow = function() {
|
|
277
|
+
return { ...this, __internal: { ...stampedInternal, hasDefaultNow: true } };
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
if ("onUpdateTimestamp" in col) {
|
|
281
|
+
stampedCol.onUpdateTimestamp = function() {
|
|
282
|
+
return { ...this, __internal: { ...stampedInternal, hasOnUpdate: true } };
|
|
283
|
+
};
|
|
284
|
+
}
|
|
285
|
+
stamped[key] = stampedCol;
|
|
286
|
+
}
|
|
287
|
+
const result = Object.assign(stamped, {
|
|
288
|
+
_: { name }
|
|
289
|
+
});
|
|
290
|
+
if (indexFn) {
|
|
291
|
+
const raw = indexFn(result);
|
|
292
|
+
if (raw.length > 0) {
|
|
293
|
+
const tableObj = result;
|
|
294
|
+
tableObj.__indexes = raw.map((item) => item.build());
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return result;
|
|
298
|
+
}
|
|
299
|
+
function toSnakeCase(str) {
|
|
300
|
+
return str.replace(/[A-Z]/g, (letter) => `_${letter.toLowerCase()}`);
|
|
301
|
+
}
|
|
302
|
+
function snakeCaseTable(tableName, columns, indexFn) {
|
|
303
|
+
const converted = {};
|
|
304
|
+
for (const [key, col] of Object.entries(columns)) {
|
|
305
|
+
const sqlName = toSnakeCase(key);
|
|
306
|
+
const columnName = col.name || sqlName;
|
|
307
|
+
const stampedInternal = { ...col.__internal, name: columnName, tableName };
|
|
308
|
+
const stampedCol = {
|
|
309
|
+
name: columnName,
|
|
310
|
+
__internal: stampedInternal,
|
|
311
|
+
primaryKey() {
|
|
312
|
+
return { ...this, __internal: { ...stampedInternal, isPrimaryKey: true } };
|
|
313
|
+
},
|
|
314
|
+
notNull() {
|
|
315
|
+
return { ...this, __internal: { ...stampedInternal, isNotNull: true } };
|
|
316
|
+
},
|
|
317
|
+
unique() {
|
|
318
|
+
return { ...this, __internal: { ...stampedInternal, isUnique: true } };
|
|
319
|
+
},
|
|
320
|
+
default(value) {
|
|
321
|
+
return {
|
|
322
|
+
...this,
|
|
323
|
+
__internal: { ...stampedInternal, hasDefault: true, defaultValue: value }
|
|
324
|
+
};
|
|
325
|
+
},
|
|
326
|
+
defaultFn(fn) {
|
|
327
|
+
return { ...this, __internal: { ...stampedInternal, hasDefault: true, defaultFn: fn } };
|
|
328
|
+
},
|
|
329
|
+
references(target) {
|
|
330
|
+
return {
|
|
331
|
+
...this,
|
|
332
|
+
__internal: {
|
|
333
|
+
...stampedInternal,
|
|
334
|
+
referencesTable: target.__internal.tableName,
|
|
335
|
+
referencesColumn: target.name
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
},
|
|
339
|
+
onDelete(action) {
|
|
340
|
+
return { ...this, __internal: { ...stampedInternal, onDelete: action } };
|
|
341
|
+
},
|
|
342
|
+
onUpdate(action) {
|
|
343
|
+
return { ...this, __internal: { ...stampedInternal, onUpdate: action } };
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
if ("autoIncrement" in col) {
|
|
347
|
+
stampedCol.autoIncrement = function() {
|
|
348
|
+
return { ...this, __internal: { ...stampedInternal, isAutoIncrement: true } };
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
if ("defaultNow" in col) {
|
|
352
|
+
stampedCol.defaultNow = function() {
|
|
353
|
+
return { ...this, __internal: { ...stampedInternal, hasDefaultNow: true } };
|
|
354
|
+
};
|
|
355
|
+
}
|
|
356
|
+
if ("onUpdateTimestamp" in col) {
|
|
357
|
+
stampedCol.onUpdateTimestamp = function() {
|
|
358
|
+
return { ...this, __internal: { ...stampedInternal, hasOnUpdate: true } };
|
|
359
|
+
};
|
|
360
|
+
}
|
|
361
|
+
converted[key] = stampedCol;
|
|
362
|
+
}
|
|
363
|
+
return table(tableName, converted, indexFn);
|
|
364
|
+
}
|
|
365
|
+
var snakeCase = {
|
|
366
|
+
table: snakeCaseTable
|
|
367
|
+
};
|
|
368
|
+
function index(name) {
|
|
369
|
+
let columns = [];
|
|
370
|
+
let isUnique = false;
|
|
371
|
+
const builder = {
|
|
372
|
+
on(...cols) {
|
|
373
|
+
columns = cols;
|
|
374
|
+
return builder;
|
|
375
|
+
},
|
|
376
|
+
unique() {
|
|
377
|
+
isUnique = true;
|
|
378
|
+
return builder;
|
|
379
|
+
},
|
|
380
|
+
build() {
|
|
381
|
+
if (columns.length === 0) {
|
|
382
|
+
throw new Error(`Index "${name}" has no columns \u2014 call .on() before returning`);
|
|
383
|
+
}
|
|
384
|
+
return {
|
|
385
|
+
name,
|
|
386
|
+
columns: columns.map((c) => c.name),
|
|
387
|
+
unique: isUnique
|
|
388
|
+
};
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
return builder;
|
|
392
|
+
}
|
|
393
|
+
export {
|
|
394
|
+
text,
|
|
395
|
+
table,
|
|
396
|
+
snakeCase,
|
|
397
|
+
real,
|
|
398
|
+
json,
|
|
399
|
+
integer,
|
|
400
|
+
index,
|
|
401
|
+
date,
|
|
402
|
+
boolean
|
|
403
|
+
};
|