forked from trent_larson/crowd-funder-for-time-pwa
rename the absurd-sql-specific items for clarity
This commit is contained in:
@@ -12,7 +12,6 @@ import {
|
||||
updateAccountSettings,
|
||||
updateDefaultSettings,
|
||||
} from "../db/index";
|
||||
import databaseService from "../services/database";
|
||||
import { Account } from "../db/tables/accounts";
|
||||
import { Contact } from "../db/tables/contacts";
|
||||
import { DEFAULT_PASSKEY_EXPIRATION_MINUTES } from "../db/tables/settings";
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import databaseService from "./services/database";
|
||||
import databaseService from "./services/AbsurdSqlDatabaseService";
|
||||
|
||||
async function run() {
|
||||
await databaseService.initialize();
|
||||
|
||||
@@ -8,10 +8,10 @@ import { SQLiteFS } from "absurd-sql";
|
||||
import IndexedDBBackend from "absurd-sql/dist/indexeddb-backend";
|
||||
|
||||
import { runMigrations } from "../db-sql/migration";
|
||||
import type { QueryExecResult } from "../interfaces/database";
|
||||
import type { DatabaseService, QueryExecResult } from "../interfaces/database";
|
||||
import { logger } from "@/utils/logger";
|
||||
|
||||
interface SQLDatabase {
|
||||
interface AbsurdSqlDatabase {
|
||||
exec: (sql: string, params?: unknown[]) => Promise<QueryExecResult[]>;
|
||||
run: (
|
||||
sql: string,
|
||||
@@ -19,9 +19,9 @@ interface SQLDatabase {
|
||||
) => Promise<{ changes: number; lastId?: number }>;
|
||||
}
|
||||
|
||||
class DatabaseService {
|
||||
private static instance: DatabaseService | null = null;
|
||||
private db: SQLDatabase | null;
|
||||
class AbsurdSqlDatabaseService implements DatabaseService {
|
||||
private static instance: AbsurdSqlDatabaseService | null = null;
|
||||
private db: AbsurdSqlDatabase | null;
|
||||
private initialized: boolean;
|
||||
private initializationPromise: Promise<void> | null = null;
|
||||
|
||||
@@ -30,11 +30,11 @@ class DatabaseService {
|
||||
this.initialized = false;
|
||||
}
|
||||
|
||||
static getInstance(): DatabaseService {
|
||||
if (!DatabaseService.instance) {
|
||||
DatabaseService.instance = new DatabaseService();
|
||||
static getInstance(): AbsurdSqlDatabaseService {
|
||||
if (!AbsurdSqlDatabaseService.instance) {
|
||||
AbsurdSqlDatabaseService.instance = new AbsurdSqlDatabaseService();
|
||||
}
|
||||
return DatabaseService.instance;
|
||||
return AbsurdSqlDatabaseService.instance;
|
||||
}
|
||||
|
||||
async initialize(): Promise<void> {
|
||||
@@ -53,7 +53,7 @@ class DatabaseService {
|
||||
try {
|
||||
await this.initializationPromise;
|
||||
} catch (error) {
|
||||
logger.error(`DatabaseService initialize method failed:`, error);
|
||||
logger.error(`AbsurdSqlDatabaseService initialize method failed:`, error);
|
||||
this.initializationPromise = null; // Reset on failure
|
||||
throw error;
|
||||
}
|
||||
@@ -79,7 +79,7 @@ class DatabaseService {
|
||||
SQL.FS.mkdir("/sql");
|
||||
SQL.FS.mount(sqlFS, {}, "/sql");
|
||||
|
||||
const path = "/sql/db.sqlite";
|
||||
const path = "/sql/timesafari.sqlite";
|
||||
if (typeof SharedArrayBuffer === "undefined") {
|
||||
const stream = SQL.FS.open(path, "a+");
|
||||
await stream.node.contents.readIfFallback();
|
||||
@@ -93,6 +93,7 @@ class DatabaseService {
|
||||
);
|
||||
}
|
||||
|
||||
// An error is thrown without this pragma: "File has invalid page size. (the first block of a new file must be written first)"
|
||||
await this.db.exec(`PRAGMA journal_mode=MEMORY;`);
|
||||
const sqlExec = this.db.exec.bind(this.db);
|
||||
|
||||
@@ -150,7 +151,7 @@ class DatabaseService {
|
||||
return result[0]?.values[0];
|
||||
}
|
||||
|
||||
async all(sql: string, params: unknown[] = []): Promise<unknown[][]> {
|
||||
async getAll(sql: string, params: unknown[] = []): Promise<unknown[][]> {
|
||||
await this.waitForInitialization();
|
||||
const result = await this.db!.exec(sql, params);
|
||||
return result[0]?.values || [];
|
||||
@@ -158,6 +159,6 @@ class DatabaseService {
|
||||
}
|
||||
|
||||
// Create a singleton instance
|
||||
const databaseService = DatabaseService.getInstance();
|
||||
const databaseService = AbsurdSqlDatabaseService.getInstance();
|
||||
|
||||
export default databaseService;
|
||||
@@ -5,7 +5,7 @@ import {
|
||||
} from "../PlatformService";
|
||||
import { logger } from "../../utils/logger";
|
||||
import { QueryExecResult } from "@/interfaces/database";
|
||||
import databaseService from "../database";
|
||||
import databaseService from "../AbsurdSqlDatabaseService";
|
||||
|
||||
/**
|
||||
* Platform service implementation for web browser platform.
|
||||
|
||||
@@ -905,9 +905,9 @@
|
||||
</div>
|
||||
</label>
|
||||
|
||||
<div id="sectionPasskeyExpiration" class="flex justify-between">
|
||||
<div id="sectionPasskeyExpiration" class="flex mt-4 justify-between">
|
||||
<span>
|
||||
<span class="text-slate-500 text-sm font-bold mb-2">
|
||||
<span class="text-slate-500 text-sm font-bold">
|
||||
Passkey Expiration Minutes
|
||||
</span>
|
||||
<br />
|
||||
@@ -953,13 +953,13 @@
|
||||
|
||||
<router-link
|
||||
:to="{ name: 'logs' }"
|
||||
class="block w-fit text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md mb-2"
|
||||
class="block w-fit text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md mt-2"
|
||||
>
|
||||
Logs
|
||||
</router-link>
|
||||
<router-link
|
||||
:to="{ name: 'test' }"
|
||||
class="block w-fit text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md mb-2"
|
||||
class="block w-fit text-center text-md bg-gradient-to-b from-slate-400 to-slate-700 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.5)] text-white px-4 py-2 rounded-md mt-2"
|
||||
>
|
||||
Test Page
|
||||
</router-link>
|
||||
|
||||
@@ -543,9 +543,9 @@ export default class Help extends Vue {
|
||||
} else {
|
||||
this.sqlResult = await platformService.dbExec(this.sqlQuery);
|
||||
}
|
||||
logger.log("SQL Result:", this.sqlResult);
|
||||
logger.log("Test SQL Result:", this.sqlResult);
|
||||
} catch (error) {
|
||||
logger.error("SQL Error:", error);
|
||||
logger.error("Test SQL Error:", error);
|
||||
this.$notify(
|
||||
{
|
||||
group: "alert",
|
||||
|
||||
Reference in New Issue
Block a user