database

package
v1.20.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 8, 2026 License: BSD-3-Clause Imports: 9 Imported by: 0

Documentation

Overview

Package database provides SQLite database setup for the ent ORM client. Uses modernc.org/sqlite (CGo-free) with WAL mode and FK constraints.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Open

func Open(dbPath string, traceSQL bool) (*ent.Client, *sql.DB, error)

Open creates an ent client connected to the SQLite database at dbPath. The database is configured with WAL journal mode, foreign key enforcement, a 5-second busy timeout, and bulk-write-tuned pragmas. It returns both the ent client and the underlying *sql.DB for raw SQL operations (e.g., sync_status table).

DSN pragma rationale:

  • synchronous(NORMAL): safe under LiteFS-replicated WAL — LiteFS provides durability via streaming replication so per-commit local fsync is redundant overhead. Halves the per-commit syscall cost on the bulk- upsert tx; the Fly primary's local WAL is replayed on replicas regardless of the local fsync mode.
  • cache_size(-32000): 32 MB page cache (negative value = KiB). Default is ~2 MB. The bulk-upsert workload reuses recently-read pages heavily during the ~60s upsert burst; 32 MB fits comfortably under the Fly 512 MB primary VM cap (sync peak heap ~37 MB, peak RSS ~232 MB observed in production).
  • temp_store(MEMORY): keeps sorter and temp tables in RAM. modernc.org/ sqlite's default is FILE which on Fly hits the rootfs overlay (NOT tmpfs — verified via /proc/mounts).

When traceSQL is true the underlying *sql.DB is opened through XSAM/otelsql, so every query — ent's and the raw sync_status statements that share this handle — emits an OpenTelemetry span beneath the active request/sync span. Controlled by PDBPLUS_OTEL_SQL (default on; set false to disable). Span volume is bounded by the trace sampler: scheduled sync cycles are not traced, so the high-volume sync path produces no DB spans — see internal/otel sampler. The low-signal sql.rows and sql.conn.reset_session span types are suppressed (see WithSpanOptions below): they roughly halve the span count per request trace and remove the orphan single-span traces that pool-lifecycle and boot-time schema-migration DB operations otherwise emit with no request root.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL