stdenttxfx

package
v0.0.237 Latest Latest
Warning

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

Go to latest
Published: May 19, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package stdenttxfx provides database transactors.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Provide

func Provide[T stdent.Tx, C stdent.Client[T]](applicationName string, clientFactory ClientFactoryFunc[T, C]) fx.Option

Provide provides the standard read-write/read-only separation.

func ProvideRWOnly added in v0.0.228

func ProvideRWOnly[T stdent.Tx, C stdent.Client[T]](
	applicationName string,
	clientFactory ClientFactoryFunc[T, C],
) fx.Option

ProvideRWOnly is the read-write-only counterpart of Provide. It deliberately does NOT register a "ro" deriver — callers that wire stdpgxfx must also avoid declaring "ro" as a derived pool, so no read-replica connection pool is opened. The "-rw" application_name suffix is kept so DBA tooling can still distinguish worker traffic from the corresponding web traffic.

func TestProvide

func TestProvide[T stdent.Tx, C stdent.Client[T]](
	applicationName,
	endRoleUsername,
	endRolePassword string,
	clientFactory ClientFactoryFunc[T, C],
) fx.Option

TestProvide provides project-specific transactor config to make it easy for any test package to interact with the database.

func TestProvideRWOnly added in v0.0.228

func TestProvideRWOnly[T stdent.Tx, C stdent.Client[T]](
	applicationName,
	endRoleUsername,
	endRolePassword string,
	clientFactory ClientFactoryFunc[T, C],
) fx.Option

TestProvideRWOnly is the read-write-only counterpart of TestProvide. It supplies the same pgtestdb.Role and stdpgxfx.EndRole values as TestProvide so test setups can swap between the two providers without changing the surrounding wiring.

Types

type ClientFactoryFunc

type ClientFactoryFunc[T stdent.Tx, C stdent.Client[T]] = func(driver dialect.Driver) C

ClientFactoryFunc is a function that creates an ent client from a dialect driver.

type Config

type Config struct {
	TestMaxQueryCosts float64 `env:"TEST_MAX_QUERY_COSTS"`
}

Config configures the transact components.

type Params

type Params[T stdent.Tx, C stdent.Client[T]] struct {
	fx.In
	fx.Lifecycle
	Config
	RW            *sql.DB `name:"rw"`
	RO            *sql.DB `name:"ro"`
	ClientFactory ClientFactoryFunc[T, C]
	TxBeginSQL    stdent.BeginHookFunc `optional:"true"`
}

Params describe fx params for creating the transactors.

type ParamsRWOnly added in v0.0.228

type ParamsRWOnly[T stdent.Tx, C stdent.Client[T]] struct {
	fx.In
	fx.Lifecycle
	Config
	RW            *sql.DB `name:"rw"`
	ClientFactory ClientFactoryFunc[T, C]
	TxBeginSQL    stdent.BeginHookFunc `optional:"true"`
}

ParamsRWOnly is the read-write-only counterpart of Params: it asks for the "rw" *sql.DB but does NOT ask for an "ro" pool. Use it from binaries (such as background workers, CLIs, or migration tools) that have no need to talk to a read replica and shouldn't open a connection pool against one.

type Result

type Result[T stdent.Tx] struct {
	fx.Out
	ReadWrite *stdent.Transactor[T] `name:"rw"`
	ReadOnly  *stdent.Transactor[T] `name:"ro"`
}

Result describes the fx components this package produces.

func New

func New[T stdent.Tx, C stdent.Client[T]](params Params[T, C]) (Result[T], error)

New provides the transactors.

type ResultRWOnly added in v0.0.228

type ResultRWOnly[T stdent.Tx] struct {
	fx.Out
	ReadWrite *stdent.Transactor[T] `name:"rw"`
}

ResultRWOnly only produces the "rw" transactor. The named output stays the same as Result.ReadWrite so downstream code that injects `name:"rw"` works unchanged regardless of which provider was used.

func NewRWOnly added in v0.0.228

func NewRWOnly[T stdent.Tx, C stdent.Client[T]](params ParamsRWOnly[T, C]) (ResultRWOnly[T], error)

NewRWOnly is the read-write-only counterpart of New. It uses the same driverOpts and newPoolClient helpers as New so the rw transactor it returns is byte-identical to the one Provide produces — in particular, the BeginHook and standard driver options are wired in the same way.

Jump to

Keyboard shortcuts

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