db

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Mar 26, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Command

type Command struct {
	SQLBuilder
	// contains filtered or unexported fields
}

Command a db command

func (*Command) Exec

func (c *Command) Exec(shardingTime *time.Time) (sql.Result, error)

Exec execute command in db

func (*Command) ExecSQL

func (c *Command) ExecSQL(s string, shardingTime *time.Time) (sql.Result, error)

ExecSQL execute command in db

func (*Command) First

func (c *Command) First(cmd string, shardingTime *time.Time) string

First return first columan as a single value

type Context

type Context struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Context db context

func NewContext

func NewContext(ctx context.Context, driverName, dataSourceName string) *Context

NewContext create a db context instance, is not thread safe

func (*Context) Begin

func (c *Context) Begin() error

Begin start a db transaction

func (*Context) Clone

func (c *Context) Clone(ctx context.Context) *Context

Clone clone a new db context with new context.Context

func (*Context) Commit

func (c *Context) Commit() error

Commit commit the db transaction if it is valid

func (*Context) NewCommand

func (c *Context) NewCommand() *Command

NewCommand return a new command

func (*Context) NewQuery

func (c *Context) NewQuery() *Query

NewQuery return a new query

func (*Context) RawDB

func (c *Context) RawDB() *sql.DB

RawDB return raw sql.DB instance

func (*Context) Rollback

func (c *Context) Rollback() error

Rollback rollback the db transaction if it is valid

func (*Context) TraceSlowSQL

func (c *Context) TraceSlowSQL(status bool, t *time.Duration)

TraceSlowSQL turn on/off slow sql tracing

type Query

type Query struct {
	SQLBuilder
	// contains filtered or unexported fields
}

Query query data in db

func (*Query) Find

func (q *Query) Find(model interface{}, shardingTime *time.Time) error

Find result single value with sql in db

func (*Query) FindAll

func (q *Query) FindAll(list interface{}, shardingTimeFrom, shardingTimeTo *time.Time) error

FindAll return all values with sql in db

type SQLBuilder

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

SQLBuilder sql builder

func (*SQLBuilder) Limit

func (sb *SQLBuilder) Limit(size, index int64)

Limit set limit clause,ignore when size is 0

func (*SQLBuilder) OrderBy

func (sb *SQLBuilder) OrderBy(clause string)

OrderBy set order by clause

func (*SQLBuilder) RawSQL

func (sb *SQLBuilder) RawSQL(sql string)

RawSQL set raw sql

func (*SQLBuilder) SetOrderColumn

func (sb *SQLBuilder) SetOrderColumn(clientColName, dbColName string)

SetOrderColumn add orderable column mapping, prevent sql injection

func (*SQLBuilder) String

func (sb *SQLBuilder) String() string

String implements Stringer, return final sql

func (*SQLBuilder) Var

func (sb *SQLBuilder) Var(name string, value interface{}, predicate bool)

Var add/update variable

func (*SQLBuilder) Vars

func (sb *SQLBuilder) Vars() *Vars

Vars return a Vars

func (*SQLBuilder) WhereAnd

func (sb *SQLBuilder) WhereAnd(clause string)

WhereAnd add a and where clause

func (*SQLBuilder) WhereOr

func (sb *SQLBuilder) WhereOr(clause string)

WhereOr add a or where clause

type Vars

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

Vars a key/value collection

func (*Vars) WithNames

func (vars *Vars) WithNames(names ...string) *Vars

WithNames set names

func (*Vars) WithValues

func (vars *Vars) WithValues(values ...interface{})

WithValues set values

Jump to

Keyboard shortcuts

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