io

package
v0.2.3 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2022 License: Apache-2.0 Imports: 13 Imported by: 12

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EnsureDereference

func EnsureDereference(value interface{}) reflect.Type

EnsureDereference returns Type of value dereferenced e.g. if any is type of *Foo, it will return Foo

func Int64Ptr

func Int64Ptr(values []interface{}, index int) (*int64, error)

Int64Ptr returns pointer to index-th element of slice as pointer to int84

func IsMatchedError

func IsMatchedError(err error) bool

IsMatchedError returns whether err is matchError

func Iterator

func Iterator(any interface{}) (func() interface{}, int, error)

Iterator creates an iterator for any data structure, it returns next function, len, or error

func MergeErrorIfNeeded

func MergeErrorIfNeeded(fn func() error, err *error)

MergeErrorIfNeeded sets err as error from passed function used i.e. with deffer

func NormalizeKey

func NormalizeKey(key interface{}) interface{}

NormalizeKey converts non nil numeric value to int or return nil

func StructColumnMapper

func StructColumnMapper(src interface{}, tagName string, options ...option.Option) ([]Column, PlaceholderBinder, error)

StructColumnMapper returns genertic column mapper

func UpdateUnresolved

func UpdateUnresolved(field *Field, resolver Resolve) error

Types

type Builder

type Builder interface {
	Build(options ...option.Option) string
}

Builder represents SQL builder

type Column

type Column interface {
	Name() string
	Length() (length int64, ok bool)
	DecimalSize() (precision, scale int64, ok bool)
	ScanType() reflect.Type
	Nullable() (nullable, ok bool)
	DatabaseTypeName() string
	Tag() *Tag
}

Column represents a column

func NamesToColumns

func NamesToColumns(columns []string) []Column

NamesToColumns converts []string to []sqlx.column

func NewColumn

func NewColumn(name, databaseTypeName string, rType reflect.Type, opts ...interface{}) Column

NewColumn creates a column

func StructColumns

func StructColumns(recordType reflect.Type, tagName string) ([]Column, error)

StructColumns returns column for the struct

func TypesToColumns

func TypesToColumns(columns []*sql.ColumnType) []Column

TypesToColumns converts []*sql.ColumnType type to []sqlx.column

type ColumnDecimalPrecision

type ColumnDecimalPrecision int64

ColumnDecimalPrecision represents column decimal precision

type ColumnDecimalScale

type ColumnDecimalScale int64

ColumnDecimalScale represents column decimal scale

type ColumnLength

type ColumnLength int64

ColumnLength represents column length

type ColumnMapper

type ColumnMapper func(src interface{}, tagName string, options ...option.Option) ([]Column, PlaceholderBinder, error)

ColumnMapper maps src to columns and its placeholders

type ColumnNullable

type ColumnNullable bool

ColumnNullable represents column nullable option

type Columns

type Columns []Column

Columns represents columns

func (Columns) Autoincrement

func (c Columns) Autoincrement() int

Autoincrement returns position of autoincrement column position or -1

func (Columns) IdentityColumnPos

func (c Columns) IdentityColumnPos() int

IdentityColumnPos returns identity column position in []Column

func (Columns) Names

func (c Columns) Names() []string

Names returns column names

func (Columns) PrimaryKeys

func (c Columns) PrimaryKeys() int

PrimaryKeys returns position of primary key position or -1

type Field

type Field struct {
	Tag
	Column
	*xunsafe.Field
	EvalAddr    func(pointer unsafe.Pointer) interface{}
	Info        *sink.Column
	MatchesType bool
}

Field represents column mapped field

func (*Field) Addr

func (f *Field) Addr(pointer unsafe.Pointer) interface{}

Addr returns field pointer

func (*Field) CanExpand

func (f *Field) CanExpand() bool

CanExpand return true if field can expend fied struct fields

type FieldStringifierFn

type FieldStringifierFn = func(pointer unsafe.Pointer) (string, bool)

func Stringifier

func Stringifier(field *xunsafe.Field, nullifyZeroValue bool, nullValue string) FieldStringifierFn

type Fields

type Fields []Field

Fields represents slice of Field

func (Fields) ColumnNames

func (f Fields) ColumnNames() []string

ColumnNames returns slice of column names for given Fields

