bunquery

package module
v0.0.0-...-b5b159f Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2025 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SortAscending  uint8 = 0x00
	SortDescending uint8 = 0x01
	SortUnknown    uint8 = 0xFF
)

Variables

View Source
var ErrNoContext = errors.New("no db context")

Functions

func CreateMutation

func CreateMutation[In any](def Mutation[In]) func(ctx context.Context, args In) error

func CreateMutationEx

func CreateMutationEx[In any, Ext any](def MutationEx[In, Ext]) func(ctx context.Context, args In, ext Ext) error

func CreateQuery

func CreateQuery[In any, Out any](def Query[In, Out]) func(ctx context.Context, args In) (Out, error)

func CreateQueryEx

func CreateQueryEx[In any, Out any, Ext any](def QueryEx[In, Out, Ext]) func(ctx context.Context, args In, ext Ext) (Out, error)

func CreateQueryMutation

func CreateQueryMutation[In any, Out any](def QueryMutation[In, Out]) func(ctx context.Context, args In) (Out, error)

func CreateQueryMutationEx

func CreateQueryMutationEx[In any, Out any, Ext any](def QueryMutationEx[In, Out, Ext]) func(ctx context.Context, args In, ext Ext) (Out, error)

func FormatContinuation

func FormatContinuation(sid uint32, directions []uint8, values []any, reverse, include bool) (string, error)

func NewContext

func NewContext(ctx context.Context, db bun.IDB, mods ...QueryMod) context.Context

func PascalToDelimited

func PascalToDelimited(s string, delim string) string

func UseContextMods

func UseContextMods(ctx context.Context, mods ...QueryMod) (context.Context, error)

func UseMutation

func UseMutation(ctx context.Context, fn func(ctx context.Context, db MutationDB) error, opts ...AnyOpt) error

func UseQuery

func UseQuery(ctx context.Context, fn func(ctx context.Context, db QueryDB) error, opts ...AnyOpt) error

Types

type AnyOpt

type AnyOpt interface {
	Apply(opts any)
}

type Continuation

type Continuation struct {
	SID        uint32
	Directions []uint8
	Values     []any
	Reverse    bool
	Include    bool
}

func NewContinuation

func NewContinuation(sid uint32, directions []uint8, values []any, reverse, include bool) *Continuation

func ParseContinuation

func ParseContinuation(token string) (*Continuation, error)

func (*Continuation) String

func (c *Continuation) String() (string, error)

type Mutation

type Mutation[In any] struct {
	Args      func(args In) (In, error)
	Handler   func(ctx context.Context, db MutationDB, args In) error
	Use       []QueryMod
	TxOptions *sql.TxOptions
}

type MutationDB

type MutationDB interface {
	QueryDB
	NewInsert() *bun.InsertQuery
	NewUpdate(bindArgs ...any) *bun.UpdateQuery
	NewDelete(bindArgs ...any) *bun.DeleteQuery
}

type MutationEx

type MutationEx[In any, Ext any] struct {
	Args      func(args In) (In, error)
	Handler   func(ctx context.Context, db MutationDB, args In, ext Ext) error
	Use       []QueryMod
	TxOptions *sql.TxOptions
}

type MutationOpt

type MutationOpt func(*MutationOpts)

func WithTxOptions

func WithTxOptions(txOptions *sql.TxOptions) MutationOpt

func (MutationOpt) Apply

func (opt MutationOpt) Apply(opts any)

type MutationOpts

type MutationOpts struct {
	QueryOpts
	TxOptions *sql.TxOptions
}

func NewMutationOpts

func NewMutationOpts(opts ...AnyOpt) *MutationOpts

type Pager

type Pager[M Sortable] struct {
	// contains filtered or unexported fields
}

func NewPager

func NewPager[M Sortable](model M, opts ...PagerOption) (*Pager[M], error)

func NewPagerFromContinuation

func NewPagerFromContinuation[M Sortable](token string, opts ...PagerOption) (*Pager[M], error)

func NewPagerFromOrder

func NewPagerFromOrder[M Sortable](model M, order string, opts ...PagerOption) (*Pager[M], error)

func NewPagerFromRequest

func NewPagerFromRequest[M Sortable](model M, req PagingRequest, opts ...PagerOption) (*Pager[M], error)

func NewPagerFromSID

func NewPagerFromSID[M Sortable](sid uint32, opts ...PagerOption) (*Pager[M], error)

func (*Pager[M]) Compile

func (p *Pager[M]) Compile() func(qry *bun.SelectQuery) *bun.SelectQuery

func (*Pager[M]) Map

func (p *Pager[M]) Map(results []M) ([]M, string, string, error)

type PagerOption

type PagerOption = func(*PagerOptions)

func WithForwardOnly

func WithForwardOnly() PagerOption

func WithPageSize

func WithPageSize(size int) PagerOption

type PagerOptions

type PagerOptions struct {
	ForwardOnly bool
	PageSize    int
}

func NewOptions

func NewOptions(opts ...PagerOption) *PagerOptions

