/**
 * @wrnexus/db — the data layer core: TS models (source of truth for DDL,
 * validation, and result typing), the `Driver` interface, and the `Db` client.
 *
 * Adapters are imported from subpaths, e.g. `@wrnexus/db/sqlite`. Migrations and
 * the sqlc-style query generator build on this core in later phases.
 */

export { v, table, Column } from "./schema.ts";
export type { Model, Columns, ColumnDef, BaseType } from "./schema.ts";
export { createDb } from "./driver.ts";
export type { Db, Driver, Row, ExecResult, TxHandle } from "./driver.ts";
export {
  setDb,
  getDb,
  hasDb,
  registerDb,
  registerLazyDb,
  databaseNames,
  closeDatabases,
} from "./client.ts";
export { createTableSql } from "./sql.ts";
export type { Dialect } from "./sql.ts";
export {
  parseMigration,
  loadMigrations,
  appliedMigrations,
  applyMigrations,
  migrate,
  rollback,
  status,
  scaffoldMigration,
} from "./migrate.ts";
export type { Migration, MigrationRunOptions } from "./migrate.ts";
export { analyzeMigrationSafety, analyzeMigrations } from "./migration-safety.ts";
export type { MigrationSafetyIssue } from "./migration-safety.ts";
export { parseQueries, generateQueriesFile } from "./generate.ts";
export type { QueryDef, QueryKind, ModelRef } from "./generate.ts";
export { paginate, loadRelated } from "./query.ts";
export type { Paginated, PageOptions, RelationOptions } from "./query.ts";
export { cursorPaginate, optimisticUpdate, tenantScope, softDeleteClause } from "./advanced.ts";
export type { CursorPage, CursorPageOptions } from "./advanced.ts";

export {
  instrumentDb,
  queryOperation,
  getDbPerformanceSnapshot,
  resetDbPerformanceSnapshot,
} from "./performance.ts";
export type { QueryIssue, QueryPolicy, QueryRecord } from "./performance.ts";
export {
  RecordNotFoundError,
  firstOrThrow,
  exists,
  countRows,
  withTransaction,
  retryTransaction,
  batch,
  databaseHealth,
  createRepository,
} from "./helpers.ts";
export type { Repository } from "./helpers.ts";
