Documentation
¶
Index ¶
- Variables
- func BindGoFlags()
- func DefaultGormConfig() *gormDriver.Config
- func Delete(ctx dbContext.Context, model Table) error
- func FreePort() (int, error)
- func InitDB(config api.Config) (*dbContext.Context, error)
- func NewDB(connection string) (*sql.DB, error)
- func NewGorm(connection string, config *gorm.Config) (*gorm.DB, error)
- func NewPgxPool(connection string) (*pgxpool.Pool, error)
- func Now() clause.Expr
- func SetupDB(connectionString string, logName string) (gormDB *gormDriver.DB, pgxPool *pgxpool.Pool, err error)
- func StartEmbedded(cfg EmbeddedConfig) (dsn string, stop func() error, err error)
- type EmbeddedConfig
- type Table
Constants ¶
This section is empty.
Variables ¶
var DefaultQueryTimeout = 30 * time.Second
var LogLevel string
LogLevel is the log level for gorm logger
Functions ¶
func DefaultGormConfig ¶
func DefaultGormConfig() *gormDriver.Config
DefaultGormConfig returns the default GORM configuration
func FreePort ¶ added in v0.1.7
FreePort binds :0 to discover a free TCP port. Public so callers can reuse it for adjacent services (e.g. postgrest) that need an unclaimed port.
func InitDB ¶
InitDB creates a context with database connections Note: Does NOT check for migrations - consumers should verify migrations separately
func NewPgxPool ¶
NewPgxPool creates a new pgx connection pool with OpenTelemetry tracing
func SetupDB ¶
func SetupDB(connectionString string, logName string) (gormDB *gormDriver.DB, pgxPool *pgxpool.Pool, err error)
SetupDB creates database connections (gorm.DB and pgxpool.Pool) Note: This does NOT run migrations - consumers should handle migrations separately
func StartEmbedded ¶ added in v0.1.7
func StartEmbedded(cfg EmbeddedConfig) (dsn string, stop func() error, err error)
StartEmbedded launches a fergusstrange/embedded-postgres under cfg.DataDir and returns the DSN plus a stop() closer. If a postmaster.pid exists in the data directory we assume a previous instance is still up and reuse its port (reading posmasterLinePort from postmaster.pid), matching the reference implementation in duty/start.go:205.
The returned stop() is a no-op when we reused an existing postmaster — we don't own that process, so we must not stop it.
Types ¶
type EmbeddedConfig ¶ added in v0.1.7
type EmbeddedConfig struct {
// DataDir is where postgres keeps its cluster, runtime, and binaries.
// The caller owns this choice; StartEmbedded does not pick a default path.
DataDir string
// Database created on first start. Defaults to "postgres" when blank.
Database string
// Port to bind. Zero picks a free port via FreePort().
Port uint32
// Username / Password. Default to "postgres"/"postgres" — fine for the
// localhost-only instances this helper is meant for.
Username, Password string
}
EmbeddedConfig configures StartEmbedded.