1
0
silverbullet/plugos/sqlite/capacitor_sqlite.ts

37 lines
903 B
TypeScript
Raw Normal View History

import { Capacitor } from "../../mobile/deps.ts";
import { CapacitorSQLite } from "../deps.ts";
import { ISQLite } from "./sqlite_interface.ts";
export class CapacitorDb implements ISQLite {
constructor(readonly name: string) {
}
async init() {
await CapacitorSQLite.createConnection({
database: this.name,
});
await CapacitorSQLite.open({
database: this.name,
});
}
async query(sql: string, ...args: any[]) {
const result = await CapacitorSQLite.query({
statement: sql,
database: this.name,
values: args,
});
if (Capacitor.getPlatform() === "ios") {
return result.values!.slice(1);
}
return result.values!;
}
async execute(sql: string, ...args: any[]): Promise<number> {
return (await CapacitorSQLite.run({
statement: sql,
database: this.name,
values: args,
})).changes!.changes!;
}
}