-
Notifications
You must be signed in to change notification settings - Fork 144
Description
Is your feature request related to a problem? Please describe.
I am trying to use SvelteKit with Capacitor (Starter, Recipe, CLI tool, Blog 1, Blog 2). Sadly most examples for sqlite here seem very specific to Angular, React and Vue.
When checking plain API docs, it sounds like everything just works out-of-the-box:
Web
the database is stored in Web browser INDEXEDDB storage as a localforage store under the jeepSqliteStore name and databases table name.
But the Web-Usage doc is many pages of code, and it's hard to see which is the generic and which is Angular/React/Vue specific.
Maybe I just don't understand what a "Stencil Component" actually is. Or why jeep-sqlite is needed. And what localforage is for.
Describe the solution you'd like
A clear and concise description of how to setup and use sqlite in native/web environment with plain Javascript. It would be great to have a simple stand-alone function to call after the page is loaded. Without polyfills, window use and document.body.appendChild() if possible.
Maybe that function can even become part of the package, why should everyone code this separately? And optional enable encryption.
// raw example, don't try this at home
import { Capacitor } from "@capacitor/core";
import { CapacitorSQLite, SQLiteConnection } from "@capacitor-community/sqlite";
import initSqlJs from 'sql.js';
export async function initDB(dbName) {
let db;
const platform = Capacitor.getPlatform();
if (platform == 'web') {
console.log('Using web sqlite')
const SQL = await initSqlJs({
locateFile: file => `./node_modules/sql.js/dist/${file}`
})
db = new SQL.Database();
} else {
console.log('Using capacitor sqlite')
const sqlite = new SQLiteConnection(CapacitorSQLite)
const ret = await sqlite.checkConnectionsConsistency()
console.log(`after checkConnectionsConsistency ${ret.result}`)
const isConn = await sqlite.isConnection(dbName, false)
console.log(`after isConnection ${isConn.result}`)
if (ret.result && isConn) {
db = await sqlite.retrieveConnection(dbName, false)
} else {
db = await sqlite.createConnection(dbName, false, "no-encryption", 1, false)
}
await db.open()
}
return db
}
Describe alternatives you've considered
Alternatively it would be awesome to have a full SvelteKit example, Svelte has already been mentioned in TypeORM-Usage doc.