Documentation
¶
Index ¶
- func CarryModel(m builder.Model, s Session) contextx.Carrier
- func CarrySchemaModel(m builder.Model, s Session) contextx.Carrier
- func InTx(ctx context.Context) bool
- func Register(cats ...builder.Catalog)
- func With(ctx context.Context, s Session) context.Context
- func WithModel(ctx context.Context, m builder.Model, s Session) context.Context
- func WithSchemaModel(ctx context.Context, m builder.Model, s Session) context.Context
- type AdaptorOption
- type AdaptorOptionApplier
- type Session
- func For(ctx context.Context, m any) (Session, bool)
- func From(ctx context.Context, name string) (Session, bool)
- func FromByModel(ctx context.Context, m builder.Model) (Session, bool)
- func Must(ctx context.Context, name string) Session
- func MustByModel(ctx context.Context, m builder.Model) Session
- func MustFor(ctx context.Context, m any) Session
- func New(a adaptor.Adaptor, name string) Session
- func NewReadonly(rw adaptor.Adaptor, ro adaptor.Adaptor, name string) Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CarryModel ¶ added in v0.2.9
CarryModel returns a Carrier that applies WithModel.
func CarrySchemaModel ¶ added in v0.2.9
CarrySchemaModel returns a Carrier that applies WithSchemaModel.
func Register ¶ added in v0.2.2
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.
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
For retrieves a Session by session name (string) or model (builder.Model).
func FromByModel ¶ added in v0.2.9
FromByModel retrieves a Session by schema-qualified key, falling back to TableName.
func MustByModel ¶ added in v0.2.9
MustByModel is like FromByModel but panics when the session is missing.