Documentation ¶
Index ¶
- Constants
- Variables
- func Exec[R any](db *DB, q any, args ...any) (R, error)
- func ForeachResult[E any](resultVal reflect.Value, f func(elem E) error) error
- func MustSql(q any, opts *Options) string
- func NamingString(s string, opts *Options) string
- func NamingStrings(ss []string, opts *Options) []string
- func QueryAll[ROW any](db *DB, q any, args ...any) ([]ROW, error)
- func QueryAssociated[K comparable, ROW any](db *DB, aggregator func(ROW) (K, bool), q any, args ...any) (map[K]ROW, error)
- func QueryGrouped[K comparable, ROW any](db *DB, aggregator func(ROW) (K, bool), q any, args ...any) (map[K][]ROW, error)
- func QueryOne[ROW any](db *DB, q any, args ...any) (ROW, error)
- func QuoteString(s string, opts *Options) string
- func QuoteStrings(ss []string, opts *Options) []string
- func ToSql(q any, opts *Options) (string, error)
- func Trans[R any](db *DB, txOpts *sql.TxOptions, f func(tx *DB) (R, error)) (R, error)
- type Args
- type ArgsProvider
- type DB
- func (db *DB) Begin(txOpts *sql.TxOptions) (*DB, error)
- func (db *DB) Bind(q string, unnamedArgs Args, namedArgs NamedArgs) (string, []any, error)
- func (db *DB) Close() error
- func (db *DB) Commit() error
- func (db *DB) DB() *sql.DB
- func (db *DB) Dialect() Dialect
- func (db *DB) Exec(dest any, q any, args ...any) error
- func (db *DB) ExecBatch(q any, batchedArgs any, prepare bool, optionalArgs ...any) error
- func (db *DB) Prepare(q string) (*DB, error)
- func (db *DB) QueryAll(dest any, q any, args ...any) error
- func (db *DB) QueryOne(dest any, q any, args ...any) error
- func (db *DB) Rollback() error
- func (db *DB) Trans(txOpts *sql.TxOptions, f func(tx *DB) error) error
- func (db *DB) WithContext(ctx context.Context) *DB
- type Dest
- type Dialect
- type Insert
- type LogFormatter
- type Logger
- type Mapper
- type NameResolver
- type NamedArg
- type NamedArgs
- type Node
- type Options
- type PostCompleter
- type PostModifier
- type PostProcessor
- type PostProcessorFunc
- type Result
- type SliceHolder
- type SqlPrinter
- type SqlValueOptions
- type Src
- type Struct
- type StructField
- type StructFieldPath
- type StructFieldTag
- type Table
- type TableField
- type Tabular
Constants ¶
View Source
const ( StructPtr = 1 Map = 2 PrimitivePtr = 3 SlicePtr = 4 )
Variables ¶
View Source
var ( ErrInvalidDriver = errors.New("invalid driver") ErrInvalidKind = errors.New("invalid kind") ErrInvalidDest = errors.New("invalid dest") ErrInvalidQuery = errors.New("invalid query") ErrInvalidArg = errors.New("invalid arg") ErrBind = errors.New("bind error") ErrNoRows = sql.ErrNoRows ErrCoerceDest = errors.New("coerce dest error") ErrSetStructField = errors.New("set struct field error") ErrPostProcess = errors.New("post process error") )
Functions ¶
func NamingString ¶
func NamingStrings ¶
func QueryAssociated ¶
func QueryGrouped ¶
func QuoteString ¶
func QuoteStrings ¶
Types ¶
type ArgsProvider ¶
func StructArgs ¶
func StructArgs(p any) ArgsProvider
type DB ¶
type DB struct {
// contains filtered or unexported fields
}
type Dialect ¶
type Dialect interface { DriverName() string QuoteString(s string) string NamingString(s string) string CompileNamedQuery(q string, opts *Options) (string, []string, error) NewDest(ci *sql.ColumnType, opts *Options) any CoerceDest(ci *sql.ColumnType, scannedVal reflect.Value, toType reflect.Type, opts *Options) (reflect.Value, error) }
type LogFormatter ¶
type Logger ¶
type Logger interface { LogQuery(ctx context.Context, msg string) LogQueryErr(ctx context.Context, msg string) }
var StdLogger Logger = stdLogger{}
type NameResolver ¶
type NameResolver interface { ResolveTableName(structName string) string ResolveFieldName(structName, structFieldName string) string }
var DefaultNameResolver NameResolver = defaultNameResolver{}
type NamedArgs ¶
func StructToNamed ¶
func StructToNamed(v any, resolver NameResolver) (NamedArgs, error)
type Node ¶
type Node interface {
ToSql(p SqlPrinter, opts *Options)
}
type Options ¶
type Options struct { // dialect Dialect Dialect Mapper Mapper NameResolver NameResolver TextCharset string TimeFormat string // log Logger Logger LogFormatter LogFormatter LogBound bool LogSuccess bool LogSlowThreshold int64 }
type PostCompleter ¶
type PostCompleter[E any, FID comparable, FE any] struct { Disabled bool Collect func(elem E, foreignIds []FID) []FID Query func(foreignIds []FID) (map[FID]FE, error) Complete func(elem E, m map[FID]FE) error }
func (PostCompleter[E, FID, FE]) If ¶
func (c PostCompleter[E, FID, FE]) If(enabled bool) PostCompleter[E, FID, FE]
func (PostCompleter[E, FID, FE]) PostProcess ¶
func (c PostCompleter[E, FID, FE]) PostProcess(resultVal reflect.Value) error
type PostModifier ¶
func PostModify ¶
func PostModify[E any](f func(elem E) error) PostModifier[E]
func (PostModifier[E]) If ¶
func (m PostModifier[E]) If(enabled bool) PostModifier[E]
func (PostModifier[E]) PostProcess ¶
func (m PostModifier[E]) PostProcess(resultVal reflect.Value) error
type PostProcessor ¶
type PostProcessorFunc ¶
func (PostProcessorFunc) PostProcess ¶
func (f PostProcessorFunc) PostProcess(resultVal reflect.Value) error
type SliceHolder ¶
type SliceHolder interface { SlicePtr() any Aggregate() }
func AssociatedDest ¶
func AssociatedDest[K comparable, V any](dest *map[K]V, aggregator func(V) (K, bool)) SliceHolder
func GroupedDest ¶
func GroupedDest[K comparable, V any](dest *map[K][]V, aggregator func(V) (K, bool)) SliceHolder
type SqlPrinter ¶
type SqlPrinter interface { Raw(s string) SqlPrinter Str(s string) SqlPrinter Value(v any, opts *SqlValueOptions) SqlPrinter }
type SqlValueOptions ¶
type Src ¶
type Src struct { Rows *sql.Rows Columns []string ColumnTypes []*sql.ColumnType }
func (*Src) NextResultSet ¶
type Struct ¶
type Struct struct { Name string `json:"name"` Fields []*StructField `json:"fields"` }
func (*Struct) ToTable ¶
func (s *Struct) ToTable(resolver NameResolver) Table
type StructField ¶
type StructField struct { Paths []*StructFieldPath `json:"paths"` TypeName string `json:"type"` Type reflect.Type `json:"-"` Tag StructFieldTag `json:"tag"` }
type StructFieldPath ¶
type StructFieldTag ¶
type Table ¶
type Table interface { Name() string Fields() []TableField FieldNames(withoutAuto bool) []string }
func ParseTable ¶
type TableField ¶
type Tabular ¶
type Tabular interface {
ToTable(resolver NameResolver) Table
}
Source Files ¶
Click to show internal directories.
Click to hide internal directories.