import { openDatabaseSync, deleteDatabaseSync } from "expo-sqlite";
import { SQLiteStore, dropStore } from "../sqlite-store.js";
function dropExpoSQLiteStore(name) {
  return dropStore(name, (filename) => new ExpoSQLiteDatabase(filename));
}
function expoSQLiteStoreProvider(opts) {
  return {
    create: (name) => new SQLiteStore(name, (name2) => new ExpoSQLiteDatabase(name2), opts),
    drop: dropExpoSQLiteStore
  };
}
class ExpoSQLitePreparedStatement {
  #statement;
  constructor(statement) {
    this.#statement = statement;
  }
  async firstValue(params) {
    const result = await this.#statement.executeForRawResultAsync(params);
    const row = await result.getFirstAsync();
    return row === null ? void 0 : row[0];
  }
  async exec(params) {
    await this.#statement.executeForRawResultAsync(params);
  }
}
class ExpoSQLiteDatabase {
  #db;
  #filename;
  #statements = /* @__PURE__ */ new Set();
  constructor(filename) {
    this.#filename = filename;
    this.#db = openDatabaseSync(filename);
  }
  close() {
    for (const stmt of this.#statements) {
      stmt.finalizeSync();
    }
    this.#db.closeSync();
  }
  destroy() {
    deleteDatabaseSync(this.#filename);
  }
  prepare(sql) {
    const statement = this.#db.prepareSync(sql);
    this.#statements.add(statement);
    return new ExpoSQLitePreparedStatement(statement);
  }
  execSync(sql) {
    this.#db.execSync(sql);
  }
}
export {
  dropExpoSQLiteStore,
  expoSQLiteStoreProvider
};
//# sourceMappingURL=store.js.map
