import { type createSqlite } from "https://esm.town/v/postpostscript/sqliteWasm?v=141";
export type SQLiteDB = ReturnType<typeof createSqlite>;
export const createServer = (dbFactory: () => Promise<SQLiteDB>) => new SQLiteServer(dbFactory);
export class SQLiteServer {
constructor(
private dbFactory: () => Promise<SQLiteDB>,
) {}
handleExecute = async (req: Request) => {
const { statement } = await req.json<any>();
const sqlite = await this.dbFactory();
const res = await sqlite.execute(statement);
return Response.json(res);
};
handleBatch = async (req: Request) => {
const { statements } = await req.json<any>();
const sqlite = await this.dbFactory();
const res = await sqlite.batch(statements);
return Response.json(res);
};
}