@type32/tauri-sqlite-orm 0.1.18-16 → 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 +6 -6
- package/dist/index.d.ts +6 -6
- package/dist/index.js +17 -47
- package/dist/index.mjs +17 -47
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -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 =
|
|
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[
|
|
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[
|
|
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[
|
|
171
|
+
[K in RequiredColumns<T['_']['columns']>]: ExtractColumnType<T['_']['columns'][K]>;
|
|
172
172
|
} & {
|
|
173
|
-
[K in OptionalColumns<T[
|
|
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[
|
|
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
|
@@ -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 =
|
|
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[
|
|
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[
|
|
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[
|
|
171
|
+
[K in RequiredColumns<T['_']['columns']>]: ExtractColumnType<T['_']['columns'][K]>;
|
|
172
172
|
} & {
|
|
173
|
-
[K in OptionalColumns<T[
|
|
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[
|
|
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
|
@@ -626,28 +626,13 @@ var SQLiteColumn = class _SQLiteColumn {
|
|
|
626
626
|
}
|
|
627
627
|
_;
|
|
628
628
|
notNull() {
|
|
629
|
-
return new _SQLiteColumn(
|
|
630
|
-
this._.name,
|
|
631
|
-
this.type,
|
|
632
|
-
{ ...this.options, notNull: true },
|
|
633
|
-
this._.mode
|
|
634
|
-
);
|
|
629
|
+
return new _SQLiteColumn(this._.name, this.type, { ...this.options, notNull: true }, this._.mode);
|
|
635
630
|
}
|
|
636
631
|
default(value) {
|
|
637
|
-
return new _SQLiteColumn(
|
|
638
|
-
this._.name,
|
|
639
|
-
this.type,
|
|
640
|
-
{ ...this.options, default: value },
|
|
641
|
-
this._.mode
|
|
642
|
-
);
|
|
632
|
+
return new _SQLiteColumn(this._.name, this.type, { ...this.options, default: value }, this._.mode);
|
|
643
633
|
}
|
|
644
634
|
$defaultFn(fn) {
|
|
645
|
-
return new _SQLiteColumn(
|
|
646
|
-
this._.name,
|
|
647
|
-
this.type,
|
|
648
|
-
{ ...this.options, $defaultFn: fn },
|
|
649
|
-
this._.mode
|
|
650
|
-
);
|
|
635
|
+
return new _SQLiteColumn(this._.name, this.type, { ...this.options, $defaultFn: fn }, this._.mode);
|
|
651
636
|
}
|
|
652
637
|
primaryKey() {
|
|
653
638
|
return new _SQLiteColumn(
|
|
@@ -658,20 +643,10 @@ var SQLiteColumn = class _SQLiteColumn {
|
|
|
658
643
|
);
|
|
659
644
|
}
|
|
660
645
|
autoincrement() {
|
|
661
|
-
return new _SQLiteColumn(
|
|
662
|
-
this._.name,
|
|
663
|
-
this.type,
|
|
664
|
-
{ ...this.options, autoincrement: true },
|
|
665
|
-
this._.mode
|
|
666
|
-
);
|
|
646
|
+
return new _SQLiteColumn(this._.name, this.type, { ...this.options, autoincrement: true }, this._.mode);
|
|
667
647
|
}
|
|
668
648
|
unique() {
|
|
669
|
-
return new _SQLiteColumn(
|
|
670
|
-
this._.name,
|
|
671
|
-
this.type,
|
|
672
|
-
{ ...this.options, unique: true },
|
|
673
|
-
this._.mode
|
|
674
|
-
);
|
|
649
|
+
return new _SQLiteColumn(this._.name, this.type, { ...this.options, unique: true }, this._.mode);
|
|
675
650
|
}
|
|
676
651
|
references(ref, column) {
|
|
677
652
|
return new _SQLiteColumn(
|
|
@@ -688,12 +663,7 @@ var SQLiteColumn = class _SQLiteColumn {
|
|
|
688
663
|
);
|
|
689
664
|
}
|
|
690
665
|
$onUpdateFn(fn) {
|
|
691
|
-
return new _SQLiteColumn(
|
|
692
|
-
this._.name,
|
|
693
|
-
this.type,
|
|
694
|
-
{ ...this.options, $onUpdateFn: fn },
|
|
695
|
-
this._.mode
|
|
696
|
-
);
|
|
666
|
+
return new _SQLiteColumn(this._.name, this.type, { ...this.options, $onUpdateFn: fn }, this._.mode);
|
|
697
667
|
}
|
|
698
668
|
as(alias2) {
|
|
699
669
|
return this;
|
|
@@ -796,9 +766,7 @@ var TauriORM = class {
|
|
|
796
766
|
}
|
|
797
767
|
async migrate() {
|
|
798
768
|
for (const table of this.tables.values()) {
|
|
799
|
-
const existingTableInfo = await this.db.select(
|
|
800
|
-
`PRAGMA table_info('${table._.name}')`
|
|
801
|
-
);
|
|
769
|
+
const existingTableInfo = await this.db.select(`PRAGMA table_info('${table._.name}')`);
|
|
802
770
|
if (existingTableInfo.length === 0) {
|
|
803
771
|
const columnsSql = Object.values(table._.columns).map((col) => this.buildColumnDefinition(col)).join(", ");
|
|
804
772
|
const createSql = `CREATE TABLE ${table._.name}
|
|
@@ -807,9 +775,7 @@ var TauriORM = class {
|
|
|
807
775
|
)`;
|
|
808
776
|
await this.db.execute(createSql);
|
|
809
777
|
} else {
|
|
810
|
-
const existingColumnNames = new Set(
|
|
811
|
-
existingTableInfo.map((c) => c.name)
|
|
812
|
-
);
|
|
778
|
+
const existingColumnNames = new Set(existingTableInfo.map((c) => c.name));
|
|
813
779
|
for (const column of Object.values(table._.columns)) {
|
|
814
780
|
if (!existingColumnNames.has(column._.name)) {
|
|
815
781
|
const columnSql = this.buildColumnDefinition(column, true);
|
|
@@ -822,7 +788,14 @@ var TauriORM = class {
|
|
|
822
788
|
}
|
|
823
789
|
}
|
|
824
790
|
select(table, columns) {
|
|
825
|
-
|
|
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);
|
|
826
799
|
}
|
|
827
800
|
insert(table) {
|
|
828
801
|
return new InsertQueryBuilder(this.db, table);
|
|
@@ -925,10 +898,7 @@ var TauriORM = class {
|
|
|
925
898
|
const status = await this.isSchemaDirty();
|
|
926
899
|
if (status.dirty) {
|
|
927
900
|
await this.migrate();
|
|
928
|
-
await this.setSchemaMeta(
|
|
929
|
-
"schema_signature",
|
|
930
|
-
this.computeModelSignature()
|
|
931
|
-
);
|
|
901
|
+
await this.setSchemaMeta("schema_signature", this.computeModelSignature());
|
|
932
902
|
return true;
|
|
933
903
|
}
|
|
934
904
|
return false;
|
package/dist/index.mjs
CHANGED
|
@@ -559,28 +559,13 @@ var SQLiteColumn = class _SQLiteColumn {
|
|
|
559
559
|
}
|
|
560
560
|
_;
|
|
561
561
|
notNull() {
|
|
562
|
-
return new _SQLiteColumn(
|
|
563
|
-
this._.name,
|
|
564
|
-
this.type,
|
|
565
|
-
{ ...this.options, notNull: true },
|
|
566
|
-
this._.mode
|
|
567
|
-
);
|
|
562
|
+
return new _SQLiteColumn(this._.name, this.type, { ...this.options, notNull: true }, this._.mode);
|
|
568
563
|
}
|
|
569
564
|
default(value) {
|
|
570
|
-
return new _SQLiteColumn(
|
|
571
|
-
this._.name,
|
|
572
|
-
this.type,
|
|
573
|
-
{ ...this.options, default: value },
|
|
574
|
-
this._.mode
|
|
575
|
-
);
|
|
565
|
+
return new _SQLiteColumn(this._.name, this.type, { ...this.options, default: value }, this._.mode);
|
|
576
566
|
}
|
|
577
567
|
$defaultFn(fn) {
|
|
578
|
-
return new _SQLiteColumn(
|
|
579
|
-
this._.name,
|
|
580
|
-
this.type,
|
|
581
|
-
{ ...this.options, $defaultFn: fn },
|
|
582
|
-
this._.mode
|
|
583
|
-
);
|
|
568
|
+
return new _SQLiteColumn(this._.name, this.type, { ...this.options, $defaultFn: fn }, this._.mode);
|
|
584
569
|
}
|
|
585
570
|
primaryKey() {
|
|
586
571
|
return new _SQLiteColumn(
|
|
@@ -591,20 +576,10 @@ var SQLiteColumn = class _SQLiteColumn {
|
|
|
591
576
|
);
|
|
592
577
|
}
|
|
593
578
|
autoincrement() {
|
|
594
|
-
return new _SQLiteColumn(
|
|
595
|
-
this._.name,
|
|
596
|
-
this.type,
|
|
597
|
-
{ ...this.options, autoincrement: true },
|
|
598
|
-
this._.mode
|
|
599
|
-
);
|
|
579
|
+
return new _SQLiteColumn(this._.name, this.type, { ...this.options, autoincrement: true }, this._.mode);
|
|
600
580
|
}
|
|
601
581
|
unique() {
|
|
602
|
-
return new _SQLiteColumn(
|
|
603
|
-
this._.name,
|
|
604
|
-
this.type,
|
|
605
|
-
{ ...this.options, unique: true },
|
|
606
|
-
this._.mode
|
|
607
|
-
);
|
|
582
|
+
return new _SQLiteColumn(this._.name, this.type, { ...this.options, unique: true }, this._.mode);
|
|
608
583
|
}
|
|
609
584
|
references(ref, column) {
|
|
610
585
|
return new _SQLiteColumn(
|
|
@@ -621,12 +596,7 @@ var SQLiteColumn = class _SQLiteColumn {
|
|
|
621
596
|
);
|
|
622
597
|
}
|
|
623
598
|
$onUpdateFn(fn) {
|
|
624
|
-
return new _SQLiteColumn(
|
|
625
|
-
this._.name,
|
|
626
|
-
this.type,
|
|
627
|
-
{ ...this.options, $onUpdateFn: fn },
|
|
628
|
-
this._.mode
|
|
629
|
-
);
|
|
599
|
+
return new _SQLiteColumn(this._.name, this.type, { ...this.options, $onUpdateFn: fn }, this._.mode);
|
|
630
600
|
}
|
|
631
601
|
as(alias2) {
|
|
632
602
|
return this;
|
|
@@ -729,9 +699,7 @@ var TauriORM = class {
|
|
|
729
699
|
}
|
|
730
700
|
async migrate() {
|
|
731
701
|
for (const table of this.tables.values()) {
|
|
732
|
-
const existingTableInfo = await this.db.select(
|
|
733
|
-
`PRAGMA table_info('${table._.name}')`
|
|
734
|
-
);
|
|
702
|
+
const existingTableInfo = await this.db.select(`PRAGMA table_info('${table._.name}')`);
|
|
735
703
|
if (existingTableInfo.length === 0) {
|
|
736
704
|
const columnsSql = Object.values(table._.columns).map((col) => this.buildColumnDefinition(col)).join(", ");
|
|
737
705
|
const createSql = `CREATE TABLE ${table._.name}
|
|
@@ -740,9 +708,7 @@ var TauriORM = class {
|
|
|
740
708
|
)`;
|
|
741
709
|
await this.db.execute(createSql);
|
|
742
710
|
} else {
|
|
743
|
-
const existingColumnNames = new Set(
|
|
744
|
-
existingTableInfo.map((c) => c.name)
|
|
745
|
-
);
|
|
711
|
+
const existingColumnNames = new Set(existingTableInfo.map((c) => c.name));
|
|
746
712
|
for (const column of Object.values(table._.columns)) {
|
|
747
713
|
if (!existingColumnNames.has(column._.name)) {
|
|
748
714
|
const columnSql = this.buildColumnDefinition(column, true);
|
|
@@ -755,7 +721,14 @@ var TauriORM = class {
|
|
|
755
721
|
}
|
|
756
722
|
}
|
|
757
723
|
select(table, columns) {
|
|
758
|
-
|
|
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);
|
|
759
732
|
}
|
|
760
733
|
insert(table) {
|
|
761
734
|
return new InsertQueryBuilder(this.db, table);
|
|
@@ -858,10 +831,7 @@ var TauriORM = class {
|
|
|
858
831
|
const status = await this.isSchemaDirty();
|
|
859
832
|
if (status.dirty) {
|
|
860
833
|
await this.migrate();
|
|
861
|
-
await this.setSchemaMeta(
|
|
862
|
-
"schema_signature",
|
|
863
|
-
this.computeModelSignature()
|
|
864
|
-
);
|
|
834
|
+
await this.setSchemaMeta("schema_signature", this.computeModelSignature());
|
|
865
835
|
return true;
|
|
866
836
|
}
|
|
867
837
|
return false;
|