@type32/tauri-sqlite-orm 0.1.18-20 → 0.1.18-21
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 +9 -1
- package/dist/index.d.ts +9 -1
- package/dist/index.js +50 -5
- package/dist/index.mjs +50 -5
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -207,7 +207,9 @@ declare class TauriORM {
|
|
|
207
207
|
private tables;
|
|
208
208
|
constructor(db: Database, schema?: Record<string, AnyTable | Record<string, Relation>> | undefined);
|
|
209
209
|
private buildColumnDefinition;
|
|
210
|
-
migrate(
|
|
210
|
+
migrate(options?: {
|
|
211
|
+
performDestructiveActions?: boolean;
|
|
212
|
+
}): Promise<void>;
|
|
211
213
|
select<T extends AnyTable, C extends (keyof T['_']['columns'])[] | undefined = undefined>(table: T, columns?: C): SelectQueryBuilder<T, C>;
|
|
212
214
|
insert<T extends AnyTable>(table: T): InsertQueryBuilder<T>;
|
|
213
215
|
update<T extends AnyTable>(table: T): UpdateQueryBuilder<T>;
|
|
@@ -232,6 +234,12 @@ declare class TauriORM {
|
|
|
232
234
|
stored: string | null;
|
|
233
235
|
}>;
|
|
234
236
|
migrateIfDirty(): Promise<boolean>;
|
|
237
|
+
doesTableExist(tableName: string): Promise<boolean>;
|
|
238
|
+
dropTable(tableName: string): Promise<void>;
|
|
239
|
+
doesColumnExist(tableName: string, columnName: string): Promise<boolean>;
|
|
240
|
+
renameTable(from: string, to: string): Promise<void>;
|
|
241
|
+
dropColumn(tableName: string, columnName: string): Promise<void>;
|
|
242
|
+
renameColumn(tableName: string, from: string, to: string): Promise<void>;
|
|
235
243
|
}
|
|
236
244
|
declare class Relation<T extends AnyTable = AnyTable> {
|
|
237
245
|
foreignTable: T;
|
package/dist/index.d.ts
CHANGED
|
@@ -207,7 +207,9 @@ declare class TauriORM {
|
|
|
207
207
|
private tables;
|
|
208
208
|
constructor(db: Database, schema?: Record<string, AnyTable | Record<string, Relation>> | undefined);
|
|
209
209
|
private buildColumnDefinition;
|
|
210
|
-
migrate(
|
|
210
|
+
migrate(options?: {
|
|
211
|
+
performDestructiveActions?: boolean;
|
|
212
|
+
}): Promise<void>;
|
|
211
213
|
select<T extends AnyTable, C extends (keyof T['_']['columns'])[] | undefined = undefined>(table: T, columns?: C): SelectQueryBuilder<T, C>;
|
|
212
214
|
insert<T extends AnyTable>(table: T): InsertQueryBuilder<T>;
|
|
213
215
|
update<T extends AnyTable>(table: T): UpdateQueryBuilder<T>;
|
|
@@ -232,6 +234,12 @@ declare class TauriORM {
|
|
|
232
234
|
stored: string | null;
|
|
233
235
|
}>;
|
|
234
236
|
migrateIfDirty(): Promise<boolean>;
|
|
237
|
+
doesTableExist(tableName: string): Promise<boolean>;
|
|
238
|
+
dropTable(tableName: string): Promise<void>;
|
|
239
|
+
doesColumnExist(tableName: string, columnName: string): Promise<boolean>;
|
|
240
|
+
renameTable(from: string, to: string): Promise<void>;
|
|
241
|
+
dropColumn(tableName: string, columnName: string): Promise<void>;
|
|
242
|
+
renameColumn(tableName: string, from: string, to: string): Promise<void>;
|
|
235
243
|
}
|
|
236
244
|
declare class Relation<T extends AnyTable = AnyTable> {
|
|
237
245
|
foreignTable: T;
|
package/dist/index.js
CHANGED
|
@@ -794,26 +794,48 @@ var TauriORM = class {
|
|
|
794
794
|
}
|
|
795
795
|
return sql2;
|
|
796
796
|
}
|
|
797
|
-
async migrate() {
|
|
797
|
+
async migrate(options) {
|
|
798
|
+
const dbTables = await this.db.select(
|
|
799
|
+
`SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'`
|
|
800
|
+
);
|
|
801
|
+
const dbTableNames = new Set(dbTables.map((t) => t.name));
|
|
802
|
+
const schemaTableNames = new Set(Array.from(this.tables.keys()));
|
|
798
803
|
for (const table of this.tables.values()) {
|
|
799
|
-
const
|
|
800
|
-
|
|
804
|
+
const tableName = table._.name;
|
|
805
|
+
const tableExists = dbTableNames.has(tableName);
|
|
806
|
+
if (!tableExists) {
|
|
801
807
|
const columnsSql = Object.values(table._.columns).map((col) => this.buildColumnDefinition(col)).join(", ");
|
|
802
|
-
const createSql = `CREATE TABLE ${
|
|
808
|
+
const createSql = `CREATE TABLE ${tableName}
|
|
803
809
|
(
|
|
804
810
|
${columnsSql}
|
|
805
811
|
)`;
|
|
806
812
|
await this.db.execute(createSql);
|
|
807
813
|
} else {
|
|
814
|
+
const existingTableInfo = await this.db.select(`PRAGMA table_info('${tableName}')`);
|
|
808
815
|
const existingColumnNames = new Set(existingTableInfo.map((c) => c.name));
|
|
816
|
+
const schemaColumnNames = new Set(Object.keys(table._.columns));
|
|
809
817
|
for (const column of Object.values(table._.columns)) {
|
|
810
818
|
if (!existingColumnNames.has(column._.name)) {
|
|
811
819
|
const columnSql = this.buildColumnDefinition(column, true);
|
|
812
|
-
const alterSql = `ALTER TABLE ${
|
|
820
|
+
const alterSql = `ALTER TABLE ${tableName}
|
|
813
821
|
ADD COLUMN ${columnSql}`;
|
|
814
822
|
await this.db.execute(alterSql);
|
|
815
823
|
}
|
|
816
824
|
}
|
|
825
|
+
if (options?.performDestructiveActions) {
|
|
826
|
+
for (const colName of existingColumnNames) {
|
|
827
|
+
if (!schemaColumnNames.has(colName)) {
|
|
828
|
+
await this.dropColumn(tableName, colName);
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
if (options?.performDestructiveActions) {
|
|
835
|
+
for (const tableName of dbTableNames) {
|
|
836
|
+
if (!schemaTableNames.has(tableName)) {
|
|
837
|
+
await this.dropTable(tableName);
|
|
838
|
+
}
|
|
817
839
|
}
|
|
818
840
|
}
|
|
819
841
|
}
|
|
@@ -933,6 +955,29 @@ var TauriORM = class {
|
|
|
933
955
|
}
|
|
934
956
|
return false;
|
|
935
957
|
}
|
|
958
|
+
async doesTableExist(tableName) {
|
|
959
|
+
const result = await this.db.select(
|
|
960
|
+
`SELECT name FROM sqlite_master WHERE type='table' AND name=?`,
|
|
961
|
+
[tableName]
|
|
962
|
+
);
|
|
963
|
+
return result.length > 0;
|
|
964
|
+
}
|
|
965
|
+
async dropTable(tableName) {
|
|
966
|
+
await this.db.execute(`DROP TABLE IF EXISTS ${tableName}`);
|
|
967
|
+
}
|
|
968
|
+
async doesColumnExist(tableName, columnName) {
|
|
969
|
+
const result = await this.db.select(`PRAGMA table_info('${tableName}')`);
|
|
970
|
+
return result.some((col) => col.name === columnName);
|
|
971
|
+
}
|
|
972
|
+
async renameTable(from, to) {
|
|
973
|
+
await this.db.execute(`ALTER TABLE ${from} RENAME TO ${to}`);
|
|
974
|
+
}
|
|
975
|
+
async dropColumn(tableName, columnName) {
|
|
976
|
+
await this.db.execute(`ALTER TABLE ${tableName} DROP COLUMN ${columnName}`);
|
|
977
|
+
}
|
|
978
|
+
async renameColumn(tableName, from, to) {
|
|
979
|
+
await this.db.execute(`ALTER TABLE ${tableName} RENAME COLUMN ${from} TO ${to}`);
|
|
980
|
+
}
|
|
936
981
|
};
|
|
937
982
|
var Relation = class {
|
|
938
983
|
constructor(foreignTable) {
|
package/dist/index.mjs
CHANGED
|
@@ -725,26 +725,48 @@ var TauriORM = class {
|
|
|
725
725
|
}
|
|
726
726
|
return sql2;
|
|
727
727
|
}
|
|
728
|
-
async migrate() {
|
|
728
|
+
async migrate(options) {
|
|
729
|
+
const dbTables = await this.db.select(
|
|
730
|
+
`SELECT name FROM sqlite_master WHERE type='table' AND name NOT LIKE 'sqlite_%'`
|
|
731
|
+
);
|
|
732
|
+
const dbTableNames = new Set(dbTables.map((t) => t.name));
|
|
733
|
+
const schemaTableNames = new Set(Array.from(this.tables.keys()));
|
|
729
734
|
for (const table of this.tables.values()) {
|
|
730
|
-
const
|
|
731
|
-
|
|
735
|
+
const tableName = table._.name;
|
|
736
|
+
const tableExists = dbTableNames.has(tableName);
|
|
737
|
+
if (!tableExists) {
|
|
732
738
|
const columnsSql = Object.values(table._.columns).map((col) => this.buildColumnDefinition(col)).join(", ");
|
|
733
|
-
const createSql = `CREATE TABLE ${
|
|
739
|
+
const createSql = `CREATE TABLE ${tableName}
|
|
734
740
|
(
|
|
735
741
|
${columnsSql}
|
|
736
742
|
)`;
|
|
737
743
|
await this.db.execute(createSql);
|
|
738
744
|
} else {
|
|
745
|
+
const existingTableInfo = await this.db.select(`PRAGMA table_info('${tableName}')`);
|
|
739
746
|
const existingColumnNames = new Set(existingTableInfo.map((c) => c.name));
|
|
747
|
+
const schemaColumnNames = new Set(Object.keys(table._.columns));
|
|
740
748
|
for (const column of Object.values(table._.columns)) {
|
|
741
749
|
if (!existingColumnNames.has(column._.name)) {
|
|
742
750
|
const columnSql = this.buildColumnDefinition(column, true);
|
|
743
|
-
const alterSql = `ALTER TABLE ${
|
|
751
|
+
const alterSql = `ALTER TABLE ${tableName}
|
|
744
752
|
ADD COLUMN ${columnSql}`;
|
|
745
753
|
await this.db.execute(alterSql);
|
|
746
754
|
}
|
|
747
755
|
}
|
|
756
|
+
if (options?.performDestructiveActions) {
|
|
757
|
+
for (const colName of existingColumnNames) {
|
|
758
|
+
if (!schemaColumnNames.has(colName)) {
|
|
759
|
+
await this.dropColumn(tableName, colName);
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
if (options?.performDestructiveActions) {
|
|
766
|
+
for (const tableName of dbTableNames) {
|
|
767
|
+
if (!schemaTableNames.has(tableName)) {
|
|
768
|
+
await this.dropTable(tableName);
|
|
769
|
+
}
|
|
748
770
|
}
|
|
749
771
|
}
|
|
750
772
|
}
|
|
@@ -864,6 +886,29 @@ var TauriORM = class {
|
|
|
864
886
|
}
|
|
865
887
|
return false;
|
|
866
888
|
}
|
|
889
|
+
async doesTableExist(tableName) {
|
|
890
|
+
const result = await this.db.select(
|
|
891
|
+
`SELECT name FROM sqlite_master WHERE type='table' AND name=?`,
|
|
892
|
+
[tableName]
|
|
893
|
+
);
|
|
894
|
+
return result.length > 0;
|
|
895
|
+
}
|
|
896
|
+
async dropTable(tableName) {
|
|
897
|
+
await this.db.execute(`DROP TABLE IF EXISTS ${tableName}`);
|
|
898
|
+
}
|
|
899
|
+
async doesColumnExist(tableName, columnName) {
|
|
900
|
+
const result = await this.db.select(`PRAGMA table_info('${tableName}')`);
|
|
901
|
+
return result.some((col) => col.name === columnName);
|
|
902
|
+
}
|
|
903
|
+
async renameTable(from, to) {
|
|
904
|
+
await this.db.execute(`ALTER TABLE ${from} RENAME TO ${to}`);
|
|
905
|
+
}
|
|
906
|
+
async dropColumn(tableName, columnName) {
|
|
907
|
+
await this.db.execute(`ALTER TABLE ${tableName} DROP COLUMN ${columnName}`);
|
|
908
|
+
}
|
|
909
|
+
async renameColumn(tableName, from, to) {
|
|
910
|
+
await this.db.execute(`ALTER TABLE ${tableName} RENAME COLUMN ${from} TO ${to}`);
|
|
911
|
+
}
|
|
867
912
|
};
|
|
868
913
|
var Relation = class {
|
|
869
914
|
constructor(foreignTable) {
|