sqlt

package module
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Feb 10, 2019 License: MIT Imports: 8 Imported by: 1

README

sqlt

sqlt 目前已到可用状态,欢迎使用

Documentation

Index

Constants

This section is empty.

Variables

Functions

func Commit

func Commit(t TxEnd) error

func Exec

func Exec(execer TExecer, ctx context.Context, id string, param interface{}) (r sql.Result, err error)

func ExecRtn

func ExecRtn(execer TExecer, ctx context.Context, id string, param interface{}, h RowsExtractor) (err error)

func MustConnect

func MustConnect(dbname, dsname string) *sqlx.DB

func MustExec

func MustExec(execer TExecer, ctx context.Context, id string, param interface{}) (r sql.Result)

func MustExecRtn

func MustExecRtn(execer TExecer, ctx context.Context, id string, param interface{}, h RowsExtractor)

func MustQuery

func MustQuery(execer TExecer, ctx context.Context, id string, param interface{}, h RowsExtractor)

func MustSql

func MustSql(maker Maker, id string, param interface{}) (sql string)

func NewTxOptions

func NewTxOptions(level sql.IsolationLevel, readonly bool) *sql.TxOptions

func Query

func Query(execer TExecer, ctx context.Context, id string, param interface{}, h RowsExtractor) (err error)

func Rollback

func Rollback(t TxEnd) error

func Sql

func Sql(maker Maker, id string, param interface{}) (string, error)

Types

type Dbop

type Dbop struct {
	Maker
	*sqlx.DB
}

func Default

func Default(dbname, dbsource, pattern string) *Dbop

func New

func New(db *sqlx.DB, maker Maker) *Dbop

func (*Dbop) TBegin

func (c *Dbop) TBegin(ctx context.Context, opt *sql.TxOptions) (*Txop, error)

func (*Dbop) TExec

func (c *Dbop) TExec(ctx context.Context, id string, param interface{}) (r sql.Result, e error)

func (*Dbop) TExecRtn

func (c *Dbop) TExecRtn(ctx context.Context, id string, param interface{}, h RowsExtractor) error

func (*Dbop) TQuery

func (c *Dbop) TQuery(ctx context.Context, id string, param interface{}, h RowsExtractor) error

type ExtractFunc

type ExtractFunc func(Rows) error

func (ExtractFunc) Extract

func (e ExtractFunc) Extract(rs Rows) error

type Maker

type Maker interface {
	MakeSql(string, interface{}) (string, error)
}

type Param

type Param = map[string]interface{}

type Rows

type Rows interface {
	Next() bool
	NextResultSet() bool
	Err() error

	Scan(...interface{}) error
	MapScan(map[string]interface{}) error
	StructScan(interface{}) error

	ColumnTypes() ([]*sql.ColumnType, error)
	Columns() ([]string, error)
}

type RowsExtractor

type RowsExtractor interface {
	Extract(Rows) error
}

type Rs

type Rs struct {
	*sqlx.Rows
}

func (*Rs) MapScan

func (r *Rs) MapScan(m map[string]interface{}) error

func (*Rs) StructScan

func (r *Rs) StructScan(dist interface{}) error

type SqlTemplate

type SqlTemplate struct {
	*template.Template
	Debug  bool
	Logger *log.Logger
}

func NewSqlTemplate

func NewSqlTemplate(pattern string) *SqlTemplate

func NewSqlTemplateWithFuncs

func NewSqlTemplateWithFuncs(pattern string, funcs template.FuncMap) *SqlTemplate

func (*SqlTemplate) MakeSql

func (t *SqlTemplate) MakeSql(id string, param interface{}) (string, error)

func (*SqlTemplate) SetDebug

func (t *SqlTemplate) SetDebug(b bool)

type TExecer

type TExecer interface {
	TQuery(context.Context, string, interface{}, RowsExtractor) error
	TExec(context.Context, string, interface{}) (sql.Result, error)
	TExecRtn(context.Context, string, interface{}, RowsExtractor) error
}

type TxBegin

type TxBegin interface {
	TBegin(context.Context, *sql.TxOptions) (*Txop, error)
}

type TxEnd

type TxEnd interface {
	TCommit() error
	TRollback() error
}

type Txop

type Txop struct {
	Maker
	*sqlx.Tx
}

func Begin

func Begin(b TxBegin, ctx context.Context, opt *sql.TxOptions) (*Txop, error)

func (*Txop) TCommit

func (t *Txop) TCommit() error

func (*Txop) TExec

func (t *Txop) TExec(ctx context.Context, id string, param interface{}) (r sql.Result, e error)

func (*Txop) TExecRtn

func (t *Txop) TExecRtn(ctx context.Context, id string, param interface{}, h RowsExtractor) error

func (*Txop) TQuery

func (t *Txop) TQuery(ctx context.Context, id string, param interface{}, h RowsExtractor) error

func (*Txop) TRollback

func (t *Txop) TRollback() error

Directories

Path Synopsis
cmd
internal

Jump to

Keyboard shortcuts

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