Help us shape the future of Go! Take the 2026 Go Developer Survey

read

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Feb 26, 2023 License: Apache-2.0 Imports: 14 Imported by: 5

Documentation

Index

Examples

Constants

This section is empty.

Variables

View Source
var DefaultMapperCache = NewMapperCache(8192)

Functions

This section is empty.

Types

type DisableMapperCache

type DisableMapperCache bool

type Mapper

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

func NewMapper

func NewMapper(fields []io.Field) *Mapper

func (*Mapper) MapToRow

func (m *Mapper) MapToRow(target interface{}) ([]interface{}, error)

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, tagName string, resolver io.Resolve, options []option.Option) (RowMapper, error)

NewRowMapper new a row mapper function

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.Option) (*Reader, error)

New creates a records to a structs reader

func NewMap

func NewMap(ctx context.Context, db *sql.DB, query string, options ...option.Option) (*Reader, error)

NewMap creates records to map reader

func NewSlice

func NewSlice(ctx context.Context, db *sql.DB, query string, columns int, options ...option.Option) (*Reader, error)

NewSlice create records to a slice reader

func NewStmt

func NewStmt(stmt *sql.Stmt, newRow func() interface{}, options ...option.Option) *Reader

NewStmt creates a statement 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)
}

func (*Reader) Stmt

func (r *Reader) Stmt() *sql.Stmt

Stmt returns *sql.Stmt associated with Reader

type RowMapper

type RowMapper func(target interface{}) ([]interface{}, error)

RowMapper represents a target values mapped to pointer of slice

func GenericRowMapper

func GenericRowMapper(columns []io.Column) (RowMapper, error)

GenericRowMapper creates a new row mapper for supplied slice or map type

func NewStructMapper

func NewStructMapper(columns []io.Column, recordType reflect.Type, tagName string, resolver io.Resolve, options ...option.Option) (RowMapper, error)

NewStructMapper creates a new record mapper for supplied struct type

type Rows

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

func NewRows

func NewRows(rows *sql.Rows, cache cache.Cache, entry *cache.Entry, matcher *cache.ParmetrizedQuery) (*Rows, error)

func (*Rows) CheckType

func (c *Rows) CheckType(ctx context.Context, values []interface{}) (bool, error)

func (*Rows) Close

func (c *Rows) Close(ctx context.Context) error

func (*Rows) ConvertColumns

func (c *Rows) ConvertColumns() ([]io.Column, error)

func (*Rows) Next

func (c *Rows) Next() bool

func (*Rows) Rollback

func (c *Rows) Rollback(ctx context.Context) error

func (*Rows) Scanner

func (c *Rows) Scanner(ctx context.Context) cache.ScannerFn

func (*Rows) XTypes

func (c *Rows) XTypes() []*xunsafe.Type

type Segment

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

type SkipError

type SkipError string

func (SkipError) Error

func (s SkipError) Error() string

Directories

Path Synopsis
afs
ast

Jump to

Keyboard shortcuts

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