A WebSQL adapter for PawSQLite
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
import { WebSQLAdapterError } from "./websql_adapter_error.mjs";
|
|
|
|
import { DatabaseWrapper } from "./database_wrapper.mjs";
|
|
|
|
import { ResponseWrapper } from "./response_wrapper.mjs";
|
|
|
|
import { enableDebug, log } from "./log.mjs";
|
|
|
|
|
|
|
|
const databases = new Map();
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "PawSQLiteWebSQLAdapter",
|
|
|
|
open: async (dbName) => {
|
|
|
|
const version = "1.0";
|
|
|
|
|
|
|
|
if (!databases.has(dbName)) {
|
|
|
|
databases.set(dbName, new DatabaseWrapper(dbName, version));
|
|
|
|
}
|
|
|
|
|
|
|
|
return ResponseWrapper.success({ version });
|
|
|
|
},
|
|
|
|
|
|
|
|
close: async (dbName) => {
|
|
|
|
databases.delete(dbName);
|
|
|
|
return ResponseWrapper.success();
|
|
|
|
},
|
|
|
|
|
|
|
|
sql: async (dbName, sql, ...args) => {
|
|
|
|
log(sql);
|
|
|
|
|
|
|
|
const db = databases.get(dbName);
|
|
|
|
if (!db) {
|
|
|
|
throw new WebSQLAdapterError("Database not open");
|
|
|
|
}
|
|
|
|
|
|
|
|
const result = await db.sql(sql, ...args);
|
|
|
|
return ResponseWrapper.success(result);
|
|
|
|
},
|
|
|
|
|
|
|
|
delete: async (dbName) => {
|
|
|
|
throw new WebSQLAdapterError("Delete not implemented");
|
|
|
|
},
|
|
|
|
|
|
|
|
debug: enableDebug
|
|
|
|
};
|