io

package
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Nov 20, 2023 License: Apache-2.0 Imports: 20 Imported by: 5

Documentation

Index

Constants

View Source
const (
	EncodingJSON = "JSON"

	TagSqlx = "sqlx"
)

Variables

This section is empty.

Functions

func DetectColumnCaseFormat added in v0.9.1

func DetectColumnCaseFormat(recordType reflect.Type) text.CaseFormat

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 ExtractColumnNames added in v0.9.1

func ExtractColumnNames(recordType reflect.Type) []string

ExtractColumnNames extract sqlx tag colum names

func Int64Ptr

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

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

func Int64ValuePtr added in v0.7.0

func Int64ValuePtr(value interface{}) (*int64, error)

func IsIdentityColumn added in v0.7.0

func IsIdentityColumn(col Column) bool

func IsMatchedError

func IsMatchedError(err error) bool

IsMatchedError returns whether err is matchError

func IsStruct added in v0.5.3

func IsStruct(t reflect.Type) bool

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 NormalizeColumnType added in v0.5.2

func NormalizeColumnType(scanType reflect.Type, name string) reflect.Type

func NormalizeKey

func NormalizeKey(key interface{}) interface{}

NormalizeKey converts non nil numeric value to int or return nil

func ParseType added in v0.5.2

func ParseType(columnType string) (reflect.Type, bool)

func RunWithError added in v0.8.0

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

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

func StructColumnMapper

func StructColumnMapper(src interface{}, 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(record interface{}, options ...option.Option) string
}

Builder represents SQL builder

func NewBuilderAdapter added in v0.4.0

func NewBuilderAdapter(builder RecordlessBuilder) Builder

type BuilderAdapter added in v0.4.0

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

Builder represents SQL builder

func (*BuilderAdapter) Build added in v0.4.0

func (b *BuilderAdapter) Build(_ interface{}, options ...option.Option) string

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 ...ColumnOption) Column

NewColumn creates a column

func StructColumns

func StructColumns(recordType reflect.Type, opts ...option.Option) ([]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 ColumnMapper

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

ColumnMapper maps src to columns and its placeholders

type ColumnOption added in v0.9.1

type ColumnOption func(o *column)

func WithColumnDecimalPrecision added in v0.9.1

func WithColumnDecimalPrecision(l int64) ColumnOption

WithColumnDecimalPrecision returns column decimal precision set option

func WithColumnDecimalScale added in v0.9.1

func WithColumnDecimalScale(l int64) ColumnOption

WithColumnDecimalScale returns column decimal scale set option

func WithColumnLength added in v0.9.1

func WithColumnLength(l int64) ColumnOption

WithColumnLength returns column length set option

func WithColumnNullable added in v0.9.1

func WithColumnNullable(l bool) ColumnOption

WithColumnNullable returns column nullable set option

func WithCustomOption added in v0.9.1

func WithCustomOption(opts ...interface{}) ColumnOption

WithCustomOption returns column tag option

func WithTag added in v0.9.1

func WithTag(t *Tag) ColumnOption

WithTag returns column tag option

type ColumnWithFields added in v0.7.0

type ColumnWithFields interface {
	Column
	Fielder
}

func NewColumnWithFields added in v0.7.0

func NewColumnWithFields(name string, databaseTypeName string, rType reflect.Type, fields []*xunsafe.Field, opts ...ColumnOption) ColumnWithFields

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, options ...interface{}) FieldStringifierFn

type Fielder added in v0.7.0

type Fielder interface {
	Fields() []*xunsafe.Field
}

type Fields

type Fields []Field

Fields represents slice of Field

func (Fields) ColumnNames

func (f Fields) ColumnNames() []string

ExtractColumnNames 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 JSONEncodedValue added in v0.7.0

type JSONEncodedValue struct {
	Val interface{}
}

func (*JSONEncodedValue) Scan added in v0.7.0

func (j *JSONEncodedValue) Scan(v interface{}) error

func (*JSONEncodedValue) Value added in v0.7.0

func (j *JSONEncodedValue) Value() (driver.Value, error)

type Matcher

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

Matcher implements column to struct filed mapper

func NewMatcher

func NewMatcher(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 RecordlessBuilder added in v0.4.0

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

Builder represents SQL builder

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
	StringifierFloat32Config StringifierFloat32Config
	StringifierFloat64Config StringifierFloat64Config
}

StringifierConfig represents stringifier config

type StringifierFloat32Config added in v0.5.4

type StringifierFloat32Config struct {
	Precision string
}

StringifierFloat32Config represents stringifier float32 config

type StringifierFloat64Config added in v0.5.4

type StringifierFloat64Config struct {
	Precision string
}

StringifierFloat64Config represents stringifier float64 config

type Tag

type Tag struct {
	Column           string
	Autoincrement    bool
	PrimaryKey       bool
	Sequence         string
	Transient        bool
	Ns               string
	Generator        string
	IsUnique         bool
	Db               string
	Table            string
	RefDb            string
	RefTable         string
	RefColumn        string
	Required         bool
	NullifyEmpty     bool
	ErrorMgs         string
	PresenceProvider bool
	Bit              bool
	Encoding         string
	CaseFormat       text.CaseFormat
	DataType         string
	Raw              string
}

Tag represent field tag

func ParseTag

func ParseTag(structTag reflect.StructTag) *Tag

ParseTag parses tag

func (*Tag) Name added in v0.9.1

func (t *Tag) Name() string

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