"use strict";

Object.defineProperty(exports, "__esModule", {
  value: true
});
exports.openDatabase = void 0;

// IMPORTANT!!!!!!!!!!!
// JSI BINDINGS DO NOT WORK WHEN CONNECTED TO THE DEBUGGER
// This is a low level api
// Make it globally available
// API FOR TYPEORM
const openDatabase = (options, ok, fail) => {
  try {
    sqlite.open(options.name);
    const connection = {
      executeSql: (sql, params, ok, fail) => {
        try {
          // console.warn(`[react-native-quick-sqlite], sql: `, sql, ` params: ` , params);
          let response = sqlite.executeSql(options.name, sql, params); // enhance object to allow the sqlite-storage typeorm driver to work

          response.rows.item = idx => response.rows._array[idx];

          ok(response);
        } catch (e) {
          fail(e);
        }
      },
      close: (ok, fail) => {
        try {
          sqlite.close(options.name);
          ok();
        } catch (e) {
          fail(e);
        }
      }
    };
    ok(connection);
  } catch (e) {
    fail(e);
  }
};

exports.openDatabase = openDatabase;
//# sourceMappingURL=index.js.map