Documentation ¶
Overview ¶
=============================================================== * Copyright (C) 2020 All rights reserved. * * FileName:hook.go * Author:WuGuoFu * Date: 2020-06-17 * Description: * ================================================================
Index ¶
- Variables
- func AddMysql(options []MysqlOption)
- type DBDao
- type DbBaseDao
- func (this *DbBaseDao) BuildQuery(input Param, name string)
- func (this *DbBaseDao) Count(bean ...interface{}) (int64, error)
- func (this *DbBaseDao) Create(bean interface{}) (int64, error)
- func (this *DbBaseDao) Delete(bean interface{}) (int64, error)
- func (this *DbBaseDao) Exec(sqlOrArgs ...interface{}) (sql.Result, error)
- func (this *DbBaseDao) Exist(bean ...interface{}) (bool, error)
- func (this *DbBaseDao) Find(beans interface{}, condiBeans ...interface{}) error
- func (this *DbBaseDao) FindAndCount(rowsSlicePtr interface{}, condiBean ...interface{}) (int64, error)
- func (this *DbBaseDao) Get(bean interface{}) (bool, error)
- func (this *DbBaseDao) InitSession()
- func (this *DbBaseDao) Query(sqlorArgs ...interface{}) (resultsSlice []map[string][]byte, err error)
- func (this *DbBaseDao) QueryInterface(sqlorArgs ...interface{}) ([]map[string]interface{}, error)
- func (this *DbBaseDao) QueryString(sqlorArgs ...interface{}) ([]map[string]string, error)
- func (this *DbBaseDao) SetTable(tableName string)
- func (this *DbBaseDao) Sum(bean interface{}, colName string) (float64, error)
- func (this *DbBaseDao) SumInt(bean interface{}, colName string) (int64, error)
- func (this *DbBaseDao) Sums(bean interface{}, colNames ...string) ([]float64, error)
- func (this *DbBaseDao) SumsInt(bean interface{}, colNames ...string) ([]int64, error)
- func (this *DbBaseDao) Update(bean interface{}) (int64, error)
- func (this *DbBaseDao) UpdateCols(bean interface{}, cols ...string) (int64, error)
- func (this *DbBaseDao) UpdateEngine(v ...interface{})
- type Engine
- func (engine *Engine) After(closures func(interface{})) *Session
- func (engine *Engine) Alias(alias string) *Session
- func (engine *Engine) AllCols() *Session
- func (engine *Engine) Asc(colNames ...string) *Session
- func (engine *Engine) Before(closures func(interface{})) *Session
- func (engine *Engine) Cascade(trueOrFalse ...bool) *Session
- func (engine *Engine) Charset(charset string) *Session
- func (engine *Engine) Cols(columns ...string) *Session
- func (engine *Engine) Context(ctx context.Context) *Session
- func (engine *Engine) Decr(column string, arg ...interface{}) *Session
- func (engine *Engine) Desc(colNames ...string) *Session
- func (engine *Engine) Distinct(columns ...string) *Session
- func (engine *Engine) GroupBy(keys string) *Session
- func (engine *Engine) Having(conditions string) *Session
- func (engine *Engine) ID(id interface{}) *Session
- func (engine *Engine) Id(id interface{}) *Session
- func (engine *Engine) In(column string, args ...interface{}) *Session
- func (engine *Engine) Incr(column string, arg ...interface{}) *Session
- func (engine *Engine) Join(joinOperator string, tablename interface{}, condition string, ...) *Session
- func (engine *Engine) Limit(limit int, start ...int) *Session
- func (engine *Engine) MustCols(columns ...string) *Session
- func (engine *Engine) NewSession() *Session
- func (engine *Engine) NoAutoCondition(no ...bool) *Session
- func (engine *Engine) NoAutoTime() *Session
- func (engine *Engine) NoCache() *Session
- func (engine *Engine) NoCascade() *Session
- func (engine *Engine) NotIn(column string, args ...interface{}) *Session
- func (engine *Engine) Nullable(columns ...string) *Session
- func (engine *Engine) Omit(columns ...string) *Session
- func (engine *Engine) OrderBy(order string) *Session
- func (engine *Engine) PingContext(ctx context.Context) error
- func (engine *Engine) Prepare() *Session
- func (engine *Engine) SQL(query interface{}, args ...interface{}) *Session
- func (engine *Engine) Select(str string) *Session
- func (engine *Engine) SetDefaultContext(ctx context.Context)
- func (engine *Engine) SetExpr(column string, expression string) *Session
- func (engine *Engine) Sql(querystring string, args ...interface{}) *Sessiondeprecated
- func (engine *Engine) StoreEngine(storeEngine string) *Session
- func (engine *Engine) Table(tableNameOrBean interface{}) *Session
- func (engine *Engine) UseBool(columns ...string) *Session
- func (engine *Engine) Where(query interface{}, args ...interface{}) *Session
- type MysqlOption
- type Param
- type ParamDesc
- type ParamIn
- type ParamInDesc
- type ParamNil
- type ParamRange
- type ParamRangeDesc
- type Session
- func (session *Session) After(closures func(interface{})) *Session
- func (session *Session) Alias(alias string) *Session
- func (session *Session) AllCols() *Session
- func (session *Session) And(query interface{}, args ...interface{}) *Session
- func (session *Session) Asc(colNames ...string) *Session
- func (session *Session) Before(closures func(interface{})) *Session
- func (session *Session) Cascade(trueOrFalse ...bool) *Session
- func (session *Session) Charset(charset string) *Session
- func (session *Session) Cols(columns ...string) *Session
- func (session *Session) Context(ctx context.Context) *Session
- func (session *Session) Decr(column string, arg ...interface{}) *Session
- func (session *Session) Delete(bean interface{}) (int64, error)
- func (session *Session) Desc(colNames ...string) *Session
- func (session *Session) Distinct(columns ...string) *Session
- func (session *Session) Exec(sqlOrArgs ...interface{}) (sql.Result, error)
- func (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{}) error
- func (session *Session) FindAndCount(rowsSlicePtr interface{}, condiBean ...interface{}) (int64, error)
- func (session *Session) ForUpdate() *Session
- func (session *Session) Get(bean interface{}) (bool, error)
- func (session *Session) GroupBy(keys string) *Session
- func (session *Session) Having(conditions string) *Session
- func (session *Session) ID(id interface{}) *Session
- func (session *Session) Id(id interface{}) *Sessiondeprecated
- func (session *Session) In(column string, args ...interface{}) *Session
- func (session *Session) Incr(column string, arg ...interface{}) *Session
- func (session *Session) Insert(beans ...interface{}) (int64, error)
- func (session *Session) InsertMulti(rowsSlicePtr interface{}) (int64, error)
- func (session *Session) InsertOne(bean interface{}) (int64, error)
- func (session *Session) Join(joinOperator string, tablename interface{}, condition string, ...) *Session
- func (session *Session) LastSQL() (string, []interface{})
- func (session *Session) Limit(limit int, start ...int) *Session
- func (session *Session) MustCols(columns ...string) *Session
- func (session *Session) NoAutoCondition(no ...bool) *Session
- func (session *Session) NoAutoTime() *Session
- func (session *Session) NoCache() *Session
- func (session *Session) NoCascade() *Session
- func (session *Session) NotIn(column string, args ...interface{}) *Session
- func (session *Session) Nullable(columns ...string) *Session
- func (session *Session) Omit(columns ...string) *Session
- func (session *Session) Or(query interface{}, args ...interface{}) *Session
- func (session *Session) OrderBy(order string) *Session
- func (session *Session) PingContext(ctx context.Context) error
- func (session *Session) Prepare() *Session
- func (session *Session) Query(sqlOrArgs ...interface{}) ([]map[string][]byte, error)
- func (session *Session) QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error)
- func (session *Session) QuerySliceString(sqlOrArgs ...interface{}) ([][]string, error)
- func (session *Session) QueryString(sqlOrArgs ...interface{}) ([]map[string]string, error)
- func (session *Session) SQL(query interface{}, args ...interface{}) *Session
- func (session *Session) Select(str string) *Session
- func (session *Session) SetExpr(column string, expression string) *Session
- func (session *Session) Sql(query string, args ...interface{}) *Sessiondeprecated
- func (session *Session) StoreEngine(storeEngine string) *Session
- func (session *Session) Table(tableNameOrBean interface{}) *Session
- func (session *Session) Unscoped() *Session
- func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int64, error)
- func (session *Session) UseBool(columns ...string) *Session
- func (session *Session) Where(query interface{}, args ...interface{}) *Session
Constants ¶
This section is empty.
Variables ¶
var ( HookExec func(func() (sql.Result, error)) (sql.Result, error) HookGet func(func() (bool, error)) (bool, error) HookFind func(func() error) error HookInsert func(func() (int64, error)) (int64, error) HookDelete func(func() (int64, error)) (int64, error) HookQuery func(func() ([]map[string][]byte, error)) ([]map[string][]byte, error) HookUpdate func(func() (int64, error)) (int64, error) )
Functions ¶
Types ¶
type DBDao ¶
type DBDao struct { Engine *Engine // contains filtered or unexported fields }
func GetDbInstance ¶
GetDbInstance returns DBDao instance.
func GetDbInstanceWithCtx ¶
GetDbInstanceWithCtx returns DBDao instance. If it's a stress test scenario,return benchmark_dbName.
func GetDefault ¶
func (*DBDao) GetSession ¶
GetSession returns a new Session
type DbBaseDao ¶
func (*DbBaseDao) BuildQuery ¶
Construct sql query statement and execute.
func (*DbBaseDao) Delete ¶
Delete records, bean's non-empty fields are conditions, Delete with ID primary key.
func (*DbBaseDao) Find ¶
Find retrieve records from table, condiBeans's non-empty fields are conditions. beans could be []Struct, []*Struct, map[int64]Struct map[int64]*Struct
func (*DbBaseDao) FindAndCount ¶
func (this *DbBaseDao) FindAndCount(rowsSlicePtr interface{}, condiBean ...interface{}) (int64, error)
FindAndCount find the results and also return the counts
func (*DbBaseDao) Query ¶
func (this *DbBaseDao) Query(sqlorArgs ...interface{}) (resultsSlice []map[string][]byte, err error)
Query a raw sql and return records as []map[string][]byte
func (*DbBaseDao) QueryInterface ¶
QueryInterface runs a raw sql and return records as []map[string]interface{}
func (*DbBaseDao) QueryString ¶
QueryString runs a raw sql and return records as []map[string]string
func (*DbBaseDao) SumInt ¶
SumInt sum the records by some column. bean's non-empty fields are conditions.
func (*DbBaseDao) Sums ¶
Sums sum the records by some columns. bean's non-empty fields are conditions.
func (*DbBaseDao) Update ¶
Update records, bean's non-empty fields are updated contents, Update with ID primary key.
func (*DbBaseDao) UpdateCols ¶
Update special specified fields, Update with ID primary key.
func (*DbBaseDao) UpdateEngine ¶
func (this *DbBaseDao) UpdateEngine(v ...interface{})
Update MySQL execution engine.
type Engine ¶
func (*Engine) Asc ¶
Asc will generate "ORDER BY column1,column2 Asc" This method can chainable use.
engine.Desc("name").Asc("age").Find(&users) // SELECT * FROM user ORDER BY name DESC, age ASC
func (*Engine) Distinct ¶
Distinct use for distinct columns. Caution: when you are using cache, distinct will not be cached because cache system need id, but distinct will not provide id
func (*Engine) Join ¶
func (engine *Engine) Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *Session
Join the join_operator should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN
func (*Engine) NoAutoCondition ¶
NoAutoCondition disable auto generate Where condition from bean or not
func (*Engine) NoAutoTime ¶
NoAutoTime Default if your struct has "created" or "updated" filed tag, the fields will automatically be filled with current time when Insert or Update invoked. Call NoAutoTime if you dont' want to fill automatically.
func (*Engine) PingContext ¶
PingContext tests if database is alive
func (*Engine) SQL ¶
SQL method let's you manually write raw SQL and operate For example:
engine.SQL("select * from user").Find(&users)
This code will execute "select * from user" and set the records to users
func (*Engine) SetDefaultContext ¶
SetDefaultContext set the default context
func (*Engine) StoreEngine ¶
StoreEngine set store engine when create table, only support mysql now
type MysqlOption ¶
type ParamIn ¶
type ParamIn []interface{}
func CastToParamIn ¶
func CastToParamIn(input interface{}) ParamIn
cast input to []interface{} type.
type ParamInDesc ¶
type ParamInDesc ParamIn
func CastToParamInDesc ¶
func CastToParamInDesc(input interface{}) ParamInDesc
cast input to ParamIn type.
type ParamRange ¶
type ParamRange struct { Min interface{} Max interface{} }
type ParamRangeDesc ¶
type ParamRangeDesc ParamRange
type Session ¶
func (*Session) Desc ¶
Desc provide desc order by query condition, the input parameters are columns.
func (*Session) Distinct ¶
Distinct use for distinct columns. Caution: when you are using cache, distinct will not be cached because cache system need id, but distinct will not provide id
func (*Session) Find ¶
Find retrieve records from table, condiBeans's non-empty fields are conditions. beans could be []Struct, []*Struct, map[int64]Struct map[int64]*Struct
func (*Session) FindAndCount ¶
func (session *Session) FindAndCount(rowsSlicePtr interface{}, condiBean ...interface{}) (int64, error)
FindAndCount find the results and also return the counts
func (*Session) Get ¶
Get retrieve one record from database, bean's non-empty fields will be as conditions
func (*Session) InsertMulti ¶
InsertMulti insert multiple records
func (*Session) InsertOne ¶
InsertOne insert only one struct into database as a record. The in parameter bean must a struct or a point to struct. The return parameter is inserted and error
func (*Session) Join ¶
func (session *Session) Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *Session
Join join_operator should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN
func (*Session) NoAutoCondition ¶
NoAutoCondition disable generate SQL condition from beans
func (*Session) NoAutoTime ¶
NoAutoTime means do not automatically give created field and updated field the current time on the current session temporarily
func (*Session) NoCache ¶
NoCache ask this session do not retrieve data from cache system and get data from database directly.
func (*Session) OrderBy ¶
OrderBy provide order by query condition, the input parameter is the content after order by on a sql statement.
func (*Session) PingContext ¶
PingContext test if database is ok
func (*Session) Prepare ¶
Prepare set a flag to session that should be prepare statement before execute query
func (*Session) QueryInterface ¶
QueryInterface runs a raw sql and return records as []map[string]interface{}
func (*Session) QuerySliceString ¶
QuerySliceString runs a raw sql and return records as [][]string
func (*Session) QueryString ¶
QueryString runs a raw sql and return records as []map[string]string
func (*Session) SQL ¶
SQL provides raw sql input parameter. When you have a complex SQL statement and cannot use Where, Id, In and etc. Methods to describe, you can use SQL.
func (*Session) StoreEngine ¶
StoreEngine is only avialble mysql dialect currently
func (*Session) Table ¶
Table can input a string or pointer to struct for special a table to operate.
func (*Session) Update ¶
Update records, bean's non-empty fields are updated contents, condiBean' non-empty filds are conditions CAUTION:
1.bool will defaultly be updated content nor conditions You should call UseBool if you have bool to use. 2.float32 & float64 may be not inexact as conditions