Documentation ¶
Index ¶
- Variables
- func ShowSQL(b bool)
- type DisableMapperCache
- type Mapper
- type MapperCache
- type MapperCacheEntry
- type NewRowMapper
- type Option
- func WithCache(aCache cache.Cache) Option
- func WithCacheRefresh(refresh cache.Refresh) Option
- func WithCacheStats(stats *cache.Stats) Option
- func WithDB(db *sql.DB) Option
- func WithDialect(dialect *info.Dialect) Option
- func WithDisableMapperCache(disable DisableMapperCache) Option
- func WithInMatcher(inMatcher *cache.ParmetrizedQuery) Option
- func WithInlineType(inlineType bool) Option
- func WithMapperCache(aCache *MapperCache) Option
- func WithOptions(opts ...option.Option) Option
- func WithRowMapper(mapper NewRowMapper) Option
- func WithUnmappedFn(fn io.Resolve) Option
- type Reader
- func New(ctx context.Context, db *sql.DB, query string, newRow func() interface{}, ...) (*Reader, error)
- func NewMap(ctx context.Context, db *sql.DB, query string, options ...Option) (*Reader, error)
- func NewSlice(ctx context.Context, db *sql.DB, query string, columns int, options ...Option) (*Reader, error)
- func NewStmt(stmt *sql.Stmt, newRow func() interface{}, opts ...Option) *Reader
- func (r *Reader) QueryAll(ctx context.Context, emit func(row interface{}) error, args ...interface{}) error
- func (r *Reader) QueryAllWithMap(ctx context.Context, emit func(row map[string]interface{}) error, ...) error
- func (r *Reader) QueryAllWithSlice(ctx context.Context, emit func(row []interface{}) error, args ...interface{}) error
- func (r *Reader) QuerySingle(ctx context.Context, emit func(row interface{}) error, args ...interface{}) error
- func (r *Reader) ReadAll(ctx context.Context, rows *sql.Rows, emit func(row interface{}) error, ...) error
- func (r *Reader) Stmt() *sql.Stmt
- type RowMapper
- type Rows
- func (c *Rows) CheckType(ctx context.Context, values []interface{}) (bool, error)
- func (c *Rows) Close(ctx context.Context) error
- func (c *Rows) ConvertColumns() ([]io.Column, error)
- func (c *Rows) Err() error
- func (c *Rows) Next() bool
- func (c *Rows) Rollback(ctx context.Context) error
- func (c *Rows) Scanner(ctx context.Context) cache.ScannerFn
- func (c *Rows) XTypes() []*xunsafe.Type
- type Segment
- type SkipError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var DefaultMapperCache = NewMapperCache(8192)
Functions ¶
Types ¶
type DisableMapperCache ¶
type DisableMapperCache bool
type Mapper ¶
type Mapper struct {
// contains filtered or unexported fields
}
func (*Mapper) MapToSQLRow ¶ added in v0.7.0
type MapperCache ¶
type MapperCache struct {
// contains filtered or unexported fields
}
func NewMapperCache ¶
func NewMapperCache(size int) *MapperCache
func (*MapperCache) Delete ¶
func (c *MapperCache) Delete(entry *MapperCacheEntry) error
func (*MapperCache) Get ¶
func (c *MapperCache) Get(structType reflect.Type, columns []io.Column, resolver io.Resolve) (*MapperCacheEntry, error)
func (*MapperCache) Put ¶
func (c *MapperCache) Put(entry *MapperCacheEntry, fields []io.Field)
type MapperCacheEntry ¶
type MapperCacheEntry struct {
// contains filtered or unexported fields
}
func (*MapperCacheEntry) Fields ¶
func (e *MapperCacheEntry) Fields() []io.Field
func (*MapperCacheEntry) HasFields ¶
func (e *MapperCacheEntry) HasFields() bool
type NewRowMapper ¶
type NewRowMapper func(columns []io.Column, targetType reflect.Type, resolver io.Resolve, options ...Option) (RowMapper, error)
NewRowMapper new a row mapper function
type Option ¶ added in v0.16.0
type Option func(o *options)
func WithCacheRefresh ¶ added in v0.16.0
func WithCacheStats ¶ added in v0.16.0
func WithDialect ¶ added in v0.16.0
func WithDisableMapperCache ¶ added in v0.16.0
func WithDisableMapperCache(disable DisableMapperCache) Option
func WithInMatcher ¶ added in v0.16.0
func WithInMatcher(inMatcher *cache.ParmetrizedQuery) Option
func WithInlineType ¶ added in v0.16.0
func WithMapperCache ¶ added in v0.16.0
func WithMapperCache(aCache *MapperCache) Option
func WithOptions ¶ added in v0.16.0
func WithRowMapper ¶ added in v0.16.0
func WithRowMapper(mapper NewRowMapper) Option
func WithUnmappedFn ¶ added in v0.16.0
type Reader ¶
type Reader struct {
// contains filtered or unexported fields
}
Reader represents generic query reader
func New ¶
func New(ctx context.Context, db *sql.DB, query string, newRow func() interface{}, options ...Option) (*Reader, error)
New creates a records to a structs reader
func NewSlice ¶
func NewSlice(ctx context.Context, db *sql.DB, query string, columns int, options ...Option) (*Reader, error)
NewSlice create records to a slice reader
func (*Reader) QueryAll ¶
func (r *Reader) QueryAll(ctx context.Context, emit func(row interface{}) error, args ...interface{}) error
QueryAll query all
func (*Reader) QueryAllWithMap ¶
func (r *Reader) QueryAllWithMap(ctx context.Context, emit func(row map[string]interface{}) error, args ...interface{}) error
QueryAllWithMap query all with a map
func (*Reader) QueryAllWithSlice ¶
func (r *Reader) QueryAllWithSlice(ctx context.Context, emit func(row []interface{}) error, args ...interface{}) error
QueryAllWithSlice query all with a slice
func (*Reader) QuerySingle ¶
func (r *Reader) QuerySingle(ctx context.Context, emit func(row interface{}) error, args ...interface{}) error
QuerySingle returns single row
func (*Reader) ReadAll ¶
func (r *Reader) ReadAll(ctx context.Context, rows *sql.Rows, emit func(row interface{}) error, options ...option.Option) error
ReadAll read all
Example ¶
package main import ( "context" "database/sql" "github.com/viant/sqlx/io/read" "log" ) func main() { dsn := "" db, err := sql.Open("mysql", dsn) if err != nil { log.Fatalln(err) } ctx := context.Background() type Foo struct { ID int Name string Active bool } newFoo := func() interface{} { return &Foo{} } reader, err := read.New(ctx, db, "SELECT * FROM foo", newFoo) if err != nil { log.Fatalln(err) } var foos []*Foo reader.QueryAll(ctx, func(row interface{}) error { foo := row.(*Foo) foos = append(foos, foo) return nil }, nil) log.Printf("read foos: %+v\n", foos) }
Output:
type RowMapper ¶
type RowMapper func(target interface{}) ([]interface{}, error)
RowMapper represents a target values mapped to pointer of slice
func GenericRowMapper ¶
GenericRowMapper creates a new row mapper for supplied slice or map type
Source Files ¶
Click to show internal directories.
Click to hide internal directories.