import {
  SQLiteStore,
  dropStore
} from "./chunk-ECUMGQGC.js";
import "./chunk-ASRS2LFV.js";
import "./chunk-EZM3XBAB.js";
import "./chunk-424PT5DM.js";

// ../replicache/src/kv/op-sqlite/types.ts
import { open as openDB } from "@op-engineering/op-sqlite";
var open = openDB;

// ../replicache/src/kv/op-sqlite/store.ts
function dropOpSQLiteStore(name) {
  return dropStore(
    name,
    (filename, opts) => new OpSQLiteDatabase(filename, opts)
  );
}
function opSQLiteStoreProvider(opts) {
  return {
    create: (name) => new SQLiteStore(
      name,
      (name2, options) => new OpSQLiteDatabase(name2, options),
      opts
    ),
    drop: dropOpSQLiteStore
  };
}
var OpSQLitePreparedStatement = class {
  #db;
  #sql;
  constructor(db, sql) {
    this.#db = db;
    this.#sql = sql;
  }
  async firstValue(params) {
    const rows = await this.#db.executeRaw(this.#sql, params);
    return rows[0]?.[0];
  }
  async exec(params) {
    await this.#db.executeRaw(this.#sql, params);
  }
};
var OpSQLiteDatabase = class {
  #db;
  #filename;
  constructor(filename, opts) {
    this.#filename = filename;
    const openOpts = { name: filename };
    if (opts?.location) {
      openOpts.location = opts.location;
    }
    if (opts?.encryptionKey) {
      openOpts.encryptionKey = opts.encryptionKey;
    }
    this.#db = open(openOpts);
  }
  close() {
    this.#db.close();
  }
  destroy() {
    try {
      const tempDb = open({ name: this.#filename });
      tempDb.delete();
      tempDb.close();
    } catch (_error) {
    }
  }
  prepare(sql) {
    return new OpSQLitePreparedStatement(this.#db, sql);
  }
  execSync(sql) {
    this.#db.executeRawSync(sql, []);
  }
};
export {
  opSQLiteStoreProvider
};
//# sourceMappingURL=op-sqlite.js.map