func (Fields) XFields

func (f Fields) XFields() []xunsafe.Field

XFields returns slice of xunsafe.Field for given Fields

type Matcher

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

Matcher implements column to struct filed mapper

func NewMatcher

func NewMatcher(tagName string, resolver Resolve) *Matcher

NewMatcher creates a fields to column matcher

func (*Matcher) Match

func (f *Matcher) Match(targetType reflect.Type, columns []Column) ([]Field, error)

Match matches field with columns

type ObjectStringifier

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

func TypeStringifier

func TypeStringifier(rType reflect.Type, nullValue string, omitTransient bool, options ...interface{}) *ObjectStringifier

TypeStringifier returns ObjectStringifier for a given Type. It will replace nil values with nullValue for properties with tag: "nullifyEmpty" and omit (if specified) transient properties By default, results are shared, no new arrays are returned unless Parallel(true) is provided as an option.

func (*ObjectStringifier) FieldNames

func (s *ObjectStringifier) FieldNames() []string

func (*ObjectStringifier) Has

func (s *ObjectStringifier) Has(fieldName string) bool

func (*ObjectStringifier) Stringifier

func (s *ObjectStringifier) Stringifier(options ...interface{}) (ObjectStringifierFn, error)

type ObjectStringifierFn

type ObjectStringifierFn func(val interface{}) ([]string, []bool)

ObjectStringifierFn returns stringified object properties values and information if value was string before

type Parallel

type Parallel bool

type PlaceholderBinder

type PlaceholderBinder func(src interface{}, params []interface{}, offset, limit int)

PlaceholderBinder copies source values to params starting with offset

type QueryResult

type QueryResult struct {
	sql.Result
	Rows  int64
	Error error
}

QueryResult summarizes an executed SQL command. use instead of standard Result when you need omit bug: "0 affected rows"

func (*QueryResult) RowsAffected

func (r *QueryResult) RowsAffected() (int64, error)

RowsAffected returns count of affected rows

type Resolve

type Resolve func(column Column) func(pointer unsafe.Pointer) interface{}

Resolve Resolver handler unresolved columns

type Resolver

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

Resolver represents unmatched column resolver

func NewResolver

func NewResolver() *Resolver

NewResolver creates a resolver

func (*Resolver) Data

func (r *Resolver) Data(index int) []interface{}

Data returns column data

func (*Resolver) Index

func (r *Resolver) Index(column string) int

Index returns column index or -1

func (*Resolver) OnSkip

func (r *Resolver) OnSkip(values []interface{}) error

func (*Resolver) Resolve

func (r *Resolver) Resolve(column Column) func(ptr unsafe.Pointer) interface{}

Resolve resolved unmapped column

type Session

type Session interface {
	Exec(context context.Context, data interface{}, db *sql.DB, tableName string, options ...option.Option) (sql.Result, error)
}

Session represents load session e.g. MySQL "LOAD DATA LOCAL INFILE"

type SessionResolver

type SessionResolver = func(dialect *info.Dialect) Session

SessionResolver returns new Session configured with given Dialect

type StringifierConfig

type StringifierConfig struct {
	Fields     []string
	CaseFormat format.Case
}

type Tag

type Tag struct {
	Column        string
	Autoincrement bool
	PrimaryKey    bool
	Sequence      string
	FieldIndex    int
	Transient     bool
	Ns            string
	Generator     string
	NullifyEmpty  bool
}

Tag represent field tag

func ParseTag

func ParseTag(tagString string) *Tag

ParseTag parses tag

type Transaction

type Transaction struct {
	*sql.Tx
	Global bool
}

func TransactionFor

func TransactionFor(ctx context.Context, dialect *info.Dialect, db *sql.DB, options []option.Option) (*Transaction, error)

func (*Transaction) Commit

func (t *Transaction) Commit() error

func (*Transaction) Rollback

func (t *Transaction) Rollback() error

func (*Transaction) RollbackWithErr

func (t *Transaction) RollbackWithErr(err error) error

type ValueAccessor

type ValueAccessor = func(index int) interface{}

ValueAccessor represents function that returns value at given index.

func Values

func Values(any interface{}) (ValueAccessor, int, error)

Values return function to access value at position

Jump to

Keyboard shortcuts

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