@type32/tauri-sqlite-orm 0.1.18-14 → 0.1.18-17

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/index.d.mts CHANGED
@@ -65,7 +65,7 @@ declare class SelectQueryBuilder<TTable extends AnyTable, TSelectedColumns exten
65
65
  having(condition: SQLCondition): this;
66
66
  leftJoin<T extends AnyTable>(table: T, condition: SQLCondition, alias: string): this;
67
67
  innerJoin<T extends AnyTable>(table: T, condition: SQLCondition, alias: string): this;
68
- include(relations: Record<string, boolean>): this;
68
+ include(relations: Partial<Record<keyof TTable['relations'], boolean>>): this;
69
69
  private buildJoins;
70
70
  execute(): Promise<any[]>;
71
71
  private processRelationResults;
@@ -138,7 +138,7 @@ type RelationsBuilder = {
138
138
  many: <U extends AnyTable>(table: U) => ManyRelation<U>;
139
139
  };
140
140
 
141
- declare class SQLiteColumn<TName extends string = string, TType extends ColumnDataType = ColumnDataType, TMode extends Mode = "default", TNotNull extends boolean = false, THasDefault extends boolean = false, TAutoincrement extends boolean = false> {
141
+ declare class SQLiteColumn<TName extends string = string, TType extends ColumnDataType = ColumnDataType, TMode extends Mode = 'default', TNotNull extends boolean = false, THasDefault extends boolean = false, TAutoincrement extends boolean = false> {
142
142
  type: TType;
143
143
  options: ColumnOptions<ColumnValueTypes<TType, TMode>>;
144
144
  _: {
@@ -156,11 +156,11 @@ declare class SQLiteColumn<TName extends string = string, TType extends ColumnDa
156
156
  primaryKey(): SQLiteColumn<TName, TType, TMode, true, THasDefault, TAutoincrement>;
157
157
  autoincrement(): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, true>;
158
158
  unique(): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
159
- references<T extends AnyTable, K extends keyof T["_"]["columns"] & string>(ref: T, column: K): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
159
+ references<T extends AnyTable, K extends keyof T['_']['columns'] & string>(ref: T, column: K): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
160
160
  $onUpdateFn(fn: () => ColumnValueTypes<TType, TMode>): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
161
161
  as(alias: string): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
162
162
  }
163
- type IsOptionalOnInsert<C extends AnySQLiteColumn> = C["_"]["notNull"] extends false ? true : C["_"]["hasDefault"] extends true ? true : C["_"]["autoincrement"] extends true ? true : false;
163
+ type IsOptionalOnInsert<C extends AnySQLiteColumn> = C['_']['notNull'] extends false ? true : C['_']['hasDefault'] extends true ? true : C['_']['autoincrement'] extends true ? true : false;
164
164
  type OptionalColumns<TColumns extends Record<string, AnySQLiteColumn>> = {
165
165
  [K in keyof TColumns]: IsOptionalOnInsert<TColumns[K]> extends true ? K : never;
166
166
  }[keyof TColumns];
@@ -168,9 +168,9 @@ type RequiredColumns<TColumns extends Record<string, AnySQLiteColumn>> = {
168
168
  [K in keyof TColumns]: IsOptionalOnInsert<TColumns[K]> extends true ? never : K;
169
169
  }[keyof TColumns];
170
170
  type InferInsertModel<T extends AnyTable> = {
171
- [K in RequiredColumns<T["_"]["columns"]>]: ExtractColumnType<T["_"]["columns"][K]>;
171
+ [K in RequiredColumns<T['_']['columns']>]: ExtractColumnType<T['_']['columns'][K]>;
172
172
  } & {
173
- [K in OptionalColumns<T["_"]["columns"]>]?: ExtractColumnType<T["_"]["columns"][K]>;
173
+ [K in OptionalColumns<T['_']['columns']>]?: ExtractColumnType<T['_']['columns'][K]>;
174
174
  };
175
175
  declare class Table<TColumns extends Record<string, AnySQLiteColumn>, TTableName extends string> {
176
176
  _: {
@@ -204,7 +204,7 @@ declare class TauriORM {
204
204
  constructor(db: Database, schema?: Record<string, AnyTable | Record<string, Relation>> | undefined);
205
205
  private buildColumnDefinition;
206
206
  migrate(): Promise<void>;
207
- select<T extends AnyTable, C extends (keyof T["_"]["columns"])[] | undefined = undefined>(table: T, columns?: C): SelectQueryBuilder<T, C>;
207
+ select<T extends AnyTable, C extends (keyof T['_']['columns'])[] | undefined = undefined>(table: T, columns?: C): SelectQueryBuilder<T, C>;
208
208
  insert<T extends AnyTable>(table: T): InsertQueryBuilder<T>;
209
209
  update<T extends AnyTable>(table: T): UpdateQueryBuilder<T>;
210
210
  delete<T extends AnyTable>(table: T): DeleteQueryBuilder<T>;
package/dist/index.d.ts CHANGED
@@ -65,7 +65,7 @@ declare class SelectQueryBuilder<TTable extends AnyTable, TSelectedColumns exten
65
65
  having(condition: SQLCondition): this;
66
66
  leftJoin<T extends AnyTable>(table: T, condition: SQLCondition, alias: string): this;
67
67
  innerJoin<T extends AnyTable>(table: T, condition: SQLCondition, alias: string): this;
68
- include(relations: Record<string, boolean>): this;
68
+ include(relations: Partial<Record<keyof TTable['relations'], boolean>>): this;
69
69
  private buildJoins;
70
70
  execute(): Promise<any[]>;
71
71
  private processRelationResults;
@@ -138,7 +138,7 @@ type RelationsBuilder = {
138
138
  many: <U extends AnyTable>(table: U) => ManyRelation<U>;
139
139
  };
140
140
 
141
- declare class SQLiteColumn<TName extends string = string, TType extends ColumnDataType = ColumnDataType, TMode extends Mode = "default", TNotNull extends boolean = false, THasDefault extends boolean = false, TAutoincrement extends boolean = false> {
141
+ declare class SQLiteColumn<TName extends string = string, TType extends ColumnDataType = ColumnDataType, TMode extends Mode = 'default', TNotNull extends boolean = false, THasDefault extends boolean = false, TAutoincrement extends boolean = false> {
142
142
  type: TType;
143
143
  options: ColumnOptions<ColumnValueTypes<TType, TMode>>;
144
144
  _: {
@@ -156,11 +156,11 @@ declare class SQLiteColumn<TName extends string = string, TType extends ColumnDa
156
156
  primaryKey(): SQLiteColumn<TName, TType, TMode, true, THasDefault, TAutoincrement>;
157
157
  autoincrement(): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, true>;
158
158
  unique(): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
159
- references<T extends AnyTable, K extends keyof T["_"]["columns"] & string>(ref: T, column: K): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
159
+ references<T extends AnyTable, K extends keyof T['_']['columns'] & string>(ref: T, column: K): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
160
160
  $onUpdateFn(fn: () => ColumnValueTypes<TType, TMode>): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
161
161
  as(alias: string): SQLiteColumn<TName, TType, TMode, TNotNull, THasDefault, TAutoincrement>;
162
162
  }
163
- type IsOptionalOnInsert<C extends AnySQLiteColumn> = C["_"]["notNull"] extends false ? true : C["_"]["hasDefault"] extends true ? true : C["_"]["autoincrement"] extends true ? true : false;
163
+ type IsOptionalOnInsert<C extends AnySQLiteColumn> = C['_']['notNull'] extends false ? true : C['_']['hasDefault'] extends true ? true : C['_']['autoincrement'] extends true ? true : false;
164
164
  type OptionalColumns<TColumns extends Record<string, AnySQLiteColumn>> = {
165
165
  [K in keyof TColumns]: IsOptionalOnInsert<TColumns[K]> extends true ? K : never;
166
166
  }[keyof TColumns];
@@ -168,9 +168,9 @@ type RequiredColumns<TColumns extends Record<string, AnySQLiteColumn>> = {
168
168
  [K in keyof TColumns]: IsOptionalOnInsert<TColumns[K]> extends true ? never : K;
169
169
  }[keyof TColumns];
170
170
  type InferInsertModel<T extends AnyTable> = {
171
- [K in RequiredColumns<T["_"]["columns"]>]: ExtractColumnType<T["_"]["columns"][K]>;
171
+ [K in RequiredColumns<T['_']['columns']>]: ExtractColumnType<T['_']['columns'][K]>;
172
172
  } & {
173
- [K in OptionalColumns<T["_"]["columns"]>]?: ExtractColumnType<T["_"]["columns"][K]>;
173
+ [K in OptionalColumns<T['_']['columns']>]?: ExtractColumnType<T['_']['columns'][K]>;
174
174
  };
175
175
  declare class Table<TColumns extends Record<string, AnySQLiteColumn>, TTableName extends string> {
176
176
  _: {
@@ -204,7 +204,7 @@ declare class TauriORM {
204
204
  constructor(db: Database, schema?: Record<string, AnyTable | Record<string, Relation>> | undefined);
205
205
  private buildColumnDefinition;
206
206
  migrate(): Promise<void>;
207
- select<T extends AnyTable, C extends (keyof T["_"]["columns"])[] | undefined = undefined>(table: T, columns?: C): SelectQueryBuilder<T, C>;
207
+ select<T extends AnyTable, C extends (keyof T['_']['columns'])[] | undefined = undefined>(table: T, columns?: C): SelectQueryBuilder<T, C>;
208
208
  insert<T extends AnyTable>(table: T): InsertQueryBuilder<T>;
209
209
  update<T extends AnyTable>(table: T): UpdateQueryBuilder<T>;
210
210
  delete<T extends AnyTable>(table: T): DeleteQueryBuilder<T>;
package/dist/index.js CHANGED
@@ -236,7 +236,12 @@ var SelectQueryBuilder = class extends BaseQueryBuilder {
236
236
  for (const [relationName, include] of Object.entries(this.includeRelations)) {
237
237
  if (!include) continue;
238
238
  const relation = this.table.relations[relationName];
239
- if (!relation) continue;
239
+ if (!relation) {
240
+ console.warn(
241
+ `[Tauri-ORM] Relation "${relationName}" not found on table "${this.table._.name}". Skipping include.`
242
+ );
243
+ continue;
244
+ }
240
245
  const foreignTable = relation.foreignTable;
241
246
  const foreignAlias = `${this.selectedTableAlias}_${relationName}`;
242
247
  this.selectedColumns.push(`${foreignAlias}.*`);
@@ -621,28 +626,13 @@ var SQLiteColumn = class _SQLiteColumn {
621
626
  }
622
627
  _;
623
628
  notNull() {
624
- return new _SQLiteColumn(
625
- this._.name,
626
- this.type,
627
- { ...this.options, notNull: true },
628
- this._.mode
629
- );
629
+ return new _SQLiteColumn(this._.name, this.type, { ...this.options, notNull: true }, this._.mode);
630
630
  }
631
631
  default(value) {
632
- return new _SQLiteColumn(
633
- this._.name,
634
- this.type,
635
- { ...this.options, default: value },
636
- this._.mode
637
- );
632
+ return new _SQLiteColumn(this._.name, this.type, { ...this.options, default: value }, this._.mode);
638
633
  }
639
634
  $defaultFn(fn) {
640
- return new _SQLiteColumn(
641
- this._.name,
642
- this.type,
643
- { ...this.options, $defaultFn: fn },
644
- this._.mode
645
- );
635
+ return new _SQLiteColumn(this._.name, this.type, { ...this.options, $defaultFn: fn }, this._.mode);
646
636
  }
647
637
  primaryKey() {
648
638
  return new _SQLiteColumn(
@@ -653,20 +643,10 @@ var SQLiteColumn = class _SQLiteColumn {
653
643
  );
654
644
  }
655
645
  autoincrement() {
656
- return new _SQLiteColumn(
657
- this._.name,
658
- this.type,
659
- { ...this.options, autoincrement: true },
660
- this._.mode
661
- );
646
+ return new _SQLiteColumn(this._.name, this.type, { ...this.options, autoincrement: true }, this._.mode);
662
647
  }
663
648
  unique() {
664
- return new _SQLiteColumn(
665
- this._.name,
666
- this.type,
667
- { ...this.options, unique: true },
668
- this._.mode
669
- );
649
+ return new _SQLiteColumn(this._.name, this.type, { ...this.options, unique: true }, this._.mode);
670
650
  }
671
651
  references(ref, column) {
672
652
  return new _SQLiteColumn(
@@ -683,12 +663,7 @@ var SQLiteColumn = class _SQLiteColumn {
683
663
  );
684
664
  }
685
665
  $onUpdateFn(fn) {
686
- return new _SQLiteColumn(
687
- this._.name,
688
- this.type,
689
- { ...this.options, $onUpdateFn: fn },
690
- this._.mode
691
- );
666
+ return new _SQLiteColumn(this._.name, this.type, { ...this.options, $onUpdateFn: fn }, this._.mode);
692
667
  }
693
668
  as(alias2) {
694
669
  return this;
@@ -791,9 +766,7 @@ var TauriORM = class {
791
766
  }
792
767
  async migrate() {
793
768
  for (const table of this.tables.values()) {
794
- const existingTableInfo = await this.db.select(
795
- `PRAGMA table_info('${table._.name}')`
796
- );
769
+ const existingTableInfo = await this.db.select(`PRAGMA table_info('${table._.name}')`);
797
770
  if (existingTableInfo.length === 0) {
798
771
  const columnsSql = Object.values(table._.columns).map((col) => this.buildColumnDefinition(col)).join(", ");
799
772
  const createSql = `CREATE TABLE ${table._.name}
@@ -802,9 +775,7 @@ var TauriORM = class {
802
775
  )`;
803
776
  await this.db.execute(createSql);
804
777
  } else {
805
- const existingColumnNames = new Set(
806
- existingTableInfo.map((c) => c.name)
807
- );
778
+ const existingColumnNames = new Set(existingTableInfo.map((c) => c.name));
808
779
  for (const column of Object.values(table._.columns)) {
809
780
  if (!existingColumnNames.has(column._.name)) {
810
781
  const columnSql = this.buildColumnDefinition(column, true);
@@ -817,7 +788,14 @@ var TauriORM = class {
817
788
  }
818
789
  }
819
790
  select(table, columns) {
820
- return new SelectQueryBuilder(this.db, table, columns);
791
+ const internalTable = this.tables.get(table._.name);
792
+ if (!internalTable) {
793
+ console.warn(
794
+ `[Tauri-ORM] Table "${table._.name}" was not passed in the schema to the ORM constructor. Relations will not be available.`
795
+ );
796
+ return new SelectQueryBuilder(this.db, table, columns);
797
+ }
798
+ return new SelectQueryBuilder(this.db, internalTable, columns);
821
799
  }
822
800
  insert(table) {
823
801
  return new InsertQueryBuilder(this.db, table);
@@ -920,10 +898,7 @@ var TauriORM = class {
920
898
  const status = await this.isSchemaDirty();
921
899
  if (status.dirty) {
922
900
  await this.migrate();
923
- await this.setSchemaMeta(
924
- "schema_signature",
925
- this.computeModelSignature()
926
- );
901
+ await this.setSchemaMeta("schema_signature", this.computeModelSignature());
927
902
  return true;
928
903
  }
929
904
  return false;
package/dist/index.mjs CHANGED
@@ -169,7 +169,12 @@ var SelectQueryBuilder = class extends BaseQueryBuilder {
169
169
  for (const [relationName, include] of Object.entries(this.includeRelations)) {
170
170
  if (!include) continue;
171
171
  const relation = this.table.relations[relationName];
172
- if (!relation) continue;
172
+ if (!relation) {
173
+ console.warn(
174
+ `[Tauri-ORM] Relation "${relationName}" not found on table "${this.table._.name}". Skipping include.`
175
+ );
176
+ continue;
177
+ }
173
178
  const foreignTable = relation.foreignTable;
174
179
  const foreignAlias = `${this.selectedTableAlias}_${relationName}`;
175
180
  this.selectedColumns.push(`${foreignAlias}.*`);
@@ -554,28 +559,13 @@ var SQLiteColumn = class _SQLiteColumn {
554
559
  }
555
560
  _;
556
561
  notNull() {
557
- return new _SQLiteColumn(
558
- this._.name,
559
- this.type,
560
- { ...this.options, notNull: true },
561
- this._.mode
562
- );
562
+ return new _SQLiteColumn(this._.name, this.type, { ...this.options, notNull: true }, this._.mode);
563
563
  }
564
564
  default(value) {
565
- return new _SQLiteColumn(
566
- this._.name,
567
- this.type,
568
- { ...this.options, default: value },
569
- this._.mode
570
- );
565
+ return new _SQLiteColumn(this._.name, this.type, { ...this.options, default: value }, this._.mode);
571
566
  }
572
567
  $defaultFn(fn) {
573
- return new _SQLiteColumn(
574
- this._.name,
575
- this.type,
576
- { ...this.options, $defaultFn: fn },
577
- this._.mode
578
- );
568
+ return new _SQLiteColumn(this._.name, this.type, { ...this.options, $defaultFn: fn }, this._.mode);
579
569
  }
580
570
  primaryKey() {
581
571
  return new _SQLiteColumn(
@@ -586,20 +576,10 @@ var SQLiteColumn = class _SQLiteColumn {
586
576
  );
587
577
  }
588
578
  autoincrement() {
589
- return new _SQLiteColumn(
590
- this._.name,
591
- this.type,
592
- { ...this.options, autoincrement: true },
593
- this._.mode
594
- );
579
+ return new _SQLiteColumn(this._.name, this.type, { ...this.options, autoincrement: true }, this._.mode);
595
580
  }
596
581
  unique() {
597
- return new _SQLiteColumn(
598
- this._.name,
599
- this.type,
600
- { ...this.options, unique: true },
601
- this._.mode
602
- );
582
+ return new _SQLiteColumn(this._.name, this.type, { ...this.options, unique: true }, this._.mode);
603
583
  }
604
584
  references(ref, column) {
605
585
  return new _SQLiteColumn(
@@ -616,12 +596,7 @@ var SQLiteColumn = class _SQLiteColumn {
616
596
  );
617
597
  }
618
598
  $onUpdateFn(fn) {
619
- return new _SQLiteColumn(
620
- this._.name,
621
- this.type,
622
- { ...this.options, $onUpdateFn: fn },
623
- this._.mode
624
- );
599
+ return new _SQLiteColumn(this._.name, this.type, { ...this.options, $onUpdateFn: fn }, this._.mode);
625
600
  }
626
601
  as(alias2) {
627
602
  return this;
@@ -724,9 +699,7 @@ var TauriORM = class {
724
699
  }
725
700
  async migrate() {
726
701
  for (const table of this.tables.values()) {
727
- const existingTableInfo = await this.db.select(
728
- `PRAGMA table_info('${table._.name}')`
729
- );
702
+ const existingTableInfo = await this.db.select(`PRAGMA table_info('${table._.name}')`);
730
703
  if (existingTableInfo.length === 0) {
731
704
  const columnsSql = Object.values(table._.columns).map((col) => this.buildColumnDefinition(col)).join(", ");
732
705
  const createSql = `CREATE TABLE ${table._.name}
@@ -735,9 +708,7 @@ var TauriORM = class {
735
708
  )`;
736
709
  await this.db.execute(createSql);
737
710
  } else {
738
- const existingColumnNames = new Set(
739
- existingTableInfo.map((c) => c.name)
740
- );
711
+ const existingColumnNames = new Set(existingTableInfo.map((c) => c.name));
741
712
  for (const column of Object.values(table._.columns)) {
742
713
  if (!existingColumnNames.has(column._.name)) {
743
714
  const columnSql = this.buildColumnDefinition(column, true);
@@ -750,7 +721,14 @@ var TauriORM = class {
750
721
  }
751
722
  }
752
723
  select(table, columns) {
753
- return new SelectQueryBuilder(this.db, table, columns);
724
+ const internalTable = this.tables.get(table._.name);
725
+ if (!internalTable) {
726
+ console.warn(
727
+ `[Tauri-ORM] Table "${table._.name}" was not passed in the schema to the ORM constructor. Relations will not be available.`
728
+ );
729
+ return new SelectQueryBuilder(this.db, table, columns);
730
+ }
731
+ return new SelectQueryBuilder(this.db, internalTable, columns);
754
732
  }
755
733
  insert(table) {
756
734
  return new InsertQueryBuilder(this.db, table);
@@ -853,10 +831,7 @@ var TauriORM = class {
853
831
  const status = await this.isSchemaDirty();
854
832
  if (status.dirty) {
855
833
  await this.migrate();
856
- await this.setSchemaMeta(
857
- "schema_signature",
858
- this.computeModelSignature()
859
- );
834
+ await this.setSchemaMeta("schema_signature", this.computeModelSignature());
860
835
  return true;
861
836
  }
862
837
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@type32/tauri-sqlite-orm",
3
- "version": "0.1.18-14",
3
+ "version": "0.1.18-17",
4
4
  "description": "A Drizzle-like ORM for Tauri v2's SQL JS API plugin.",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",