flint-orm 0.4.4 → 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.
@@ -3,6 +3,7 @@ export interface SerializedColumn {
3
3
  name: string;
4
4
  sqlType: 'text' | 'integer' | 'real' | 'blob';
5
5
  isPrimaryKey: boolean;
6
+ isAutoIncrement?: boolean;
6
7
  isNotNull: boolean;
7
8
  isUnique: boolean;
8
9
  hasDefault: boolean;
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
- const obj = {
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/operations";`).join(`
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);
@@ -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
- const obj = {
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/operations";`).join(`
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.4",
3
+ "version": "0.4.5",
4
4
  "bin": {
5
5
  "flint": "./dist/src/cli.js"
6
6
  },