sqlx

package
v0.0.0-...-9f10b00 Latest Latest
Warning

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

Go to latest
Published: Mar 2, 2026 License: Unlicense Imports: 17 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ParamsRegexp = regexp.MustCompile(`\$\{\s*[a-zA-Z_]+[a-zA-Z_0-9]*\s*\}`)
)

Functions

func All

func All[T any](ctx context.Context, stmt *Stmt, sizehint int, args ...any) ([]T, error)

func AsModel

func AsModel[T any]()

func DisableEnsureBackedUp

func DisableEnsureBackedUp()

func First

func First[T any](ctx context.Context, stmt *Stmt, args ...any) (*T, error)

func InitAllLazyStmts

func InitAllLazyStmts(ctx context.Context, mapfn func(*LazyStmt) bool) error

func Logger

func Logger() *slog.Logger

func MustDB

func MustDB(ctx context.Context) *sql.DB

func MustTx

func MustTx(ctx context.Context) *sql.Tx

func Page

func Page[T any](ctx context.Context, stmt *Stmt, rows *sql.Rows, page []T) ([]T, bool, error)

func PeekDB

func PeekDB(ctx context.Context) *sql.DB

func PeekTx

func PeekTx(ctx context.Context) *sql.Tx

func Stream

func Stream[T any](ctx context.Context, stmt *Stmt, rows *sql.Rows) iter.Seq2[*T, error]

Stream the yielded ptr reused for each row, you can not store it.

func Sync

func Sync(ctx context.Context) error

func TxScope

func TxScope(ctx context.Context, f func(ctx context.Context) error, opts *sql.TxOptions) error

func UnwrapSqlNullType

func UnwrapSqlNullType(st reflect.Type) (reflect.Type, bool)

func WithDB

func WithDB(ctx context.Context, db *sql.DB) context.Context

func WithDialect

func WithDialect(ctx context.Context, dialect IDialect) context.Context

func WithExec

func WithExec(ctx context.Context, exec IExecutor) context.Context

func WithTx

func WithTx(ctx context.Context, tx *sql.Tx) context.Context

Types

type IDialect

type IDialect interface {
	EnsureTables(ctx context.Context, infos []*ModelInfo) error

	ParamPlaceholder(index int) string
}

func MustDialect

func MustDialect(ctx context.Context) IDialect

func PeekDialect

func PeekDialect(ctx context.Context) IDialect

type IExecutor

type IExecutor interface {
	QueryContext(ctx context.Context, query string, args ...any) (*sql.Rows, error)
	ExecContext(ctx context.Context, query string, args ...any) (sql.Result, error)
}

func MustExecutor

func MustExecutor(ctx context.Context) IExecutor

func PeekExecutor

func PeekExecutor(ctx context.Context) IExecutor

type Index

type Index struct {
	Name   string
	Unique bool
	Fields []*IndexField
}

type IndexField

type IndexField struct {
	Name string
	Desc bool
	// contains filtered or unexported fields
}

type LazyStmt

type LazyStmt struct {
	*Stmt
	// contains filtered or unexported fields
}

func NewLazyStmt

func NewLazyStmt(rawsql string) *LazyStmt

func (*LazyStmt) Init

func (s *LazyStmt) Init(ctx context.Context) error

func (*LazyStmt) Must

func (s *LazyStmt) Must() *Stmt

func (*LazyStmt) Name

func (s *LazyStmt) Name() string

func (*LazyStmt) String

func (s *LazyStmt) String() string

func (*LazyStmt) WithName

func (s *LazyStmt) WithName(name string) *LazyStmt

type LazyStmtGroup

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

func NewLazyStmtGroup

func NewLazyStmtGroup() *LazyStmtGroup

func (*LazyStmtGroup) InitAll

func (g *LazyStmtGroup) InitAll(ctx context.Context, mapfn func(*LazyStmt) bool) error

func (*LazyStmtGroup) New

func (g *LazyStmtGroup) New(rawsql string) *LazyStmt

type MapOperator

type MapOperator[T any, U any] struct {
	// contains filtered or unexported fields
}

