export function makeDbAdapter(sqlite3, handle) {
    const prepare = async (sql) => {
        const iter = sqlite3.statements(handle, sql, { unscoped: true });
        const { value } = await iter.next();
        if (iter.return)
            await iter.return();
        if (!value) {
            throw new Error(`Failed to prepare statement: ${sql}`);
        }
        return value;
    };
    return {
        prepare,
        bind: async (stmt, index, value) => sqlite3.bind(stmt, index, value),
        step: async (stmt) => sqlite3.step(stmt),
        column_text: async (stmt, index) => sqlite3.column_text(stmt, index),
        finalize: async (stmt) => sqlite3.finalize(stmt),
        exec: async (sql) => sqlite3.exec(handle, sql),
        close: async () => sqlite3.close(handle),
    };
}
