zsql

package module
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 23, 2021 License: MIT Imports: 20 Imported by: 0

README

zsql

sql lib on mist

Documentation

Index

Constants

View Source
const MiddlewareName = "zsql"

Variables

View Source
var (
	ErrInvalidValue = errors.New("invalid value, should be pointer to struct or slice")
	// ErrInvalidTransaction invalid transaction when you are trying to `Commit` or `Rollback`
	ErrInvalidTransaction = errors.New("invalid transaction")
)
View Source
var (
	ErrInvalidConnForListen = errors.New("conn does not support LISTEN / NOTIFY")
)
View Source
var (
	StandardTimeLayout = "2006-01-02 15:04:05"
)

Functions

func MaxIdle

func MaxIdle(count int) mist.Option

func MaxOpen

func MaxOpen(count int) mist.Option

func MysqlAddress

func MysqlAddress(name, read, write string) mist.Option

name will set to be default when empty

func PgAddress

func PgAddress(name, read, write string) mist.Option

func Scan

func Scan(rows *sql.Rows, db *DB)

Types

type Builder

type Builder interface {
	Writer
	WriteQuoted(field interface{})
	AddVar(vars ...interface{})
}

Builder builder interface

type Clause

type Clause struct {
	Name       string // WHERE
	Expression Expression
}

Clause

func (Clause) Build

func (c Clause) Build(builder Builder)

type ConnPool

type ConnPool interface {
	PrepareContext(ctx context.Context, query string) (*sql.Stmt, error)
	ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)
	QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)
	QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row
}

ConnPool db conns pool interface

type DB

type DB struct {
	Statement    *Statement
	RowsAffected int64
	LastInsertId int64
	Error        error
	// contains filtered or unexported fields
}

func Get

func Get(ctx context.Context, args ...string) *DB

func (*DB) AddError

func (db *DB) AddError(err error) error

func (*DB) AddNameMap

func (db *DB) AddNameMap(old, new string) (tx *DB)

func (*DB) Begin

func (db *DB) Begin(opts ...*sql.TxOptions) *DB

func (*DB) Commit

func (db *DB) Commit() *DB

func (*DB) Exec

func (db *DB) Exec(sql string, args ...interface{}) (tx *DB)

func (*DB) Find

func (db *DB) Find(dest interface{}) (tx *DB)

func (*DB) GroupBy

func (db *DB) GroupBy(column string) (tx *DB)

func (*DB) ID

func (m *DB) ID() string

func (*DB) Limit

func (db *DB) Limit(limit int) (tx *DB)

func (*DB) Listen

func (db *DB) Listen(ctx context.Context, channel string) (abstract.Observable, error)

func (*DB) MustWrite

func (db *DB) MustWrite() (tx *DB)

MustWrite 当使用Query时可以强制用读库

func (*DB) Offset

func (db *DB) Offset(offset int) (tx *DB)

func (*DB) Order

func (db *DB) Order(value interface{}) (tx *DB)

func (*DB) Paging

func (db *DB) Paging(page, perPage int) (tx *DB)

func (*DB) Query

func (db *DB) Query(sql string, args ...interface{}) (tx *DB)

func (*DB) QueryReturn

func (db *DB) QueryReturn(sql string, args ...interface{}) (tx *DB)

func (*DB) Reset

func (db *DB) Reset() (tx *DB)

func (*DB) Rollback

func (db *DB) Rollback() *DB

func (*DB) Rows

func (db *DB) Rows() []*DataRow

func (*DB) TypeName

func (m *DB) TypeName() string

func (*DB) Where

func (db *DB) Where(where ...interface{}) (tx *DB)

type DataRow

type DataRow struct {
	Fields map[string]interface{}
}

func (*DataRow) GetFloat64

func (d *DataRow) GetFloat64(fieldName string) float64

func (*DataRow) GetInt

func (d *DataRow) GetInt(fieldName string) int

func (*DataRow) GetInt32

func (d *DataRow) GetInt32(fieldName string) int32

