import {
  __esm,
  __export
} from "./chunk-8sqjbsgt.js";

// packages/core/src/db/bun-adapter.ts
var exports_bun_adapter = {};
__export(exports_bun_adapter, {
  bunSqliteFactory: () => bunSqliteFactory
});
import { createRequire } from "node:module";

class BunSqliteAdapter {
  db;
  isOpen = true;
  constructor(path) {
    this.db = new (bunDatabase())(path);
  }
  get open() {
    return this.isOpen;
  }
  exec(sql) {
    this.db.exec(sql);
  }
  prepare(sql) {
    const stmt = this.db.prepare(sql);
    return {
      all: (...params) => stmt.all(...params),
      get: (...params) => stmt.get(...params) ?? null,
      run: (...params) => {
        const r = stmt.run(...params);
        return { changes: Number(r.changes), lastInsertRowid: r.lastInsertRowid };
      }
    };
  }
  pragma(statement) {
    const trimmed = statement.trim();
    if (trimmed.includes("=")) {
      this.db.exec(`PRAGMA ${trimmed}`);
      return;
    }
    return this.db.prepare(`PRAGMA ${trimmed}`).get();
  }
  transaction(fn) {
    return this.db.transaction(fn);
  }
  loadExtension(path) {
    this.db.loadExtension(path);
  }
  close() {
    if (!this.isOpen)
      return;
    this.db.close();
    this.isOpen = false;
  }
}
var nodeRequire, _Database, bunDatabase = () => {
  if (!_Database) {
    const spec = ["bun", "sqlite"].join(":");
    _Database = nodeRequire(spec).Database;
  }
  return _Database;
}, bunSqliteFactory;
var init_bun_adapter = __esm(() => {
  nodeRequire = createRequire(import.meta.url);
  bunSqliteFactory = {
    open: (path) => new BunSqliteAdapter(path)
  };
});

export { bunSqliteFactory, exports_bun_adapter, init_bun_adapter };
