Back to godoc.org
github.com/rushteam/gosql

package gosql

v0.1.2
Latest Go to latest
Published: Jun 14, 2020 | License: MIT | Module: github.com/rushteam/gosql

Index

Variables

var Debug = false

Debug env

var ErrNoRows = sql.ErrNoRows

ErrNoRows sql ErrNoRows

func DeleteSQL

func DeleteSQL(opts ...Option) (string, []interface{})

DeleteSQL ..

func InsertSQL

func InsertSQL(opts ...Option) (string, []interface{})

InsertSQL ..

func NewCollect

func NewCollect(clst Cluster, name ...string)

NewCollect ..

func ReplaceSQL

func ReplaceSQL(opts ...Option) (string, []interface{})

ReplaceSQL ..

func SelectSQL

func SelectSQL(opts ...Option) (string, []interface{})

SelectSQL ..

func UpdateSQL

func UpdateSQL(opts ...Option) (string, []interface{})

UpdateSQL ..

type Add

type Add int

Add ..

type Clause

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

Clause ...

func (*Clause) Build

func (p *Clause) Build(i int) (string, []interface{})

Build ...

func (*Clause) OrWhere

func (p *Clause) OrWhere(key interface{}, vals ...interface{}) *Clause

OrWhere ..

func (*Clause) Where

func (p *Clause) Where(key interface{}, vals ...interface{}) *Clause

Where ..

type Cluster

type Cluster interface {
	Executor(s *Session, master bool) (*Session, error)
	Begin() (*Session, error)
	Fetch(dst interface{}, opts ...Option) error
	FetchAll(dst interface{}, opts ...Option) error
	Update(dst interface{}, opts ...Option) (Result, error)
	Insert(dst interface{}, opts ...Option) (Result, error)
	Replace(dst interface{}, opts ...Option) (Result, error)
	Delete(dst interface{}, opts ...Option) (Result, error)
}

Cluster ..

func Collect

func Collect(name ...string) Cluster

Collect get a cluster by name

type DB

type DB interface {
	SetMaxIdleConns(n int)
	SetMaxOpenConns(n int)
	SetConnMaxLifetime(d time.Duration)
	Stats() sql.DBStats
	PingContext(ctx context.Context) error
	Ping() error
	Close() error
	BeginTx(ctx context.Context, opts *sql.TxOptions) (*sql.Tx, error)
	Begin() (*sql.Tx, error)
	Driver() driver.Driver
	Conn(ctx context.Context) (*sql.Conn, error)
}

DB ..

type DbOption

type DbOption func(db *sql.DB) *sql.DB

DbOption ..

func SetConnMaxLifetime

func SetConnMaxLifetime(d time.Duration) DbOption

SetConnMaxLifetime ..

func SetMaxIdleConns

func SetMaxIdleConns(n int) DbOption

SetMaxIdleConns ..

func SetMaxOpenConns

func SetMaxOpenConns(n int) DbOption

SetMaxOpenConns ..

type Error

type Error struct {
	Number  uint16
	Message string
}

Error ..

func (*Error) Error

func (e *Error) Error() string

type Executor

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

Executor is a Executor

type Option

type Option func(q SQLSegments) SQLSegments

Option is SQL segment part

func Columns

func Columns(fields ...string) Option

Columns for set columns

func CorssJoin

func CorssJoin(table string, conditionA, logic, conditionB string) Option

CorssJoin for corss join

func Flag

func Flag(flags ...string) Option

Flag for set flag

func ForUpdate

func ForUpdate() Option

ForUpdate ..

func GroupBy

func GroupBy(fields ...string) Option

GroupBy ..

func InnerJoin

func InnerJoin(table string, conditionA, logic, conditionB string) Option

InnerJoin for inner join

func Join

func Join(table string, conditionA, logic, conditionB string) Option

Join for join

func LeftJoin

func LeftJoin(table string, conditionA, logic, conditionB string) Option

LeftJoin ..

func Limit

func Limit(n int) Option

Limit ..

func Offset

func Offset(n int) Option

Offset ..

func OrWhere

func OrWhere(key interface{}, vals ...interface{}) Option

OrWhere ..

func OrderBy

func OrderBy(fields ...string) Option

OrderBy ..

func Params

func Params(vals ...map[string]interface{}) Option

Params ...

func Returning

func Returning() Option

Returning ..

func RightJoin

func RightJoin(table string, conditionA, logic, conditionB string) Option

RightJoin for right join

func Set

func Set(key string, val interface{}) Option

Set ..

func Table

func Table(name interface{}) Option

Table for set table

func Union

func Union(f func(*SQLSegments)) Option

Union for union sql

func Where

func Where(key interface{}, vals ...interface{}) Option

Where ..

type PoolCluster

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

