session

package
v0.0.0-...-3c93513 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2023 License: Apache-2.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BeforeQuery  = "BeforeQuery"
	AfterQuery   = "AfterQuery"
	BeforeUpdate = "BeforeUpdate"
	AfterUpdate  = "AfterUpdate"
	BeforeDelete = "BeforeDelete"
	AfterDelete  = "AfterDelete"
	BeforeInsert = "BeforeInsert"
	AfterInsert  = "AfterInsert"
)

Hooks constants

Variables

This section is empty.

Functions

This section is empty.

Types

type JoinType

type JoinType int

INNER JOIN、LEFT JOIN、RIGHT JOIN、FULL JOIN、CROSS JOIN,JION

const (
	JOIN JoinType = iota + 1 // inner join
	INNER
	LEFT
	RIGHT
	FULL
	CROSS
)

func (JoinType) String

func (j JoinType) String() string

type Session

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

Session keep a pointer to sql.DB and provides all execution of all kind of database operations.

func New

func New(db *server.DB, split *map[string]spliter.Split, dbs map[string]*server.DB, opt operator.Operator, config *server.Config) *Session

New creates instance of Session

func (*Session) Begin

func (s *Session) Begin() (err error)

Begin a transaction

func (*Session) CallMethod

func (s *Session) CallMethod(method string, value interface{})

s.CallMethod(BeforeUpdate, nil) CallMethod calls the registered hooks

func (*Session) Clear

func (s *Session) Clear()

Clear initialize the state of a session

func (*Session) Commit

func (s *Session) Commit() (err error)

Commit a transaction

func (*Session) Count

func (s *Session) Count() (int64, error)

Count records with where clause

func (*Session) Create

func (s *Session) Create(values interface{}) (int64, error)

func (*Session) Delete

func (s *Session) Delete() (int64, error)

Delete records with where clause

func (*Session) DropTable

func (s *Session) DropTable() error

DropTable drops a table with the name of model

func (*Session) Find

func (s *Session) Find(values interface{}) error

Find gets all eligible records

func (*Session) First

func (s *Session) First(value interface{}) error

First gets the 1st row

func (*Session) GetIntFromInterface

func (s *Session) GetIntFromInterface(val interface{}) (int, error)

输入一个interface{}类型的值,返回一个int 类型的值

func (*Session) GetTableFromNone

func (s *Session) GetTableFromNone(tableName string) ([]string, error)

仅支持获取以数字 分表的选手

func (*Session) GetTableFromTableAndSplitFiled

func (s *Session) GetTableFromTableAndSplitFiled(tableName string, splitFiledVal interface{}) (string, error)

GetTableFromTableAndSplitFiled 根据表名和分表字段获取表名 如果分表字段为空,就返回原来的表名 tableName 表名 splitFiledVal 分表字段的值 一般只有两种类型 一个是int 一个是time.Time

func (*Session) GetTimeFromInterface

func (s *Session) GetTimeFromInterface(val interface{}) (time.Time, error)

输入一个interface{}类型的值,返回一个time.Time 类型的值

func (*Session) GroupBy

func (s *Session) GroupBy(desc string) *Session

GroupBy adds group by condition to clause

func (*Session) Having

func (s *Session) Having(desc string, args ...interface{}) *Session

Having adds having condition to clause

func (*Session) Join

func (s *Session) Join(joinType JoinType, desc string, args ...interface{}) *Session

Join adds join condition to clause

func (*Session) Limit

func (s *Session) Limit(num int) *Session

Limit adds limit condition to clause

func (*Session) Model

func (s *Session) Model(value interface{}) *Session

Model assigns refTable

func (*Session) Offset

func (s *Session) Offset(num int) *Session

Limit adds limit condition to clause

func (*Session) Omit

func (s *Session) Omit(field ...string) *Session

func (*Session) Or

func (s *Session) Or(desc string, args ...interface{}) *Session

func (*Session) OrderBy

func (s *Session) OrderBy(desc string) *Session

OrderBy adds order by condition to clause

func (*Session) Query

func (s *Session) Query(ctx context.Context, db *sql.DB, dia dialect.Dialect, sqlInfo string, args []interface{}, list interface{}) error

Query QueryRow gets a record from db

func (*Session) QueryPagination

func (s *Session) QueryPagination(ctx context.Context, db *sql.DB, dia dialect.Dialect, sqlInfo string, args []interface{}, limit, offset int, list interface{}) (err error)

QueryPagination QueryRow gets a record from db

func (*Session) QueryRowContext

func (s *Session) QueryRowContext(ctx context.Context, db *sql.DB, dia dialect.Dialect, sqlInfo string, args []interface{}) *sql.Row

func (*Session) Raw

func (s *Session) Raw(sql string, values ...interface{}) *Session

Raw appends sql and sqlVars

func (*Session) RefTable

func (s *Session) RefTable() *schema.Schema

RefTable returns a Schema instance that contains all parsed fields

func (*Session) Rollback

func (s *Session) Rollback() (err error)

Rollback a transaction

func (*Session) Select

func (s *Session) Select(field ...string) *Session

Select custom input fields

func (*Session) Table

func (s *Session) Table(table string) *Session

Table

func (*Session) Update

func (s *Session) Update(desc string, args ...interface{}) (int64, error)

func (*Session) Where

func (s *Session) Where(desc string, args ...interface{}) *Session

Where adds limit condition to clause

func (*Session) WithContext

func (s *Session) WithContext(ctx context.Context) *Session

WithContext sets context

Jump to

Keyboard shortcuts

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