feat(frontend): wa-sqlite memory-only + Factureaza + Vite polling + Appointments + Catalog

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-03-13 18:37:08 +02:00
parent 78d2a77b0d
commit 9aef3d6933
6 changed files with 673 additions and 20 deletions

View File

@@ -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
}