import {
  init_schema,
  schema_exports
} from "./chunk-DDJOPRB7.js";
import {
  getDb,
  init_client
} from "./chunk-TLEKKGH7.js";
import {
  __esm
} from "./chunk-2ESYSVXG.js";

// src/db/drizzle.ts
import { BetterSQLiteSession } from "drizzle-orm/better-sqlite3/session";
import { BaseSQLiteDatabase } from "drizzle-orm/sqlite-core/db";
import { SQLiteSyncDialect } from "drizzle-orm/sqlite-core/dialect";
import {
  createTableRelationsHelpers,
  extractTablesRelationalConfig
} from "drizzle-orm/relations";
import { entityKind } from "drizzle-orm/entity";
function getDrizzle() {
  if (g.__caDrizzle) return g.__caDrizzle;
  const raw = getDb();
  const dialect = new SQLiteSyncDialect({});
  const tablesConfig = extractTablesRelationalConfig(
    schema_exports,
    createTableRelationsHelpers
  );
  const schemaConfig = {
    fullSchema: schema_exports,
    schema: tablesConfig.tables,
    tableNamesMap: tablesConfig.tableNamesMap
  };
  const session = new BetterSQLiteSession(
    raw,
    dialect,
    schemaConfig,
    {}
  );
  class LibSQLDatabase extends BaseSQLiteDatabase {
    static [entityKind] = "LibSQLDatabase";
  }
  g.__caDrizzle = new LibSQLDatabase("sync", dialect, session, schemaConfig);
  return g.__caDrizzle;
}
var g;
var init_drizzle = __esm({
  "src/db/drizzle.ts"() {
    init_client();
    init_schema();
    g = globalThis;
  }
});

export {
  getDrizzle,
  init_drizzle
};
