/**
 * JSI BINDINGS DO NOT WORK WHEN CONNECTED TO THE CHROME DEBUGGER
 * Use flipper to debug your RN apps from now on
 */

/**
 * Object returned by SQL Query executions {
 *  status: 0 or undefined for correct execution, 1 for error
 *  insertId: Represent the auto-generated row id if applicable
 *  rowsAffected: Number of affected rows if result of a update query
 *  message: if status === 1, here you will find error description
 *  rows: if status is undefined or 0 this object will contain the query results
 * }
 *
 * @interface QueryResult
 */
// API FOR TYPEORM
export const openDatabase = (options, ok, fail) => {
  try {
    sqlite.open(options.name, options.location);
    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); // Add 'item' function to result object to allow the sqlite-storage typeorm driver to work

          if (response.rows != null) {
            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);
  }
};
//# sourceMappingURL=index.js.map