session

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 11 Imported by: 1

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CarryModel added in v0.2.9

func CarryModel(m builder.Model, s Session) contextx.Carrier

CarryModel returns a Carrier that applies WithModel.

func CarrySchemaModel added in v0.2.9

func CarrySchemaModel(m builder.Model, s Session) contextx.Carrier

CarrySchemaModel returns a Carrier that applies WithSchemaModel.

func InTx added in v0.2.9

func InTx(ctx context.Context) bool

InTx reports whether ctx carries an active *sql.Tx executor.

func Register added in v0.2.2

func Register(cats ...builder.Catalog)

Register records tables from cats and panics if a table key is registered twice. The key is TableName, or Schema.TableName when the table has a schema.

func With added in v0.0.4

func With(ctx context.Context, s Session) context.Context

With binds s into ctx under s.Name().

func WithModel added in v0.2.9

func WithModel(ctx context.Context, m builder.Model, s Session) context.Context

WithModel binds s into ctx under m.TableName().

func WithSchemaModel added in v0.2.9

func WithSchemaModel(ctx context.Context, m builder.Model, s Session) context.Context

WithSchemaModel binds s into ctx under the schema-qualified model key.

Types

type AdaptorOption added in v0.1.18

type AdaptorOption struct {
	// ReadOnly selects the read-only adaptor when true.
	ReadOnly bool
}

AdaptorOption configures Adaptor selection.

type AdaptorOptionApplier added in v0.2.1

type AdaptorOptionApplier func(*AdaptorOption)

AdaptorOptionApplier mutates AdaptorOption.

func ReadOnly added in v0.0.3

func ReadOnly() AdaptorOptionApplier

ReadOnly selects the read-only adaptor from NewReadonly.

type Session added in v0.0.3

type Session interface {
	// Name returns the logical session name.
	Name() string
	// T resolves a table from a model, Table, or WithTable value.
	T(any) builder.Table
	// Adaptor returns the underlying adaptor; ReadOnly() selects the RO adaptor when set.
	Adaptor(...AdaptorOptionApplier) adaptor.Adaptor

	// Tx runs fn inside a transaction on the RW adaptor.
	Tx(context.Context, func(context.Context) error) error
	// Exec executes f on the RW adaptor.
	Exec(context.Context, frag.Fragment) (sql.Result, error)
	// Query runs f on the RW adaptor.
	Query(context.Context, frag.Fragment) (*sql.Rows, error)
}

Session is a named database access handle.

func For added in v0.0.3

func For(ctx context.Context, m any) (Session, bool)

For retrieves a Session by session name (string) or model (builder.Model).

func From added in v0.0.4

func From(ctx context.Context, name string) (Session, bool)

From retrieves a Session bound under the given name.

func FromByModel added in v0.2.9

func FromByModel(ctx context.Context, m builder.Model) (Session, bool)

FromByModel retrieves a Session by schema-qualified key, falling back to TableName.

func Must added in v0.2.1

func Must(ctx context.Context, name string) Session

Must is like From but panics when the session is missing.

func MustByModel added in v0.2.9

func MustByModel(ctx context.Context, m builder.Model) Session

MustByModel is like FromByModel but panics when the session is missing.

func MustFor added in v0.2.1

func MustFor(ctx context.Context, m any) Session

MustFor is like For but panics when the session is missing.

func New added in v0.0.3

func New(a adaptor.Adaptor, name string) Session

New creates a Session backed by a single adaptor.

func NewReadonly added in v0.2.1

func NewReadonly(rw adaptor.Adaptor, ro adaptor.Adaptor, name string) Session

NewReadonly creates a Session with separate read-write and read-only adaptors.

Jump to

Keyboard shortcuts

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