sqlutil

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotFound = errors.New("data not found")

Functions

func ExecBuild

func ExecBuild(db IDB, v interface{}, builder BuildFunc) (sql.Result, error)

func WrapTx

func WrapTx(db *sql.DB, handler func(tx *sql.Tx) error) error

Types

type BuildFunc

type BuildFunc func(interface{}) (*BuildResult, error)

type BuildResult

type BuildResult struct {
	Sql    string
	Values []interface{}
}

type Builder

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

func NewBuilder

func NewBuilder(table string) *Builder

func (*Builder) AddBatch

func (b *Builder) AddBatch(values []interface{})

func (*Builder) AddField

func (b *Builder) AddField(name string, val interface{})

func (*Builder) Delete

func (b *Builder) Delete() (res BuildResult)

func (*Builder) FindByID

func (b *Builder) FindByID() (res BuildResult)

func (*Builder) Insert

func (b *Builder) Insert() (res BuildResult)

func (*Builder) SetFields

func (b *Builder) SetFields(fields []string)

func (*Builder) SetID

func (b *Builder) SetID(id string, val interface{})

func (*Builder) SetPrepare

func (b *Builder) SetPrepare(p bool)

func (*Builder) Update

func (b *Builder) Update() (res BuildResult)

func (*Builder) Upsert

func (b *Builder) Upsert() (res BuildResult)

type IDB

type IDB interface {
	Exec(sql string, args ...interface{}) (sql.Result, error)
	Query(sql string, args ...interface{}) (*sql.Rows, error)
}

type NoneResult

type NoneResult struct {
}

func (*NoneResult) LastInsertId

func (*NoneResult) LastInsertId() (int64, error)

func (*NoneResult) RowsAffected

func (*NoneResult) RowsAffected() (int64, error)

type OrmBuilder

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

func NewOrm

func NewOrm(p interface{}) *OrmBuilder

func (*OrmBuilder) BuildBatch

func (b *OrmBuilder) BuildBatch(slice interface{}) (*BuildResult, error)

func (*OrmBuilder) BuildDelete

func (b *OrmBuilder) BuildDelete(v interface{}) (*BuildResult, error)

func (*OrmBuilder) BuildFindByID

func (b *OrmBuilder) BuildFindByID() string

func (*OrmBuilder) BuildInsert

func (b *OrmBuilder) BuildInsert(v interface{}) (*BuildResult, error)

func (*OrmBuilder) BuildUpdate

func (b *OrmBuilder) BuildUpdate(v interface{}) (*BuildResult, error)

func (*OrmBuilder) BuildUpsert

func (b *OrmBuilder) BuildUpsert(v interface{}) (*BuildResult, error)

func (*OrmBuilder) FindById

func (b *OrmBuilder) FindById(db IDB, id interface{}, o interface{}) error

type Runner

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

func NewRunner

func NewRunner(db IDB, sql string, args ...interface{}) *Runner

func (*Runner) Affect

func (r *Runner) Affect() (int64, error)

func (*Runner) LastId

func (r *Runner) LastId() (int64, error)

func (*Runner) Many

func (r *Runner) Many(f func(*sql.Rows) error) error

func (*Runner) One

func (r *Runner) One(f func(*sql.Rows) error) error

func (*Runner) OneE

func (r *Runner) OneE(f func(*sql.Rows) error) error

func (*Runner) Result

func (r *Runner) Result() (sql.Result, error)

type SetBool

type SetBool struct {
	sql.NullBool
	Setter
}

func NewSetBool

func NewSetBool(b bool) SetBool

func (*SetBool) Get

func (sb *SetBool) Get() bool

func (*SetBool) Set

func (sb *SetBool) Set(b bool)

type SetF64

type SetF64 struct {
	sql.NullFloat64
	Setter
}

func NewSetF64

func NewSetF64(i float64) SetF64

func (*SetF64) Get

func (sf *SetF64) Get() float64

func (*SetF64) Set

func (sf *SetF64) Set(f float64)

type SetI32

type SetI32 struct {
	sql.NullInt32
	Setter
}

func NewSetI32

func NewSetI32(i int32) SetI32

func (*SetI32) Get

func (si *SetI32) Get() int32

func (*SetI32) GetInt

func (si *SetI32) GetInt() int

func (*SetI32) Set

func (si *SetI32) Set(i int32)

type SetI64

type SetI64 struct {
	sql.NullInt64
	Setter
}

func NewSetI64

func NewSetI64(i int64) SetI64

func (*SetI64) Get

func (si *SetI64) Get() int64

func (*SetI64) Set

func (si *SetI64) Set(i int64)

type SetString

type SetString struct {
	sql.NullString
	Setter
}

func NewFmtStr

func NewFmtStr(s string, args ...interface{}) SetString

func NewSetStr

func NewSetStr(s string) SetString

func (*SetString) Get

func (ss *SetString) Get() string

func (*SetString) Set

func (ss *SetString) Set(s string)

type SetTime

type SetTime struct {
	sql.NullTime
	Setter
}

func NewSetTime

func NewSetTime(i time.Time) SetTime

func (*SetTime) Get

func (st *SetTime) Get() time.Time

func (*SetTime) Set

func (st *SetTime) Set(t time.Time)

func (SetTime) String

func (st SetTime) String() string

type Setter

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

func (*Setter) ForceSet

func (s *Setter) ForceSet()

func (Setter) IsSet

func (s Setter) IsSet() bool

Jump to

Keyboard shortcuts

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