type PagingRequest

type PagingRequest interface {
	GetContinue() string
	GetOrder() string
}

type Patch

type Patch[Target any, Derived any] struct {
	// contains filtered or unexported fields
}

func CreatePatch

func CreatePatch[Target any, Derived any](target *Target, derived *Derived) Patch[Target, Derived]

func (*Patch[Target, Derived]) Compile

func (patch *Patch[Target, Derived]) Compile() func(*bun.UpdateQuery) *bun.UpdateQuery

func (*Patch[Target, Derived]) Target

func (patch *Patch[Target, Derived]) Target() *Target

type Query

type Query[In any, Out any] struct {
	Args    func(args In) (In, error)
	Handler func(ctx context.Context, db QueryDB, args In) (Out, error)
	Use     []QueryMod
}

type QueryAppenderFunc

type QueryAppenderFunc func(fmter schema.Formatter, b []byte) ([]byte, error)

func TableAlias

func TableAlias(value any) QueryAppenderFunc

func TableName

func TableName(value any) QueryAppenderFunc

func (QueryAppenderFunc) AppendQuery

func (f QueryAppenderFunc) AppendQuery(fmter schema.Formatter, b []byte) ([]byte, error)

type QueryBuilderEx

type QueryBuilderEx interface {
	bun.QueryBuilder
	With(name string, query bun.Query) QueryBuilderEx
	Err(err error) QueryBuilderEx
}

func NewQueryBuilderEx

func NewQueryBuilderEx[Query any, Source SupportsQueryBuilderEx[Query]](qry Source) QueryBuilderEx

type QueryDB

type QueryDB interface {
	Unwrap() bun.IDB
	NewSelect(bindArgs ...any) *bun.SelectQuery
}

func UseQueryDB

func UseQueryDB(ctx context.Context, opts ...AnyOpt) (QueryDB, error)

type QueryEx

type QueryEx[In any, Out any, Ext any] struct {
	Args    func(args In) (In, error)
	Handler func(ctx context.Context, db QueryDB, args In, ext Ext) (Out, error)
	Use     []QueryMod
}

type QueryMod

type QueryMod interface {
	Kind() string
	Bind(context.Context, bun.IDB, QueryBuilderEx, ...any)
}

func NewQueryMod

func NewQueryMod(kind string, fn func(ctx context.Context, iDB bun.IDB, query QueryBuilderEx, args ...any)) QueryMod

type QueryMods

type QueryMods []QueryMod

func FromContext

func FromContext(ctx context.Context) (bun.IDB, QueryMods, error)

func (QueryMods) Bind

func (m QueryMods) Bind(ctx context.Context, db bun.IDB, qry QueryBuilderEx, args ...any)

func (QueryMods) Use

func (m QueryMods) Use(mods ...QueryMod) QueryMods

type QueryMutation

type QueryMutation[In any, Out any] struct {
	Args      func(args In) (In, error)
	Handler   func(ctx context.Context, db MutationDB, args In) (Out, error)
	Use       []QueryMod
	TxOptions *sql.TxOptions
}

type QueryMutationEx

type QueryMutationEx[In any, Out any, Ext any] struct {
	Args      func(args In) (In, error)
	Handler   func(ctx context.Context, db MutationDB, args In, ext Ext) (Out, error)
	Use       []QueryMod
	TxOptions *sql.TxOptions
}

type QueryOpt

type QueryOpt func(*QueryOpts)

func WithMods

func WithMods(mods ...QueryMod) QueryOpt

func (QueryOpt) Apply

func (opt QueryOpt) Apply(opts any)

type QueryOpts

type QueryOpts struct {
	Mods []QueryMod
}

func NewQueryOpts

func NewQueryOpts(opts ...AnyOpt) *QueryOpts

type ResourcePatcher

type ResourcePatcher[Resource any] interface {
	Target() *Resource
}

type Sort

type Sort[M Sortable] struct {
	// contains filtered or unexported fields
}

func NewSort

func NewSort[M Sortable](model M) *Sort[M]

func (*Sort[M]) Column

func (s *Sort[M]) Column(cols ...string) *Sort[M]

func (*Sort[M]) Default

func (s *Sort[M]) Default() *Sort[M]

func (*Sort[M]) Direction

func (s *Sort[M]) Direction(dirs ...uint8) *Sort[M]

func (*Sort[M]) MustRegister

func (s *Sort[M]) MustRegister() uint32

func (*Sort[M]) Order

func (s *Sort[M]) Order(exprs ...string) *Sort[M]

func (*Sort[M]) Register

func (s *Sort[M]) Register() (uint32, error)

type Sortable

type Sortable interface {
	GetSortValues(rid uint32) []any
}

type SupportsQueryBuilderEx

type SupportsQueryBuilderEx[P any] interface {
	*P
	QueryBuilder() bun.QueryBuilder
	With(name string, query bun.Query) *P
	Err(err error) *P
}

Directories

Path Synopsis
v

Jump to

Keyboard shortcuts

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