Documentation
¶
Index ¶
- Constants
- Variables
- func SetDefaultJSONHandler(jsonHandler json.Interface)
- type AfterDeleteProcessor
- type AfterInsertProcessor
- type AfterLoadProcessor
- type AfterLoadSessionProcessor
- type AfterSetProcessor
- type AfterUpdateProcessor
- type BeforeDeleteProcessor
- type BeforeInsertProcessor
- type BeforeSetProcessor
- type BeforeUpdateProcessor
- type Cell
- type ColumnsSchema
- type Engine
- type ErrFieldIsNotExist
- type ErrFieldIsNotValid
- type IterFunc
- type QueryedField
- type Rows
- 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) Begin() error
- func (session *Session) BufferSize(size int) *Session
- func (session *Session) Cascade(trueOrFalse ...bool) *Session
- func (session *Session) Charset(charset string) *Session
- func (session *Session) Close() error
- func (session *Session) Cols(columns ...string) *Session
- func (session *Session) Commit() error
- func (session *Session) Conds() builder.Cond
- func (session *Session) Context(ctx context.Context) *Session
- func (session *Session) ContextCache(context contexts.ContextCache) *Session
- func (session *Session) Count(bean ...interface{}) (int64, error)
- func (session *Session) CreateIndexes(bean interface{}) error
- func (session *Session) CreateTable(bean interface{}) error
- func (session *Session) CreateUniques(bean interface{}) error
- func (session *Session) DB() *core.DB
- func (session *Session) Decr(column string, arg ...interface{}) *Session
- func (session *Session) Delete(beans ...interface{}) (int64, error)
- func (session *Session) Desc(colNames ...string) *Session
- func (session *Session) Distinct(columns ...string) *Session
- func (session *Session) DropIndexes(bean interface{}) error
- func (session *Session) DropTable(beanOrTableName interface{}) error
- func (session *Session) Exec(sqlOrArgs ...interface{}) (sql.Result, error)
- func (session *Session) Exist(bean ...interface{}) (bool, 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(beans ...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) Import(r io.Reader) ([]sql.Result, error)
- func (session *Session) ImportFile(ddlPath string) ([]sql.Result, error)
- func (session *Session) In(column string, args ...interface{}) *Session
- func (session *Session) Incr(column string, arg ...interface{}) *Session
- func (session *Session) IndexHint(op, forType, indexerOrColName string) *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) IsClosed() bool
- func (session *Session) IsInTx() bool
- func (session *Session) IsTableEmpty(bean interface{}) (bool, error)
- func (session *Session) IsTableExist(beanOrTableName interface{}) (bool, error)
- func (session *Session) Iterate(bean interface{}, fun IterFunc) error
- func (session *Session) Join(joinOperator string, tablename interface{}, condition interface{}, ...) *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) MustLogSQL(logs ...bool) *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) NoVersionCheck() *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 interface{}, args ...interface{}) *Session
- func (session *Session) Ping() error
- 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) Quote(value string) string
- func (session *Session) QuoteTo(buf *strings.Builder, value string)
- func (session *Session) Rollback() error
- func (session *Session) Rows(bean interface{}) (*Rows, error)
- func (session *Session) SQL(query interface{}, args ...interface{}) *Session
- func (session *Session) ScanInterfaceMap(rows *core.Rows) (map[string]interface{}, error)
- func (session *Session) ScanInterfaceMaps(rows *core.Rows) (resultsSlice []map[string]interface{}, err error)
- func (session *Session) ScanStringMap(rows *core.Rows) (map[string]string, error)
- func (session *Session) ScanStringMaps(rows *core.Rows) (resultsSlice []map[string]string, err error)
- func (session *Session) ScanStringSlice(rows *core.Rows) ([]string, error)
- func (session *Session) ScanStringSlices(rows *core.Rows) (resultsSlice [][]string, err error)
- func (session *Session) Select(str string) *Session
- func (session *Session) SetExpr(column string, expression interface{}) *Session
- func (session *Session) StoreEngine(storeEngine string) *Session
- func (session *Session) Sum(bean interface{}, columnName string) (res float64, err error)
- func (session *Session) SumInt(bean interface{}, columnName string) (res int64, err error)
- func (session *Session) Sums(bean interface{}, columnNames ...string) ([]float64, error)
- func (session *Session) SumsInt(bean interface{}, columnNames ...string) ([]int64, error)
- func (session *Session) Table(tableNameOrBean interface{}) *Session
- func (session *Session) TableInfo(bean interface{}) (*schemas.Table, error)
- func (session *Session) TableName(bean interface{}, includeSchema ...bool) string
- func (session *Session) Truncate(beans ...interface{}) (int64, error)
- func (session *Session) Tx() *core.Tx
- 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 ¶
Variables ¶
var ( // ErrPtrSliceType represents a type error ErrPtrSliceType = errors.New("A point to a slice is needed") // ErrParamsType params error ErrParamsType = errors.New("Params type error") // ErrTableNotFound table not found error ErrTableNotFound = errors.New("Table not found") // ErrUnSupportedType unsupported error ErrUnSupportedType = errors.New("Unsupported type error") // ErrNotExist record does not exist error ErrNotExist = errors.New("Record does not exist") // ErrCacheFailed cache failed error ErrCacheFailed = errors.New("Cache failed") // ErrConditionType condition type unsupported ErrConditionType = errors.New("Unsupported condition type") )
ErrNeedDeletedCond delete needs less one condition error
var (
ErrNoColumnsTobeUpdated = statements.ErrNoColumnsTobeUpdated
)
enumerated all errors
ErrNoElementsOnSlice represents an error there is no element when insert
Functions ¶
Types ¶
type AfterDeleteProcessor ¶
type AfterDeleteProcessor interface {
AfterDelete()
}
AfterDeleteProcessor executed after an object has been deleted
type AfterInsertProcessor ¶
type AfterInsertProcessor interface {
AfterInsert()
}
AfterInsertProcessor executed after an object is persisted to the database
type AfterLoadProcessor ¶
type AfterLoadProcessor interface {
AfterLoad()
}
AfterLoadProcessor executed after an ojbect has been loaded from database
type AfterLoadSessionProcessor ¶
type AfterLoadSessionProcessor interface {
AfterLoad(*Session)
}
AfterLoadSessionProcessor executed after an ojbect has been loaded from database with session parameter
type AfterSetProcessor ¶
AfterSetProcessor executed after data set to the struct fields
type AfterUpdateProcessor ¶
type AfterUpdateProcessor interface {
AfterUpdate()
}
AfterUpdateProcessor executed after an object has been updated
type BeforeDeleteProcessor ¶
type BeforeDeleteProcessor interface {
BeforeDelete()
}
BeforeDeleteProcessor executed before an object is deleted
type BeforeInsertProcessor ¶
type BeforeInsertProcessor interface {
BeforeInsert()
}
BeforeInsertProcessor executed before an object is initially persisted to the database
type BeforeSetProcessor ¶
BeforeSetProcessor executed before data set to the struct fields
type BeforeUpdateProcessor ¶
type BeforeUpdateProcessor interface {
BeforeUpdate()
}
BeforeUpdateProcessor executed before an object is updated
type ColumnsSchema ¶
type ColumnsSchema struct {
Fields []*QueryedField
FieldNames []string
Types []*sql.ColumnType
}
func ParseColumnsSchema ¶
func ParseColumnsSchema(fieldNames []string, types []*sql.ColumnType, table *schemas.Table) *ColumnsSchema
func (*ColumnsSchema) ParseTableSchema ¶
func (columnsSchema *ColumnsSchema) ParseTableSchema(table *schemas.Table)
type Engine ¶
type ErrFieldIsNotExist ¶
ErrFieldIsNotExist columns does not exist
func (ErrFieldIsNotExist) Error ¶
func (e ErrFieldIsNotExist) Error() string
type ErrFieldIsNotValid ¶
ErrFieldIsNotValid is not valid
func (ErrFieldIsNotValid) Error ¶
func (e ErrFieldIsNotValid) Error() string
type QueryedField ¶
type Rows ¶
type Rows struct {
// contains filtered or unexported fields
}
Rows rows wrapper a rows to
func (*Rows) Close ¶
Close session if session.IsAutoClose is true, and claimed any opened resources
func (*Rows) Err ¶
Err returns the error, if any, that was encountered during iteration. Err may be called after an explicit or implicit Close.
func (*Rows) Next ¶
Next move cursor to next record, return false if end has reached
type Session ¶
type Session struct {
TZLocation *time.Location
DatabaseTZ *time.Location
Dialect dialects.Dialect
Driver dialects.Driver
DriverName string
Logger log.ContextLogger
LogSessionID bool
TableNameMapper names.Mapper
IsAutoClose bool
SessionType sessionType
// contains filtered or unexported fields
}
Session keep a pointer to sql.DB and provides all execution of all kind of database operations.
func (*Session) After ¶
After Apply after Processor, affected bean is passed to closure arg
func (*Session) Alias ¶
Alias set the table alias
func (*Session) And ¶
And provides custom query condition.
func (*Session) Asc ¶
Asc provide asc order by query condition, the input parameters are columns.
func (*Session) Before ¶
Before Apply before Processor, affected bean is passed to closure arg
func (*Session) BufferSize ¶
BufferSize sets the buffersize for iterate
func (*Session) Cascade ¶
Cascade indicates if loading sub Struct
func (*Session) Charset ¶
Charset is only avialble mysql dialect currently
func (*Session) Close ¶
Close release the connection from pool
func (*Session) Cols ¶
Cols provides some columns to special
func (*Session) Commit ¶
Commit When using transaction, Commit will commit all operations.
func (*Session) Conds ¶
Conds returns session query conditions except auto bean conditions
func (*Session) Context ¶
Context sets the context on this session
func (*Session) ContextCache ¶
func (session *Session) ContextCache(context contexts.ContextCache) *Session
ContextCache enable context cache or not
func (*Session) Count ¶
Count counts the records. bean's non-empty fields are conditions.
func (*Session) CreateIndexes ¶
CreateIndexes create indexes
func (*Session) CreateTable ¶
CreateTable create a table according a bean
func (*Session) CreateUniques ¶
CreateUniques create uniques
func (*Session) Decr ¶
Decr provides a query string like "count = count - 1"
func (*Session) Delete ¶
Delete records, bean's non-empty fields are conditions At least one condition must be set.
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) DropIndexes ¶
DropIndexes drop indexes
func (*Session) DropTable ¶
DropTable drop table will drop table if exist, if drop failed, it will return error
func (*Session) Exec ¶
Exec raw sql
func (*Session) Exist ¶
Exist returns true if the record exist otherwise return false
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) ForUpdate ¶
ForUpdate Set Read/Write locking for UPDATE
func (*Session) Get ¶
Get retrieve one record from database, bean's non-empty fields will be as conditions
func (*Session) GroupBy ¶
GroupBy Generate Group By statement
func (*Session) Having ¶
Having Generate Having statement
func (*Session) ID ¶
ID provides converting id as a query condition
func (*Session) Import ¶
Import SQL DDL from io.Reader
func (*Session) ImportFile ¶
ImportFile SQL DDL file
func (*Session) In ¶
In provides a query string like "id in (1, 2, 3)"
func (*Session) Incr ¶
Incr provides a query string like "count = count + 1"
func (*Session) IndexHint ¶
func (*Session) Insert ¶
Insert insert one or more beans
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 Deprecated: Please use Insert directly
func (*Session) IsClosed ¶
IsClosed returns if session is closed
func (*Session) IsInTx ¶
IsInTx if current session is in a transaction
func (*Session) IsTableEmpty ¶
IsTableEmpty if table have any records
func (*Session) IsTableExist ¶
IsTableExist if a table is exist
func (*Session) Iterate ¶
Iterate record by record handle records from table, condiBeans's non-empty fields are conditions. beans could be []Struct, []*Struct, map[int64]Struct map[int64]*Struct
func (*Session) Join ¶
func (session *Session) Join(joinOperator string, tablename interface{}, condition interface{}, args ...interface{}) *Session
Join join_operator should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN
func (*Session) LastSQL ¶
LastSQL returns last query information
func (*Session) Limit ¶
Limit provide limit and offset query condition
func (*Session) MustCols ¶
MustCols specify some columns must use even if they are empty
func (*Session) MustLogSQL ¶
MustLogSQL means record SQL or not and don't follow engine's setting
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) NoCascade ¶
NoCascade indicate that no cascade load child object
func (*Session) NoVersionCheck ¶
disable version check
func (*Session) NotIn ¶
NotIn provides a query string like "id in (1, 2, 3)"
func (*Session) Nullable ¶
Nullable Set null when column is zero-value and nullable for update
func (*Session) Omit ¶
Omit Only not use the parameters as select or update columns
func (*Session) Or ¶
Or provides custom query condition.
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) Query ¶
Query runs a raw sql and return records as []map[string][]byte
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) Quote ¶
Quote Use QuoteStr quote the string sql
func (*Session) QuoteTo ¶
QuoteTo quotes string and writes into the buffer
func (*Session) Rollback ¶
Rollback When using transaction, you can rollback if any error
func (*Session) Rows ¶
Rows return sql.Rows compatible Rows obj, as a forward Iterator object for iterating record by record, bean's non-empty fields are conditions.
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) ScanInterfaceMap ¶
ScanInterfaceMap scan result from *core.Rows and return a map
func (*Session) ScanInterfaceMaps ¶
func (session *Session) ScanInterfaceMaps(rows *core.Rows) (resultsSlice []map[string]interface{}, err error)
ScanInterfaceMaps scan results from *core.Rows and return a slice of map
func (*Session) ScanStringMap ¶
ScanStringMap scan results from *core.Rows and return a map
func (*Session) ScanStringMaps ¶
func (session *Session) ScanStringMaps(rows *core.Rows) (resultsSlice []map[string]string, err error)
ScanStringMaps scan results from *core.Rows and return a slice of map
func (*Session) ScanStringSlice ¶
ScanStringSlice scan results from *core.Rows and return a slice of one row
func (*Session) ScanStringSlices ¶
ScanStringSlices scan results from *core.Rows and return a slice of all rows
func (*Session) Select ¶
Select provides some columns to special
func (*Session) SetExpr ¶
SetExpr provides a query string like "column = {expression}"
func (*Session) StoreEngine ¶
StoreEngine is only avialble mysql dialect currently
func (*Session) Sum ¶
Sum call sum some column. bean's non-empty fields are conditions.
func (*Session) SumInt ¶
SumInt call sum some column. bean's non-empty fields are conditions.
func (*Session) Sums ¶
Sums call sum some columns. bean's non-empty fields are conditions.
func (*Session) SumsInt ¶
SumsInt sum specify columns and return as []int64 instead of []float64
func (*Session) Table ¶
Table can input a string or pointer to struct for special a table to operate.
func (*Session) TableInfo ¶
TableInfo get table info according to bean's content
func (*Session) TableName ¶
TableName returns table name with schema prefix if has
func (*Session) Truncate ¶
Truncate records, bean's non-empty fields are conditions In contrast to Delete this method allows deletes without conditions.
func (*Session) Unscoped ¶
Unscoped always disable struct tag "deleted"
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
func (*Session) UseBool ¶
UseBool automatically retrieve condition according struct, but if struct has bool field, it will ignore them. So use UseBool to tell system to do not ignore them. If no parameters, it will use all the bool field of struct, or it will use parameters's columns
Source Files
¶
- error.go
- processors.go
- rows.go
- scan.go
- session.go
- session_cols.go
- session_cond.go
- session_delete.go
- session_exist.go
- session_find.go
- session_get.go
- session_insert.go
- session_iterate.go
- session_raw.go
- session_schema.go
- session_stats.go
- session_tx.go
- session_update.go