func (*DataRow) GetInt64

func (d *DataRow) GetInt64(fieldName string) int64

func (*DataRow) GetString

func (d *DataRow) GetString(fieldName string) string

func (*DataRow) GetTime

func (d *DataRow) GetTime(fieldName string) time.Time

func (*DataRow) GetTimeStr

func (d *DataRow) GetTimeStr(fieldName string) string

type Expression

type Expression interface {
	Build(builder Builder)
}

Expression expression interface

type IClause

type IClause interface {
	Name() string
	Build(Builder)
	MergeClause(*Clause)
}

type Limit

type Limit struct {
	Limit  int
	Offset int
}

func (Limit) Build

func (limit Limit) Build(builder Builder)

func (Limit) MergeClause

func (limit Limit) MergeClause(clause *Clause)

func (Limit) Name

func (limit Limit) Name() string

type Middleware

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

func (*Middleware) Close

func (m *Middleware) Close() error

func (*Middleware) Init

func (m *Middleware) Init(opt []mist.Option)

func (*Middleware) Inter

func (m *Middleware) Inter(full bool) mist.Interceptor

type Statement

type Statement struct {
	Context context.Context
	*DB
	Schema       *schema.Schema
	SQL          strings.Builder
	Vals         []interface{}
	Model        interface{}
	Dest         interface{}
	ConnPool     ConnPool
	Clauses      map[string]Clause
	NameMapper   map[string]string
	BuildClauses []string
	ReflectValue reflect.Value
	Table        string
}

func (*Statement) AddClause

func (st *Statement) AddClause(v IClause)

func (*Statement) AddVar

func (st *Statement) AddVar(vars ...interface{})

func (*Statement) Build

func (st *Statement) Build(clauses ...string)

func (*Statement) Parse

func (st *Statement) Parse(value interface{}) (err error)

func (*Statement) Reset

func (st *Statement) Reset() (tx *DB)

func (*Statement) WriteByte

func (st *Statement) WriteByte(c byte) error

func (*Statement) WriteQuoted

func (st *Statement) WriteQuoted(value interface{})

func (*Statement) WriteString

func (st *Statement) WriteString(str string) (int, error)

type TxBeginner

type TxBeginner interface {
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
}

type TxCommitter

type TxCommitter interface {
	Commit() error
	Rollback() error
}

type Where

type Where struct {
	Columns []WhereColumn
}

func (*Where) And

func (where *Where) And(field string, quality WhereEquality, value interface{}) WhereColumn

func (Where) Build

func (where Where) Build(builder Builder)

func (Where) MergeClause

func (where Where) MergeClause(clause *Clause)

func (Where) Name

func (where Where) Name() string

func (*Where) Or

func (where *Where) Or(field string, quality WhereEquality, value interface{}) WhereColumn

type WhereColumn

type WhereColumn interface {
	C(WhereColumn)
	Len() int

	IsEmpty() bool
	// contains filtered or unexported methods
}

func And

func And(field string, quality, value interface{}) WhereColumn

type WhereEquality

type WhereEquality string
const (

	// equal
	WE_EQ WhereEquality = "="
	// not equal
	WE_NE WhereEquality = "<>"
	// like
	WE_LK WhereEquality = "LIKE"
	// less than
	WE_LT WhereEquality = "<"
	// less than or equal to
	WE_LTE WhereEquality = "<="
	// greater than
	WE_GT WhereEquality = ">"
	// greater than or equal to
	WE_GTE     WhereEquality = ">="
	WE_BETWEEN WhereEquality = "BETWEEN"
	WE_IN      WhereEquality = "IN"
)

func ToWhereEquality

func ToWhereEquality(op string) WhereEquality

func (WhereEquality) Equality

func (we WhereEquality) Equality() string

type Writer

type Writer interface {
	WriteByte(byte) error
	WriteString(string) (int, error)
}

Directories

Path Synopsis
pkg

Jump to

Keyboard shortcuts

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