PoolCluster impl Cluster

func NewCluster

func NewCluster(opts ...PoolClusterOpts) *PoolCluster

NewCluster start

func (*PoolCluster) Begin

func (c *PoolCluster) Begin() (*Session, error)

Begin a transaction

func (*PoolCluster) Delete

func (c *PoolCluster) Delete(dst interface{}, opts ...Option) (Result, error)

Delete delete record

func (*PoolCluster) Exec

func (c *PoolCluster) Exec(query string, args ...interface{}) (sql.Result, error)

Exec ..

func (*PoolCluster) ExecContext

func (c *PoolCluster) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext ..

func (*PoolCluster) Executor

func (c *PoolCluster) Executor(s *Session, master bool) (*Session, error)

Executor ..

func (*PoolCluster) Fetch

func (c *PoolCluster) Fetch(dst interface{}, opts ...Option) error

Fetch fetch record to model

func (*PoolCluster) FetchAll

func (c *PoolCluster) FetchAll(dst interface{}, opts ...Option) error

FetchAll fetch records to models

func (*PoolCluster) Insert

func (c *PoolCluster) Insert(dst interface{}, opts ...Option) (Result, error)

Insert insert from model

func (*PoolCluster) Master

func (c *PoolCluster) Master() (*Session, error)

Master select master db

func (*PoolCluster) Query

func (c *PoolCluster) Query(query string, args ...interface{}) (*sql.Rows, error)

Query ..

func (*PoolCluster) QueryContext

func (c *PoolCluster) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContext ..

func (*PoolCluster) QueryRow

func (c *PoolCluster) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow ..

func (*PoolCluster) QueryRowContext

func (c *PoolCluster) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext ..

func (*PoolCluster) Replace

func (c *PoolCluster) Replace(dst interface{}, opts ...Option) (Result, error)

Replace replace from model

func (*PoolCluster) Slave

func (c *PoolCluster) Slave(v uint64) (*Session, error)

Slave select slave db

func (*PoolCluster) Update

func (c *PoolCluster) Update(dst interface{}, opts ...Option) (Result, error)

Update update from model

type PoolClusterOpts

type PoolClusterOpts func(p *PoolCluster) *PoolCluster

PoolClusterOpts ..

func AddDb

func AddDb(driver, dsn string, opts ...DbOption) PoolClusterOpts

AddDb add a db

type Result

type Result sql.Result

Result sql Result

type SQLSegments

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

SQLSegments ...

func NewSQLSegment

func NewSQLSegment() *SQLSegments

NewSQLSegment ..

func (*SQLSegments) Args

func (s *SQLSegments) Args() []interface{}

Args for set some args

func (*SQLSegments) Build

func (s *SQLSegments) Build() (string, []interface{})

Build for build a sql with SQLSegments

func (*SQLSegments) BuildDelete

func (s *SQLSegments) BuildDelete() string

BuildDelete build a delete sql

func (*SQLSegments) BuildInsert

func (s *SQLSegments) BuildInsert() string

BuildInsert ...

func (*SQLSegments) BuildReplace

func (s *SQLSegments) BuildReplace() string

BuildReplace build a replace sql

func (*SQLSegments) BuildSelect

func (s *SQLSegments) BuildSelect() string

BuildSelect ...

func (*SQLSegments) BuildUpdate

func (s *SQLSegments) BuildUpdate() string

BuildUpdate build a update sql

func (*SQLSegments) CorssJoin

func (s *SQLSegments) CorssJoin(table string, conditionA, logic, conditionB string) *SQLSegments

CorssJoin SQLSegments

func (*SQLSegments) Delete

func (s *SQLSegments) Delete() *SQLSegments

Delete for a part of delete sql

func (*SQLSegments) Field

func (s *SQLSegments) Field(fields ...string) *SQLSegments

Field SQLSegments

func (*SQLSegments) Flag

func (s *SQLSegments) Flag(flags ...string) *SQLSegments

Flag SQLSegments

func (*SQLSegments) ForUpdate

func (s *SQLSegments) ForUpdate() *SQLSegments

ForUpdate SQLSegments

func (*SQLSegments) GroupBy

func (s *SQLSegments) GroupBy(fields ...string) *SQLSegments

GroupBy SQLSegments

func (*SQLSegments) Having

func (s *SQLSegments) Having(key interface{}, vals ...interface{}) *SQLSegments

Having ...

func (*SQLSegments) InnerJoin

func (s *SQLSegments) InnerJoin(table string, conditionA, logic, conditionB string) *SQLSegments

InnerJoin SQLSegments

func (*SQLSegments) Insert

func (s *SQLSegments) Insert(vals ...map[string]interface{}) *SQLSegments

Insert ...

func (*SQLSegments) IsEmptyWhereClause

