mobile: migrate to sqlite

This commit is contained in:
Ammar Ahmed
2023-11-16 08:54:37 +05:00
committed by Abdullah Atta
parent 2168609577
commit 5bfad0149b
110 changed files with 64611 additions and 11914 deletions

View File

@@ -137,7 +137,6 @@ class Database {
transaction = (
executor: (tr: Transaction<DatabaseSchema>) => void | Promise<void>
) => {
console.time("transaction");
return this.transactionMutex.runExclusive(() =>
this.sql()
.transaction()
@@ -147,7 +146,6 @@ class Database {
this._transaction = undefined;
})
.finally(() => {
console.timeEnd("transaction");
this._transaction = undefined;
})
);

View File

@@ -314,7 +314,7 @@ export class Attachments implements ICollection {
});
}
markAsFailed(id: string, reason: string) {
markAsFailed(id: string, reason?: string) {
return this.collection.update([id], {
dateUploaded: null,
failed: reason

View File

@@ -294,6 +294,19 @@ class RelationsArray<TType extends keyof RelatableTable> {
return result.count > 0;
}
async hasAll(...ids: string[]) {
const result = await this.db
.sql()
.selectFrom("relations")
.$call(this.buildRelationsQuery())
.clearSelect()
.where(this.direction === "from" ? "toId" : "fromId", "in", ids)
.select((b) => b.fn.count<number>("id").as("count"))
.executeTakeFirst();
if (!result) return false;
return result.count === ids.length;
}
/**
* Build an optimized query for obtaining relations based on the given
* parameters. The resulting query uses a covering index (the most