forked from trent_larson/crowd-funder-for-time-pwa
remove unused DB methods (for now)
This commit is contained in:
@@ -12,6 +12,4 @@ export interface DatabaseService {
|
||||
sql: string,
|
||||
params?: unknown[],
|
||||
): Promise<{ changes: number; lastId?: number }>;
|
||||
getOneRow(sql: string, params?: unknown[]): Promise<unknown[] | undefined>;
|
||||
getAll(sql: string, params?: unknown[]): Promise<unknown[][]>;
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import type { DatabaseService, QueryExecResult } from "../interfaces/database";
|
||||
import { logger } from "@/utils/logger";
|
||||
|
||||
interface QueuedOperation {
|
||||
type: "run" | "query" | "getOneRow" | "getAll";
|
||||
type: "run" | "query";
|
||||
sql: string;
|
||||
params: unknown[];
|
||||
resolve: (value: unknown) => void;
|
||||
@@ -84,7 +84,7 @@ class AbsurdSqlDatabaseService implements DatabaseService {
|
||||
SQL.FS.mkdir("/sql");
|
||||
SQL.FS.mount(sqlFS, {}, "/sql");
|
||||
|
||||
const path = "/sql/timesafari.sqlite";
|
||||
const path = "/sql/timesafari.absurd-sql";
|
||||
if (typeof SharedArrayBuffer === "undefined") {
|
||||
const stream = SQL.FS.open(path, "a+");
|
||||
await stream.node.contents.readIfFallback();
|
||||
@@ -133,7 +133,6 @@ class AbsurdSqlDatabaseService implements DatabaseService {
|
||||
if (!operation) continue;
|
||||
|
||||
try {
|
||||
let queryResult: QueryExecResult[] = [];
|
||||
let result: unknown;
|
||||
switch (operation.type) {
|
||||
case "run":
|
||||
@@ -142,14 +141,6 @@ class AbsurdSqlDatabaseService implements DatabaseService {
|
||||
case "query":
|
||||
result = await this.db.exec(operation.sql, operation.params);
|
||||
break;
|
||||
case "getOneRow":
|
||||
queryResult = await this.db.exec(operation.sql, operation.params);
|
||||
result = queryResult[0]?.values[0];
|
||||
break;
|
||||
case "getAll":
|
||||
queryResult = await this.db.exec(operation.sql, operation.params);
|
||||
result = queryResult[0]?.values || [];
|
||||
break;
|
||||
}
|
||||
operation.resolve(result);
|
||||
} catch (error) {
|
||||
@@ -232,19 +223,6 @@ class AbsurdSqlDatabaseService implements DatabaseService {
|
||||
await this.waitForInitialization();
|
||||
return this.queueOperation<QueryExecResult[]>("query", sql, params);
|
||||
}
|
||||
|
||||
async getOneRow(
|
||||
sql: string,
|
||||
params: unknown[] = [],
|
||||
): Promise<unknown[] | undefined> {
|
||||
await this.waitForInitialization();
|
||||
return this.queueOperation<unknown[] | undefined>("getOneRow", sql, params);
|
||||
}
|
||||
|
||||
async getAll(sql: string, params: unknown[] = []): Promise<unknown[][]> {
|
||||
await this.waitForInitialization();
|
||||
return this.queueOperation<unknown[][]>("getAll", sql, params);
|
||||
}
|
||||
}
|
||||
|
||||
// Create a singleton instance
|
||||
|
||||
@@ -19,7 +19,7 @@ import {
|
||||
import { logger } from "../../utils/logger";
|
||||
|
||||
interface QueuedOperation {
|
||||
type: "run" | "query" | "getOneRow" | "getAll";
|
||||
type: "run" | "query";
|
||||
sql: string;
|
||||
params: unknown[];
|
||||
resolve: (value: unknown) => void;
|
||||
@@ -145,26 +145,12 @@ export class CapacitorPlatformService implements PlatformService {
|
||||
);
|
||||
result = {
|
||||
columns: [], // SQLite plugin doesn't provide column names
|
||||
values: (queryResult.values || []).map((row) => Object.values(row)),
|
||||
values: (queryResult.values || []).map((row) =>
|
||||
Object.values(row),
|
||||
),
|
||||
};
|
||||
break;
|
||||
}
|
||||
case "getOneRow": {
|
||||
const oneRowResult = await this.db.query(
|
||||
operation.sql,
|
||||
operation.params,
|
||||
);
|
||||
result = oneRowResult.values?.[0];
|
||||
break;
|
||||
}
|
||||
case "getAll": {
|
||||
const allResult = await this.db.query(
|
||||
operation.sql,
|
||||
operation.params,
|
||||
);
|
||||
result = allResult.values || [];
|
||||
break;
|
||||
}
|
||||
}
|
||||
operation.resolve(result);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user