func NewMap

func NewMap[T any, U any](stmt *Stmt, operator func(ctx context.Context, t *T) (U, error)) *MapOperator[T, U]

func (*MapOperator[T, U]) Iter

func (m *MapOperator[T, U]) Iter(ctx context.Context, args ...any) iter.Seq2[U, error]

type ModelField

type ModelField struct {
	Name   string
	GoType reflect.Type
	Opts   rbc.TagOptions
}

func (*ModelField) AutoIncrement

func (f *ModelField) AutoIncrement(keys ...string) bool

func (*ModelField) CheckExpr

func (f *ModelField) CheckExpr(keys ...string) sql.Null[string]

func (*ModelField) DefaultExpr

func (f *ModelField) DefaultExpr(keys ...string) sql.Null[string]

func (*ModelField) GetAny

func (f *ModelField) GetAny(keys ...string) sql.Null[string]

func (*ModelField) HasAny

func (f *ModelField) HasAny(keys ...string) bool

func (*ModelField) IsPrimaryKey

func (f *ModelField) IsPrimaryKey(keys ...string) bool

func (*ModelField) Nullable

func (f *ModelField) Nullable(keys ...string) bool

func (*ModelField) SqlType

func (f *ModelField) SqlType() string

func (*ModelField) Unique

func (f *ModelField) Unique(keys ...string) bool

type ModelInfo

type ModelInfo struct {
	GoType reflect.Type
	Fields []*ModelField
}

func (*ModelInfo) Indexes

func (info *ModelInfo) Indexes(keys ...string) ([]*Index, error)

Indexes returns the indexes of the model. index tag format:

`[!↓>]<indexname>[/<orderidx>]`

- `!` means the index is unique. - `↓` or `>` means the field is sorted in descending order. - `indexname` is the name of the index. - `orderidx` is the order index of the field in the index.

type ReduceOperator

type ReduceOperator[T any, U any] struct {
	// contains filtered or unexported fields
}

func NewReduce

func NewReduce[T any, U any](stmt *Stmt, operator func(context.Context, U, *T) (U, error)) *ReduceOperator[T, U]

func (*ReduceOperator[T, U]) Calc

func (r *ReduceOperator[T, U]) Calc(ctx context.Context, result U, args ...any) (U, error)

type Stmt

type Stmt struct {
	*sql.Stmt
	// contains filtered or unexported fields
}

func NewStmt

func NewStmt(ctx context.Context, rawsql string) (*Stmt, error)

func (*Stmt) Args

func (s *Stmt) Args(vals ...any) ([]any, error)

func (*Stmt) Exec

func (s *Stmt) Exec(ctx context.Context, args ...any) (sql.Result, error)

func (*Stmt) ExecContext

func (s *Stmt) ExecContext(ctx context.Context, args ...any) (sql.Result, error)

func (*Stmt) MustExec

func (s *Stmt) MustExec(ctx context.Context, args ...any) sql.Result

func (*Stmt) MustRows

func (s *Stmt) MustRows(ctx context.Context, args ...any) *sql.Rows

func (*Stmt) Rows

func (s *Stmt) Rows(ctx context.Context, args ...any) (*sql.Rows, error)

type UniqueSlice

type UniqueSlice[T any, K comparable] struct {
	V []T
	// contains filtered or unexported fields
}

func NewUniqueSlice

func NewUniqueSlice[T any, K comparable](keyof func(*T) K) *UniqueSlice[T, K]

func (*UniqueSlice[T, K]) Has

func (s *UniqueSlice[T, K]) Has(key K) bool

func (*UniqueSlice[T, K]) Push

func (s *UniqueSlice[T, K]) Push(v T) bool

func (*UniqueSlice[T, K]) Reindex

func (s *UniqueSlice[T, K]) Reindex() *UniqueSlice[T, K]

func (*UniqueSlice[T, K]) WithFactor

func (s *UniqueSlice[T, K]) WithFactor(factor int) *UniqueSlice[T, K]

Jump to

Keyboard shortcuts

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