db

package
v0.1.7 Latest Latest
Warning

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

Go to latest
Published: Apr 19, 2026 License: Apache-2.0 Imports: 25 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultQueryTimeout = 30 * time.Second
View Source
var LogLevel string

LogLevel is the log level for gorm logger

Functions

func BindGoFlags

func BindGoFlags()

BindGoFlags binds database flags to the provided flag set

func DefaultGormConfig

func DefaultGormConfig() *gormDriver.Config

DefaultGormConfig returns the default GORM configuration

func Delete

func Delete(ctx dbContext.Context, model Table) error

Delete performs a soft delete on the given model

func FreePort added in v0.1.7

func FreePort() (int, error)

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

func InitDB(config api.Config) (*dbContext.Context, error)

InitDB creates a context with database connections Note: Does NOT check for migrations - consumers should verify migrations separately

func NewDB

func NewDB(connection string) (*sql.DB, error)

NewDB creates a new sql.DB connection

func NewGorm

func NewGorm(connection string, config *gorm.Config) (*gorm.DB, error)

NewGorm creates a new Gorm DB connection using the provided connection string

func NewPgxPool

func NewPgxPool(connection string) (*pgxpool.Pool, error)

NewPgxPool creates a new pgx connection pool with OpenTelemetry tracing

func Now

func Now() clause.Expr

Now returns a SQL expression for the current timestamp

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.

type Table

type Table interface {
	TableName() string
}

Table interface for models with TableName

Jump to

Keyboard shortcuts

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