one

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2026 License: MIT Imports: 10 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApplicationSetting

type ApplicationSetting struct {
	Key   string
	Value string
}

type DBTX

type DBTX interface {
	Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error)
	Query(context.Context, string, ...interface{}) (pgx.Rows, error)
	QueryRow(context.Context, string, ...interface{}) pgx.Row
}

type Querier

type Querier interface {
	// kind: read
	// store: Settings
	GetSetting(ctx context.Context, key string) (*ApplicationSetting, error)
	// kind: write
	// store: Settings
	UpsertSetting(ctx context.Context, arg *UpsertSettingParams) (*ApplicationSetting, error)
}

type Queries

type Queries struct {
	// contains filtered or unexported fields
}

func New

func New(db DBTX) *Queries

func (*Queries) GetSetting

func (q *Queries) GetSetting(ctx context.Context, key string) (*ApplicationSetting, error)

kind: read store: Settings

func (*Queries) UpsertSetting

func (q *Queries) UpsertSetting(ctx context.Context, arg *UpsertSettingParams) (*ApplicationSetting, error)

kind: write store: Settings

func (*Queries) WithTx

func (q *Queries) WithTx(tx pgx.Tx) *Queries

type QueryOption

type QueryOption func(*queryOptions)

QueryOption customizes routing for one generated query call.

func ReadFromPrimary

func ReadFromPrimary() QueryOption

ReadFromPrimary routes a read query to the primary database.

func WithTx

func WithTx(tx pgx.Tx) QueryOption

WithTx executes a query through tx and suppresses write mirrors.

type Settings

type Settings interface {
	SettingsReader
	SettingsWriter
}

Settings exposes all queries in its generated store group.

type SettingsReader

type SettingsReader interface {
	// GetSetting executes the generated GetSetting query.
	GetSetting(ctx context.Context, key string, storeOptions ...QueryOption) (*ApplicationSetting, error)
}

SettingsReader exposes read queries in the Settings store group.

type SettingsWriter

type SettingsWriter interface {
	// UpsertSetting executes the generated UpsertSetting query.
	UpsertSetting(ctx context.Context, arg *UpsertSettingT, storeOptions ...QueryOption) (*ApplicationSetting, error)
}

SettingsWriter exposes write queries in the Settings store group.

type SingletonOption

type SingletonOption func(*singletonConfig)

SingletonOption customizes a single-database topology.

func WithDatabaseName

func WithDatabaseName(name string) SingletonOption

WithDatabaseName identifies the database in telemetry. An empty name defaults to "default".

func WithReadReplicas

func WithReadReplicas(databases ...DBTX) SingletonOption

WithReadReplicas appends databases used for round-robin reads.

func WithWriteMirrors

func WithWriteMirrors(databases ...DBTX) SingletonOption

WithWriteMirrors appends databases that synchronously receive writes.

type Store

type Store interface {
	// Settings returns the Settings query group.
	Settings() Settings
}

Store is the topology-independent generated query API.

func NewStore

func NewStore(ctx context.Context, topology Topology, options ...StoreOption) (Store, error)

NewStore creates the generated query API from an opaque topology configuration.

type StoreOption

type StoreOption func(*storeOptions)

StoreOption customizes a generated store.

func WithLogger

func WithLogger(logger *slog.Logger) StoreOption

WithLogger configures optional structured logging for routed queries. A nil logger disables logging.

func WithMeterProvider

func WithMeterProvider(provider metric.MeterProvider) StoreOption

WithMeterProvider configures the provider used for routed query metrics. A nil provider uses the global OpenTelemetry meter provider.

func WithSettingsFactory added in v0.0.3

func WithSettingsFactory(createSettings func(Settings) Settings) StoreOption

WithSettingsFactory configures an optional wrapper for the Settings query group. A nil factory leaves the generated query group unwrapped.

func WithTracerProvider

func WithTracerProvider(provider trace.TracerProvider) StoreOption

WithTracerProvider configures the provider used for routed query spans. A nil provider uses the global OpenTelemetry tracer provider.

type Topology

type Topology interface {
	// contains filtered or unexported methods
}

Topology is an opaque database topology for Store.

func Singleton

func Singleton(primary DBTX, options ...SingletonOption) Topology

Singleton returns a topology with one primary database.

type UpsertSettingParams

type UpsertSettingParams struct {
	Key   string
	Value string
}

type UpsertSettingT added in v0.0.3

type UpsertSettingT = UpsertSettingParams

UpsertSettingT is the store parameter type for UpsertSetting.

Jump to

Keyboard shortcuts

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