Documentation
¶
Index ¶
- Variables
- func All[T any](ctx context.Context, stmt *Stmt, sizehint int, args ...any) ([]T, error)
- func AsModel[T any]()
- func DisableEnsureBackedUp()
- func First[T any](ctx context.Context, stmt *Stmt, args ...any) (*T, error)
- func InitAllLazyStmts(ctx context.Context, mapfn func(*LazyStmt) bool) error
- func Logger() *slog.Logger
- func MustDB(ctx context.Context) *sql.DB
- func MustTx(ctx context.Context) *sql.Tx
- func Page[T any](ctx context.Context, stmt *Stmt, rows *sql.Rows, page []T) ([]T, bool, error)
- func PeekDB(ctx context.Context) *sql.DB
- func PeekTx(ctx context.Context) *sql.Tx
- func Stream[T any](ctx context.Context, stmt *Stmt, rows *sql.Rows) iter.Seq2[*T, error]
- func Sync(ctx context.Context) error
- func TxScope(ctx context.Context, f func(ctx context.Context) error, opts *sql.TxOptions) error
- func UnwrapSqlNullType(st reflect.Type) (reflect.Type, bool)
- func WithDB(ctx context.Context, db *sql.DB) context.Context
- func WithDialect(ctx context.Context, dialect IDialect) context.Context
- func WithExec(ctx context.Context, exec IExecutor) context.Context
- func WithTx(ctx context.Context, tx *sql.Tx) context.Context
- type IDialect
- type IExecutor
- type Index
- type IndexField
- type LazyStmt
- type LazyStmtGroup
- type MapOperator
- type ModelField
- func (f *ModelField) AutoIncrement(keys ...string) bool
- func (f *ModelField) CheckExpr(keys ...string) sql.Null[string]
- func (f *ModelField) DefaultExpr(keys ...string) sql.Null[string]
- func (f *ModelField) GetAny(keys ...string) sql.Null[string]
- func (f *ModelField) HasAny(keys ...string) bool
- func (f *ModelField) IsPrimaryKey(keys ...string) bool
- func (f *ModelField) Nullable(keys ...string) bool
- func (f *ModelField) SqlType() string
- func (f *ModelField) Unique(keys ...string) bool
- type ModelInfo
- type ReduceOperator
- type Stmt
- func (s *Stmt) Args(vals ...any) ([]any, error)
- func (s *Stmt) Exec(ctx context.Context, args ...any) (sql.Result, error)
- func (s *Stmt) ExecContext(ctx context.Context, args ...any) (sql.Result, error)
- func (s *Stmt) MustExec(ctx context.Context, args ...any) sql.Result
- func (s *Stmt) MustRows(ctx context.Context, args ...any) *sql.Rows
- func (s *Stmt) Rows(ctx context.Context, args ...any) (*sql.Rows, error)
- type UniqueSlice
Constants ¶
This section is empty.
Variables ¶
View Source
var (
ParamsRegexp = regexp.MustCompile(`\$\{\s*[a-zA-Z_]+[a-zA-Z_0-9]*\s*\}`)
)
Functions ¶
func DisableEnsureBackedUp ¶
func DisableEnsureBackedUp()
func InitAllLazyStmts ¶
Types ¶
type IDialect ¶
type IDialect interface {
EnsureTables(ctx context.Context, infos []*ModelInfo) error
ParamPlaceholder(index int) string
}
func MustDialect ¶
func PeekDialect ¶
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 PeekExecutor ¶
type Index ¶
type Index struct {
Name string
Unique bool
Fields []*IndexField
}
type IndexField ¶
type LazyStmt ¶
type LazyStmt struct {
*Stmt
// contains filtered or unexported fields
}
func NewLazyStmt ¶
type LazyStmtGroup ¶
type LazyStmtGroup struct {
// contains filtered or unexported fields
}
func NewLazyStmtGroup ¶
func NewLazyStmtGroup() *LazyStmtGroup
func (*LazyStmtGroup) New ¶
func (g *LazyStmtGroup) New(rawsql string) *LazyStmt
type MapOperator ¶
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) DefaultExpr ¶
func (f *ModelField) DefaultExpr(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 ¶
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 Stmt ¶
func (*Stmt) ExecContext ¶
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]
Click to show internal directories.
Click to hide internal directories.