Documentation
¶
Overview ¶
Package db provides driver-agnostic helpers for opening *sql.DB connections and tuning them for hex applications.
hex/db imports no SQL driver and no migration tooling. Consumers:
- Blank-import their driver of choice (e.g. modernc.org/sqlite, github.com/lib/pq).
- Import a companion migration subpackage (hex/db/sqlite, hex/db/postgres) if they use golang-migrate.
This keeps hex/db's dependency footprint tiny and prevents unused drivers from being linked into every binary. See ADR-0004.
Example:
import (
_ "modernc.org/sqlite"
"github.com/jordanbrauer/hex/db"
hexsqlite "github.com/jordanbrauer/hex/db/sqlite"
)
//go:embed migrations/*.sql
var migrations embed.FS
conn, err := db.Open(ctx, db.Config{
Driver: "sqlite",
DSN: "/var/lib/myapp.db",
Pragmas: []string{"journal_mode = WAL"},
})
if err != nil { return err }
if err := hexsqlite.Migrate(conn, migrations, "migrations"); err != nil {
return err
}
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Config ¶
type Config struct {
// Driver is the sql.Open driver name (e.g. "sqlite", "postgres"). The
// consumer must blank-import the driver package for this name to
// resolve at runtime.
Driver string
// DSN is the data source name passed to sql.Open. Format is
// driver-specific.
DSN string
// Pragmas are executed once immediately after the connection is opened.
// The strings are passed through to Exec verbatim, so callers control
// whether to prefix "PRAGMA ", "SET ", etc.
Pragmas []string
// Pool configuration. Zero means "use driver default".
MaxOpenConns int
MaxIdleConns int
ConnMaxLifetime time.Duration
ConnMaxIdleTime time.Duration
}
Config describes how to open a database connection.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package lua exposes hex/db to Lua scripts via a gopher-lua module named "db".
|
Package lua exposes hex/db to Lua scripts via a gopher-lua module named "db". |
|
Package postgres runs golang-migrate migrations against a Postgres database.
|
Package postgres runs golang-migrate migrations against a Postgres database. |
|
Package provider is the default hex/db service provider.
|
Package provider is the default hex/db service provider. |
|
Package sqlite runs golang-migrate migrations against a SQLite database.
|
Package sqlite runs golang-migrate migrations against a SQLite database. |
Click to show internal directories.
Click to hide internal directories.