func (s *SQLSegments) IsEmptyWhereClause() bool

IsEmptyWhereClause ...

func (*SQLSegments) Join

func (s *SQLSegments) Join(table string, conditionA, logic, conditionB string) *SQLSegments

Join SQLSegments

func (*SQLSegments) LeftJoin

func (s *SQLSegments) LeftJoin(table string, conditionA, logic, conditionB string) *SQLSegments

LeftJoin SQLSegments

func (*SQLSegments) Limit

func (s *SQLSegments) Limit(n int) *SQLSegments

Limit SQLSegments

func (*SQLSegments) Offset

func (s *SQLSegments) Offset(n int) *SQLSegments

Offset SQLSegments

func (*SQLSegments) OrWhere

func (s *SQLSegments) OrWhere(key interface{}, vals ...interface{}) *SQLSegments

OrWhere ..

func (*SQLSegments) OrderBy

func (s *SQLSegments) OrderBy(fields ...string) *SQLSegments

OrderBy SQLSegments

func (*SQLSegments) Params

func (s *SQLSegments) Params(vals ...map[string]interface{}) *SQLSegments

Params ...

func (*SQLSegments) Returning

func (s *SQLSegments) Returning() *SQLSegments

Returning SQLSegments

func (*SQLSegments) RightJoin

func (s *SQLSegments) RightJoin(table string, conditionA, logic, conditionB string) *SQLSegments

RightJoin SQLSegments

func (*SQLSegments) Table

func (s *SQLSegments) Table(name interface{}) *SQLSegments

Table SQLSegments

func (*SQLSegments) Union

func (s *SQLSegments) Union(f func(*SQLSegments)) *SQLSegments

Union ...

func (*SQLSegments) UnsafeUpdate

func (s *SQLSegments) UnsafeUpdate(vals map[string]interface{}) *SQLSegments

UnsafeUpdate 可以没有where条件更新 ,Update 更新必须指定where条件才能更新否则panic

func (*SQLSegments) Update

func (s *SQLSegments) Update(vals map[string]interface{}) *SQLSegments

Update ..

func (*SQLSegments) UpdateField

func (s *SQLSegments) UpdateField(key string, val interface{}) *SQLSegments

UpdateField for set a field when update sql

func (*SQLSegments) Where

func (s *SQLSegments) Where(key interface{}, vals ...interface{}) *SQLSegments

Where ..

type Session

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

Session ..

func (*Session) Commit

func (s *Session) Commit() error

Commit ..

func (*Session) Delete

func (s *Session) Delete(dst interface{}, opts ...Option) (Result, error)

Delete ..

func (*Session) Exec

func (s *Session) Exec(query string, args ...interface{}) (sql.Result, error)

Exec ..

func (*Session) ExecContext

func (s *Session) ExecContext(ctx context.Context, query string, args ...interface{}) (sql.Result, error)

ExecContext ..

func (*Session) Executor

func (s *Session) Executor() (Executor, error)

Executor ..

func (*Session) Fetch

func (s *Session) Fetch(dst interface{}, opts ...Option) error

Fetch ..

func (*Session) FetchAll

func (s *Session) FetchAll(dst interface{}, opts ...Option) error

FetchAll ..

func (*Session) Insert

func (s *Session) Insert(dst interface{}, opts ...Option) (Result, error)

Insert ..

func (*Session) Query

func (s *Session) Query(query string, args ...interface{}) (*sql.Rows, error)

Query ..

func (*Session) QueryContext

func (s *Session) QueryContext(ctx context.Context, query string, args ...interface{}) (*sql.Rows, error)

QueryContext ..

func (*Session) QueryRow

func (s *Session) QueryRow(query string, args ...interface{}) *sql.Row

QueryRow ..

func (*Session) QueryRowContext

func (s *Session) QueryRowContext(ctx context.Context, query string, args ...interface{}) *sql.Row

QueryRowContext ..

func (*Session) Replace

func (s *Session) Replace(dst interface{}, opts ...Option) (Result, error)

Replace ..

func (*Session) Rollback

func (s *Session) Rollback() error

Rollback ..

func (*Session) Update

func (s *Session) Update(dst interface{}, opts ...Option) (Result, error)

Update ..

type Sub

type Sub int

Sub ..

type TbName

type TbName struct {
	Name  string
	Alias string
}

TbName ..

type Tx

type Tx interface {
	StmtContext(ctx context.Context, stmt *sql.Stmt) *sql.Stmt
	Stmt(stmt *sql.Stmt) *sql.Stmt
	Commit() error
	Rollback() error
}

Tx ..

Documentation was rendered with GOOS=linux and GOARCH=amd64.

Jump to identifier

Keyboard shortcuts

? : This menu
f or F : Jump to identifier