flint-orm 0.4.3 → 0.4.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/dist/migration/types.d.ts +1 -0
- package/dist/src/cli.js +74 -59
- package/dist/src/migration/index.js +8 -19
- package/package.json +17 -8
package/dist/src/cli.js
CHANGED
|
@@ -275,6 +275,9 @@ function diffColumns(tableName, prevCols, currCols) {
|
|
|
275
275
|
if (prevCol.isPrimaryKey !== currCol.isPrimaryKey) {
|
|
276
276
|
unsafe = true;
|
|
277
277
|
}
|
|
278
|
+
if ((prevCol.isAutoIncrement ?? false) !== (currCol.isAutoIncrement ?? false)) {
|
|
279
|
+
unsafe = true;
|
|
280
|
+
}
|
|
278
281
|
if (prevCol.isNotNull !== currCol.isNotNull) {
|
|
279
282
|
if (prevCol.isNotNull && !currCol.isNotNull) {
|
|
280
283
|
unsafe = true;
|
|
@@ -529,6 +532,7 @@ function serializeColumn(col) {
|
|
|
529
532
|
name: col.name,
|
|
530
533
|
sqlType: internal.sqlType,
|
|
531
534
|
isPrimaryKey: internal.isPrimaryKey,
|
|
535
|
+
isAutoIncrement: internal.isAutoIncrement ?? false,
|
|
532
536
|
isNotNull: internal.isNotNull,
|
|
533
537
|
isUnique: internal.isUnique,
|
|
534
538
|
hasDefault: internal.hasDefault,
|
|
@@ -592,6 +596,8 @@ function columnToDDL(col) {
|
|
|
592
596
|
const parts = [col.name, sqlType(col)];
|
|
593
597
|
if (col.isPrimaryKey)
|
|
594
598
|
parts.push("PRIMARY KEY");
|
|
599
|
+
if (col.isAutoIncrement === true)
|
|
600
|
+
parts.push("AUTOINCREMENT");
|
|
595
601
|
if (col.isNotNull && !col.isPrimaryKey)
|
|
596
602
|
parts.push("NOT NULL");
|
|
597
603
|
if (col.isUnique && !col.isPrimaryKey)
|
|
@@ -775,24 +781,7 @@ function serializeOpArg(op) {
|
|
|
775
781
|
}
|
|
776
782
|
}
|
|
777
783
|
function serializeColumnArg(col) {
|
|
778
|
-
|
|
779
|
-
name: col.name,
|
|
780
|
-
sqlType: col.sqlType,
|
|
781
|
-
isPrimaryKey: col.isPrimaryKey,
|
|
782
|
-
isNotNull: col.isNotNull,
|
|
783
|
-
isUnique: col.isUnique,
|
|
784
|
-
hasDefault: col.hasDefault,
|
|
785
|
-
defaultValue: col.defaultValue
|
|
786
|
-
};
|
|
787
|
-
if (col.referencesTable && col.referencesColumn) {
|
|
788
|
-
obj.referencesTable = col.referencesTable;
|
|
789
|
-
obj.referencesColumn = col.referencesColumn;
|
|
790
|
-
if (col.onDelete)
|
|
791
|
-
obj.onDelete = col.onDelete;
|
|
792
|
-
if (col.onUpdate)
|
|
793
|
-
obj.onUpdate = col.onUpdate;
|
|
794
|
-
}
|
|
795
|
-
return JSON.stringify(obj);
|
|
784
|
+
return JSON.stringify(col);
|
|
796
785
|
}
|
|
797
786
|
function serializeIndexArg(idx) {
|
|
798
787
|
return `{ name: ${JSON.stringify(idx.name)}, columns: ${JSON.stringify(idx.columns)}, unique: ${idx.unique} }`;
|
|
@@ -832,7 +821,7 @@ async function generate(tables, migrationsDir, nameOrOptions) {
|
|
|
832
821
|
const migrationDir = join(migrationsDir, folderName);
|
|
833
822
|
mkdirSync(migrationDir, { recursive: true });
|
|
834
823
|
const uniqueOps = [...new Set(operations.map((op) => op.type))];
|
|
835
|
-
const imports = uniqueOps.map((op) => `import { ${op} } from "flint-orm/migration
|
|
824
|
+
const imports = uniqueOps.map((op) => `import { ${op} } from "flint-orm/migration";`).join(`
|
|
836
825
|
`);
|
|
837
826
|
const operationLines = operations.map((op) => {
|
|
838
827
|
const arg = serializeOpArg(op);
|
|
@@ -13666,48 +13655,74 @@ async function cmdMigrate(args, config) {
|
|
|
13666
13655
|
const isLocalDriver = config.driver === "bun-sqlite" || config.driver === "better-sqlite3";
|
|
13667
13656
|
const dbUrl = isLocalDriver ? resolve3(process.cwd(), config.database.url) : config.database.url;
|
|
13668
13657
|
let executor;
|
|
13669
|
-
|
|
13670
|
-
|
|
13671
|
-
|
|
13672
|
-
|
|
13673
|
-
|
|
13674
|
-
|
|
13675
|
-
|
|
13676
|
-
|
|
13677
|
-
|
|
13678
|
-
|
|
13679
|
-
|
|
13680
|
-
|
|
13681
|
-
|
|
13682
|
-
|
|
13683
|
-
|
|
13684
|
-
|
|
13685
|
-
|
|
13686
|
-
|
|
13687
|
-
|
|
13688
|
-
|
|
13689
|
-
|
|
13690
|
-
|
|
13691
|
-
|
|
13692
|
-
|
|
13693
|
-
|
|
13694
|
-
|
|
13695
|
-
|
|
13696
|
-
|
|
13697
|
-
|
|
13698
|
-
|
|
13699
|
-
|
|
13658
|
+
const DRIVER_PACKAGES = {
|
|
13659
|
+
"better-sqlite3": "better-sqlite3",
|
|
13660
|
+
libsql: "@libsql/client",
|
|
13661
|
+
"libsql-web": "@libsql/client",
|
|
13662
|
+
turso: "@tursodatabase/database",
|
|
13663
|
+
"turso-sync": "@tursodatabase/sync"
|
|
13664
|
+
};
|
|
13665
|
+
try {
|
|
13666
|
+
switch (config.driver) {
|
|
13667
|
+
case "bun-sqlite": {
|
|
13668
|
+
const { BunSqliteExecutor: BunSqliteExecutor2 } = await Promise.resolve().then(() => (init_bun_sqlite(), exports_bun_sqlite));
|
|
13669
|
+
const { Database: Database10 } = await import("bun:sqlite");
|
|
13670
|
+
executor = new BunSqliteExecutor2(new Database10(dbUrl));
|
|
13671
|
+
break;
|
|
13672
|
+
}
|
|
13673
|
+
case "better-sqlite3": {
|
|
13674
|
+
const { BetterSqlite3Executor: BetterSqlite3Executor2 } = await Promise.resolve().then(() => (init_better_sqlite3(), exports_better_sqlite3));
|
|
13675
|
+
const Database10 = (await Promise.resolve().then(() => __toESM(require_lib(), 1))).default;
|
|
13676
|
+
executor = new BetterSqlite3Executor2(new Database10(dbUrl));
|
|
13677
|
+
break;
|
|
13678
|
+
}
|
|
13679
|
+
case "libsql": {
|
|
13680
|
+
const { LibsqlExecutor: LibsqlExecutor2 } = await Promise.resolve().then(() => (init_libsql(), exports_libsql));
|
|
13681
|
+
const { createClient: createLibsqlClient } = await Promise.resolve().then(() => (init_node(), exports_node));
|
|
13682
|
+
executor = new LibsqlExecutor2(createLibsqlClient({ url: dbUrl, authToken: config.database.authToken }));
|
|
13683
|
+
break;
|
|
13684
|
+
}
|
|
13685
|
+
case "libsql-web": {
|
|
13686
|
+
const { LibsqlWebExecutor: LibsqlWebExecutor2 } = await Promise.resolve().then(() => (init_libsql_web(), exports_libsql_web));
|
|
13687
|
+
const { createClient: createLibsqlWebClient } = await Promise.resolve().then(() => (init_web2(), exports_web));
|
|
13688
|
+
executor = new LibsqlWebExecutor2(createLibsqlWebClient({ url: dbUrl, authToken: config.database.authToken }));
|
|
13689
|
+
break;
|
|
13690
|
+
}
|
|
13691
|
+
case "turso-sync": {
|
|
13692
|
+
const { TursoSyncExecutor: TursoSyncExecutor2 } = await Promise.resolve().then(() => (init_turso_sync(), exports_turso_sync));
|
|
13693
|
+
const { connect: connect4 } = await Promise.resolve().then(() => (init_promise2(), exports_promise));
|
|
13694
|
+
const db = await connect4({ path: dbUrl, authToken: config.database.authToken });
|
|
13695
|
+
executor = new TursoSyncExecutor2(db);
|
|
13696
|
+
break;
|
|
13697
|
+
}
|
|
13698
|
+
case "turso": {
|
|
13699
|
+
const { TursoExecutor: TursoExecutor2 } = await Promise.resolve().then(() => (init_turso(), exports_turso));
|
|
13700
|
+
const { connect: connect4 } = await Promise.resolve().then(() => (init_promise3(), exports_promise2));
|
|
13701
|
+
const db = await connect4(dbUrl);
|
|
13702
|
+
executor = new TursoExecutor2(db);
|
|
13703
|
+
break;
|
|
13704
|
+
}
|
|
13705
|
+
default:
|
|
13706
|
+
cancel(`Unsupported driver: ${config.driver}`);
|
|
13707
|
+
process.exit(1);
|
|
13700
13708
|
}
|
|
13701
|
-
|
|
13702
|
-
|
|
13703
|
-
|
|
13704
|
-
|
|
13705
|
-
|
|
13706
|
-
|
|
13709
|
+
} catch (err) {
|
|
13710
|
+
const msg = err instanceof Error ? err.message : String(err);
|
|
13711
|
+
const pkg = DRIVER_PACKAGES[config.driver];
|
|
13712
|
+
if (pkg && (msg.includes("Cannot find module") || msg.includes("ERR_MODULE_NOT_FOUND") || msg.includes("not found"))) {
|
|
13713
|
+
const installCmd = pkg === "@libsql/client" ? "npm install @libsql/client" : `npm install ${pkg}`;
|
|
13714
|
+
note(`Driver "${config.driver}" is not installed.
|
|
13715
|
+
|
|
13716
|
+
Install it with:
|
|
13717
|
+
|
|
13718
|
+
${import_picocolors.default.dim(installCmd)}
|
|
13719
|
+
`, "Missing driver");
|
|
13720
|
+
} else {
|
|
13721
|
+
note(`Failed to load driver "${config.driver}":
|
|
13722
|
+
|
|
13723
|
+
${import_picocolors.default.dim(msg)}`, "Error");
|
|
13707
13724
|
}
|
|
13708
|
-
|
|
13709
|
-
cancel(`Unsupported driver: ${config.driver}`);
|
|
13710
|
-
process.exit(1);
|
|
13725
|
+
process.exit(1);
|
|
13711
13726
|
}
|
|
13712
13727
|
try {
|
|
13713
13728
|
if (statusOnly) {
|
|
@@ -57,6 +57,7 @@ function serializeColumn(col) {
|
|
|
57
57
|
name: col.name,
|
|
58
58
|
sqlType: internal.sqlType,
|
|
59
59
|
isPrimaryKey: internal.isPrimaryKey,
|
|
60
|
+
isAutoIncrement: internal.isAutoIncrement ?? false,
|
|
60
61
|
isNotNull: internal.isNotNull,
|
|
61
62
|
isUnique: internal.isUnique,
|
|
62
63
|
hasDefault: internal.hasDefault,
|
|
@@ -207,6 +208,9 @@ function diffColumns(tableName, prevCols, currCols) {
|
|
|
207
208
|
if (prevCol.isPrimaryKey !== currCol.isPrimaryKey) {
|
|
208
209
|
unsafe = true;
|
|
209
210
|
}
|
|
211
|
+
if ((prevCol.isAutoIncrement ?? false) !== (currCol.isAutoIncrement ?? false)) {
|
|
212
|
+
unsafe = true;
|
|
213
|
+
}
|
|
210
214
|
if (prevCol.isNotNull !== currCol.isNotNull) {
|
|
211
215
|
if (prevCol.isNotNull && !currCol.isNotNull) {
|
|
212
216
|
unsafe = true;
|
|
@@ -463,6 +467,8 @@ function columnToDDL(col) {
|
|
|
463
467
|
const parts = [col.name, sqlType(col)];
|
|
464
468
|
if (col.isPrimaryKey)
|
|
465
469
|
parts.push("PRIMARY KEY");
|
|
470
|
+
if (col.isAutoIncrement === true)
|
|
471
|
+
parts.push("AUTOINCREMENT");
|
|
466
472
|
if (col.isNotNull && !col.isPrimaryKey)
|
|
467
473
|
parts.push("NOT NULL");
|
|
468
474
|
if (col.isUnique && !col.isPrimaryKey)
|
|
@@ -646,24 +652,7 @@ function serializeOpArg(op) {
|
|
|
646
652
|
}
|
|
647
653
|
}
|
|
648
654
|
function serializeColumnArg(col) {
|
|
649
|
-
|
|
650
|
-
name: col.name,
|
|
651
|
-
sqlType: col.sqlType,
|
|
652
|
-
isPrimaryKey: col.isPrimaryKey,
|
|
653
|
-
isNotNull: col.isNotNull,
|
|
654
|
-
isUnique: col.isUnique,
|
|
655
|
-
hasDefault: col.hasDefault,
|
|
656
|
-
defaultValue: col.defaultValue
|
|
657
|
-
};
|
|
658
|
-
if (col.referencesTable && col.referencesColumn) {
|
|
659
|
-
obj.referencesTable = col.referencesTable;
|
|
660
|
-
obj.referencesColumn = col.referencesColumn;
|
|
661
|
-
if (col.onDelete)
|
|
662
|
-
obj.onDelete = col.onDelete;
|
|
663
|
-
if (col.onUpdate)
|
|
664
|
-
obj.onUpdate = col.onUpdate;
|
|
665
|
-
}
|
|
666
|
-
return JSON.stringify(obj);
|
|
655
|
+
return JSON.stringify(col);
|
|
667
656
|
}
|
|
668
657
|
function serializeIndexArg(idx) {
|
|
669
658
|
return `{ name: ${JSON.stringify(idx.name)}, columns: ${JSON.stringify(idx.columns)}, unique: ${idx.unique} }`;
|
|
@@ -703,7 +692,7 @@ async function generate(tables, migrationsDir, nameOrOptions) {
|
|
|
703
692
|
const migrationDir = join(migrationsDir, folderName);
|
|
704
693
|
mkdirSync(migrationDir, { recursive: true });
|
|
705
694
|
const uniqueOps = [...new Set(operations.map((op) => op.type))];
|
|
706
|
-
const imports = uniqueOps.map((op) => `import { ${op} } from "flint-orm/migration
|
|
695
|
+
const imports = uniqueOps.map((op) => `import { ${op} } from "flint-orm/migration";`).join(`
|
|
707
696
|
`);
|
|
708
697
|
const operationLines = operations.map((op) => {
|
|
709
698
|
const arg = serializeOpArg(op);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flint-orm",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"bin": {
|
|
5
5
|
"flint": "./dist/src/cli.js"
|
|
6
6
|
},
|
|
@@ -65,22 +65,31 @@
|
|
|
65
65
|
"format": "oxfmt --write",
|
|
66
66
|
"check": "oxlint && oxfmt"
|
|
67
67
|
},
|
|
68
|
-
"dependencies": {
|
|
68
|
+
"dependencies": {},
|
|
69
|
+
"devDependencies": {
|
|
69
70
|
"@clack/prompts": "1.7.0",
|
|
70
71
|
"@libsql/client": "0.17.4",
|
|
71
72
|
"@tursodatabase/database": "0.6.1",
|
|
72
73
|
"@tursodatabase/sync": "0.6.1",
|
|
73
|
-
"better-sqlite3": "12.11.1",
|
|
74
|
-
"picocolors": "1.1.1"
|
|
75
|
-
},
|
|
76
|
-
"devDependencies": {
|
|
77
74
|
"@types/better-sqlite3": "7.6.13",
|
|
78
75
|
"@types/bun": "1.3.14",
|
|
79
76
|
"@types/node": "26.1.1",
|
|
77
|
+
"better-sqlite3": "12.11.1",
|
|
80
78
|
"oxfmt": "0.57.0",
|
|
81
|
-
"oxlint": "1.72.0"
|
|
79
|
+
"oxlint": "1.72.0",
|
|
80
|
+
"picocolors": "1.1.1"
|
|
82
81
|
},
|
|
83
82
|
"peerDependencies": {
|
|
84
|
-
"
|
|
83
|
+
"@libsql/client": ">=0.17.4",
|
|
84
|
+
"@tursodatabase/database": ">=0.6.1",
|
|
85
|
+
"@tursodatabase/sync": ">=0.6.1",
|
|
86
|
+
"better-sqlite3": ">=12.11.1",
|
|
87
|
+
"typescript": ">=5.0.0"
|
|
88
|
+
},
|
|
89
|
+
"peerDependenciesMeta": {
|
|
90
|
+
"@libsql/client": { "optional": true },
|
|
91
|
+
"@tursodatabase/database": { "optional": true },
|
|
92
|
+
"@tursodatabase/sync": { "optional": true },
|
|
93
|
+
"better-sqlite3": { "optional": true }
|
|
85
94
|
}
|
|
86
95
|
}
|