diff --git a/frontend/src/db/database.js b/frontend/src/db/database.js index ebcefd8..f73e213 100644 --- a/frontend/src/db/database.js +++ b/frontend/src/db/database.js @@ -1,5 +1,4 @@ -import SQLiteESMFactory from '@journeyapps/wa-sqlite/dist/wa-sqlite-async.mjs' -import { IDBBatchAtomicVFS } from '@journeyapps/wa-sqlite/src/examples/IDBBatchAtomicVFS.js' +import SQLiteESMFactory from '@journeyapps/wa-sqlite/dist/wa-sqlite.mjs' import * as SQLite from '@journeyapps/wa-sqlite' import { SCHEMA_SQL } from './schema.js' @@ -7,14 +6,19 @@ let db = null let sqlite3 = null const tableListeners = new Map() -export async function initDatabase() { - if (db) return db +let initPromise = null + +export function initDatabase() { + if (initPromise) return initPromise + initPromise = _init() + return initPromise +} + +async function _init() { const module = await SQLiteESMFactory() sqlite3 = SQLite.Factory(module) - const vfs = await IDBBatchAtomicVFS.create('roaauto', module) - sqlite3.vfs_register(vfs, true) - db = await sqlite3.open_v2('roaauto.db', - SQLite.SQLITE_OPEN_READWRITE | SQLite.SQLITE_OPEN_CREATE, 'roaauto') + db = await sqlite3.open_v2(':memory:') + for (const sql of SCHEMA_SQL.split(';').filter(s => s.trim())) { await sqlite3.exec(db, sql) } @@ -34,10 +38,20 @@ export function onTableChange(table, cb) { export async function execSQL(sql, params = []) { if (!db) throw new Error('DB not initialized') const results = [] - await sqlite3.exec(db, sql, (row, cols) => { - const obj = {} - cols.forEach((c, i) => { obj[c] = row[i] }) - results.push(obj) - }) + + if (params.length === 0) { + await sqlite3.exec(db, sql, (row, cols) => { + results.push(Object.fromEntries(cols.map((c, i) => [c, row[i]]))) + }) + } else { + for await (const stmt of sqlite3.statements(db, sql)) { + sqlite3.bind_collection(stmt, params) + const cols = sqlite3.column_names(stmt) + while ((await sqlite3.step(stmt)) === SQLite.SQLITE_ROW) { + results.push(Object.fromEntries(cols.map((c, i) => [c, sqlite3.column(stmt, i)]))) + } + } + } + return results } diff --git a/frontend/src/main.js b/frontend/src/main.js index e25dba2..c4a62d4 100644 --- a/frontend/src/main.js +++ b/frontend/src/main.js @@ -14,8 +14,13 @@ app.use(pinia) app.use(router) const auth = useAuthStore() -if (auth.isAuthenticated) { - initDatabase().then(() => syncEngine.fullSync()) + +async function bootstrap() { + if (auth.isAuthenticated) { + await initDatabase() + syncEngine.fullSync().catch(() => {}) + } + app.mount('#app') } -app.mount('#app') +bootstrap() diff --git a/frontend/src/views/appointments/AppointmentsView.vue b/frontend/src/views/appointments/AppointmentsView.vue index c00f058..33bc1de 100644 --- a/frontend/src/views/appointments/AppointmentsView.vue +++ b/frontend/src/views/appointments/AppointmentsView.vue @@ -1,6 +1,197 @@ + + diff --git a/frontend/src/views/catalog/CatalogView.vue b/frontend/src/views/catalog/CatalogView.vue index 547fb3b..9d83f11 100644 --- a/frontend/src/views/catalog/CatalogView.vue +++ b/frontend/src/views/catalog/CatalogView.vue @@ -1,6 +1,408 @@ + + diff --git a/frontend/src/views/orders/OrderDetailView.vue b/frontend/src/views/orders/OrderDetailView.vue index b55cfa8..08aab49 100644 --- a/frontend/src/views/orders/OrderDetailView.vue +++ b/frontend/src/views/orders/OrderDetailView.vue @@ -20,6 +20,14 @@ > Valideaza +