xorm

package
v1.2.17 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2021 License: MIT Imports: 57 Imported by: 0

README

FIX sqlType

packages/xormplus/xorm/schemas/type.go

FIX null update

packages/xormplus/xorm/internal/statements/update.go

FIX sql.Scanner

packages/xormplus/xorm/session.go

Documentation

Overview

Copyright 2018 The Xorm Authors. All rights reserved. Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

Index

Constants

View Source
const (
	RSA_PUBKEY_ENCRYPT_MODE = iota //公钥加密
	RSA_PUBKEY_DECRYPT_MODE        //公钥解密
	RSA_PRIKEY_ENCRYPT_MODE        //私钥加密
	RSA_PRIKEY_DECRYPT_MODE        //私钥解密
)
View Source
const (
	PROPAGATION_REQUIRED      = 0 //Support a current transaction; create a new one if none exists.
	PROPAGATION_SUPPORTS      = 1 //Support a current transaction; execute non-transactionally if none exists.
	PROPAGATION_MANDATORY     = 2 //Support a current transaction; return an error if no current transaction exists.
	PROPAGATION_REQUIRES_NEW  = 3 //Create a new transaction, suspending the current transaction if one exists.
	PROPAGATION_NOT_SUPPORTED = 4 //Do not support a current transaction; rather always execute non-transactionally.
	PROPAGATION_NEVER         = 5 //Do not support a current transaction; return an error if a current transaction exists.
	PROPAGATION_NESTED        = 6 //Execute within a nested transaction if a current transaction exists, behave like PROPAGATION_REQUIRED else.
	PROPAGATION_NOT_REQUIRED  = 7
)
View Source
const (
	MSSQL_DRIVER      string = "mssql"
	MSSQL_ODBC_DRIVER string = "odbc"
	MYSQL_DRIVER      string = "mysql"
	MYMYSQL_DRIVER    string = "mymysql"
	POSTGRESQL_DRIVER string = "postgres"
	OCI8_DRIVER       string = "oci8"
	GORACLE_DRIVER    string = "godror"
	SQLITE3_DRIVER    string = "sqlite3"
)
View Source
const (
	// Version show the xorm's version
	Version string = "1.0.5.0912"
)

Variables

View Source
var (
	ErrDataToLarge     = errors.New("message too long for RSA public key size")
	ErrDataLen         = errors.New("data length error")
	ErrDataBroken      = errors.New("data broken, first byte is not zero")
	ErrKeyPairDismatch = errors.New("data is not encrypted by the private key")
	ErrDecryption      = errors.New("decryption error")
	ErrPublicKey       = errors.New("get public key error")
	ErrPrivateKey      = errors.New("get private key error")
)
View Source
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")
	ErrParamsFormat = errors.New("Params format 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")
	ErrNotInTransaction      = errors.New("Not in transaction.")
	ErrNestedTransaction     = errors.New("Nested transaction error.")
	ErrTransactionDefinition = errors.New("Transaction definition error.")
	// ErrCacheFailed cache failed error
	ErrCacheFailed = errors.New("Cache failed")

	// ErrNeedDeletedCond delete needs less one condition error
	ErrNeedDeletedCond = errors.New("Delete action needs at least one condition")
	// ErrNotImplemented not implemented
	ErrNotImplemented = errors.New("Not implemented")

	// ErrConditionType condition type unsupported
	ErrConditionType = errors.New("Unsupported condition type")
	// ErrNeedMoreArguments need more arguments
	ErrNeedMoreArguments = errors.New("Need more sql arguments")
	// ErrUnSupportedSQLType parameter of SQL is not supported
	ErrUnSupportedSQLType = errors.New("Unsupported sql type")
)
View Source
var ErrNoElementsOnSlice = errors.New("No element on slice when insert")

ErrNoElementsOnSlice represents an error there is no element when insert

Functions

func Bool

func Bool(i interface{}) bool

false: "", 0, false, off

func Bytes

func Bytes(i interface{}) []byte

func ConvertToBoundSQL

func ConvertToBoundSQL(sql string, args []interface{}) (string, error)

ConvertToBoundSQL will convert SQL and args to a bound SQL

func DecodeToString

func DecodeToString(b []byte) string

func Encode

func Encode(vs ...interface{}) []byte

func EncodeBool

func EncodeBool(b bool) []byte

func EncodeFloat32

func EncodeFloat32(f float32) []byte

func EncodeFloat64

func EncodeFloat64(f float64) []byte

func EncodeInt

func EncodeInt(i int) []byte

func EncodeInt16

func EncodeInt16(i int16) []byte

func EncodeInt32

func EncodeInt32(i int32) []byte

func EncodeInt64

func EncodeInt64(i int64) []byte

func EncodeInt8

func EncodeInt8(i int8) []byte

func EncodeString

func EncodeString(s string) []byte

func EncodeUint

func EncodeUint(i uint) []byte

func EncodeUint16

func EncodeUint16(i uint16) []byte

func EncodeUint32

func EncodeUint32(i uint32) []byte

func EncodeUint64

func EncodeUint64(i uint64) []byte

func EncodeUint8

func EncodeUint8(i uint8) []byte

func Float32

func Float32(i interface{}) float32

func Float64

func Float64(i interface{}) float64

func Int

func Int(i interface{}) int

func Int16

func Int16(i interface{}) int16

func Int32

func Int32(i interface{}) int32

func Int64

func Int64(i interface{}) int64

func Int8

func Int8(i interface{}) int8

func IsNumeric

func IsNumeric(s string) bool

func JSONString

func JSONString(v interface{}, IndentJSON bool) (string, error)

func NewDataset

func NewDataset(headers []string) *tablib.Dataset

NewDataset creates a new Dataset.

func NewDatasetWithData

func NewDatasetWithData(headers []string, data interface{}, mustMatch bool) (*tablib.Dataset, error)

NewDatasetWithData creates a new Dataset.

func NewMemoryContextCache

func NewMemoryContextCache() memoryContextCache

NewMemoryContextCache return memoryContextCache

func PKCS5Padding

func PKCS5Padding(ciphertext []byte, blockSize int) []byte

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

func StrToTime

func StrToTime(str string, format string, TZLocation ...*time.Location) (time.Time, error)

func String

func String(i interface{}) string

func Strings

func Strings(i interface{}) []string

func Time

func Time(i interface{}, format string, TZLocation ...*time.Location) time.Time

func TimeDuration

func TimeDuration(i interface{}) time.Duration

func Uint

func Uint(i interface{}) uint

func Uint16

func Uint16(i interface{}) uint16

func Uint32

func Uint32(i interface{}) uint32

func Uint64

func Uint64(i interface{}) uint64

func Uint8

func Uint8(i interface{}) uint8

func ZeroPadding

func ZeroPadding(ciphertext []byte, blockSize int) []byte

func ZeroUnPadding

func ZeroUnPadding(origData []byte) []byte

Types

type AesEncrypt

type AesEncrypt struct {
	PubKey string
}

func (*AesEncrypt) Decrypt

func (this *AesEncrypt) Decrypt(src []byte) (decrypted []byte, err error)

解密字符串

func (*AesEncrypt) Encrypt

func (this *AesEncrypt) Encrypt(strMesg string) ([]byte, error)

加密字符串

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

type AfterSetProcessor interface {
	AfterSet(string, Cell)
}

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

type BeforeSetProcessor interface {
	BeforeSet(string, Cell)
}

BeforeSetProcessor executed before data set to the struct fields

type BeforeUpdateProcessor

type BeforeUpdateProcessor interface {
	BeforeUpdate()
}

BeforeUpdateProcessor executed before an object is updated

type Cell

type Cell *interface{}

Cell cell is a result of one column field

type Cipher

type Cipher interface {
	Encrypt(strMsg string) ([]byte, error)
	Decrypt(src []byte) (decrypted []byte, err error)
}

type ContextCache

type ContextCache interface {
	// Put puts value into cache with key.
	Put(key string, val interface{})
	// Get gets cached value by given key.
	Get(key string) interface{}
}

ContextCache is the interface that operates the cache data.

type Databook

type Databook struct {
	XDatabook *tablib.Databook
}

func NewDatabook

func NewDatabook() *Databook

func NewDatabookWithData

func NewDatabookWithData(sheetName map[string]string, data interface{}, mustMatch bool, headers ...map[string][]string) (*Databook, error)

func (*Databook) AddSheet

func (databook *Databook) AddSheet(title string, data interface{}, mustMatch bool, headers ...[]string) error

func (*Databook) HTML

func (databook *Databook) HTML() *tablib.Exportable

func (*Databook) JSON

func (databook *Databook) JSON() (*tablib.Exportable, error)

func (*Databook) SaveAsHTML

func (databook *Databook) SaveAsHTML(filename string, perm os.FileMode) error

func (*Databook) SaveAsJSON

func (databook *Databook) SaveAsJSON(filename string, perm os.FileMode) error

func (*Databook) SaveAsXLSX

func (databook *Databook) SaveAsXLSX(filename string, perm os.FileMode) error

func (*Databook) SaveAsXML

func (databook *Databook) SaveAsXML(filename string, perm os.FileMode) error

func (*Databook) SaveAsYAML

func (databook *Databook) SaveAsYAML(filename string, perm os.FileMode) error

func (*Databook) Sheet

func (databook *Databook) Sheet(title string) tablib.Sheet

func (*Databook) Sheets

func (databook *Databook) Sheets() map[string]tablib.Sheet

func (*Databook) Size

func (databook *Databook) Size() int

func (*Databook) Wipe

func (databook *Databook) Wipe()

func (*Databook) XLSX

func (databook *Databook) XLSX() (*tablib.Exportable, error)

func (*Databook) XML

func (databook *Databook) XML() (*tablib.Exportable, error)

func (*Databook) YAML

func (databook *Databook) YAML() (*tablib.Exportable, error)

type DesEncrypt

type DesEncrypt struct {
	PubKey string
}

func (*DesEncrypt) Decrypt

func (this *DesEncrypt) Decrypt(crypted []byte) (decrypted []byte, err error)

func (*DesEncrypt) Encrypt

func (this *DesEncrypt) Encrypt(strMesg string) ([]byte, error)

type Engine

type Engine struct {
	SqlMap      SqlMap
	SqlTemplate SqlTemplate

	TZLocation *time.Location // The timezone of the application
	DatabaseTZ *time.Location // The timezone of the database
	// contains filtered or unexported fields
}

Engine is the major struct of xorm, it means a database manager. Commonly, an application only need one engine

func NewDB

func NewDB(driverName string, dataSourceName string) (*Engine, error)

func NewEngine

func NewEngine(driverName string, dataSourceName string) (*Engine, error)

NewEngine new a db manager according to the parameter. Currently support four drivers

func NewEngineWithDialectAndDB

func NewEngineWithDialectAndDB(driverName, dataSourceName string, dialect dialects.Dialect, db *core.DB) (*Engine, error)

NewEngineWithDialectAndDB new a db manager according to the parameter. If you do not want to use your own dialect or db, please use NewEngine. For creating dialect, you can call dialects.OpenDialect. And, for creating db, you can call core.Open or core.FromDB.

func NewEngineWithParams

func NewEngineWithParams(driverName string, dataSourceName string, params map[string]string) (*Engine, error)

NewEngineWithParams new a db manager with params. The params will be passed to dialects.

func NewMSSQL

func NewMSSQL(driverName string, dataSourceName string) (*Engine, error)

func NewMySQL

func NewMySQL(driverName string, dataSourceName string) (*Engine, error)

func NewOracle

func NewOracle(driverName string, dataSourceName string) (*Engine, error)

func NewPostgreSQL

func NewPostgreSQL(dataSourceName string) (*Engine, error)

func NewSqlite3

func NewSqlite3(dataSourceName string) (*Engine, error)

func (*Engine) AddHook

func (engine *Engine) AddHook(hook contexts.Hook)

func (*Engine) AddSql

func (engine *Engine) AddSql(key string, sql string)

func (*Engine) AddSqlTemplate

func (engine *Engine) AddSqlTemplate(key string, sqlTemplateStr string) error

func (*Engine) After

func (engine *Engine) After(closures func(interface{})) *Session

After apply after insert Processor, affected bean is passed to closure arg

func (*Engine) Alias

func (engine *Engine) Alias(alias string) *Session

Alias set the table alias

func (*Engine) AllCols

func (engine *Engine) AllCols() *Session

AllCols indicates that all columns should be use

func (*Engine) Asc

func (engine *Engine) Asc(colNames ...string) *Session

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) AutoIncrStr

func (engine *Engine) AutoIncrStr() string

AutoIncrStr Database's autoincrement statement

func (*Engine) BatchAddSql

func (engine *Engine) BatchAddSql(sqlStrMap map[string]string)

func (*Engine) BatchAddSqlTemplate

func (engine *Engine) BatchAddSqlTemplate(key string, sqlTemplateStrMap map[string]string) error

func (*Engine) BatchLoadSqlMap

func (engine *Engine) BatchLoadSqlMap(filepathSlice []string) error

func (*Engine) BatchLoadSqlTemplate

func (engine *Engine) BatchLoadSqlTemplate(filepathSlice []string) error

func (*Engine) BatchReloadSqlMap

func (engine *Engine) BatchReloadSqlMap(filepathSlice []string) error

func (*Engine) BatchReloadSqlTemplate

func (engine *Engine) BatchReloadSqlTemplate(filepathSlice []string) error

func (*Engine) BatchRemoveSql

func (engine *Engine) BatchRemoveSql(key []string)

func (*Engine) BatchRemoveSqlTemplate

func (engine *Engine) BatchRemoveSqlTemplate(key []string)

func (*Engine) BatchUpdateSql

func (engine *Engine) BatchUpdateSql(sqlStrMap map[string]string)

func (*Engine) BatchUpdateSqlTemplate

func (engine *Engine) BatchUpdateSqlTemplate(key string, sqlTemplateStrMap map[string]string) error

func (*Engine) Before

func (engine *Engine) Before(closures func(interface{})) *Session

Before apply before Processor, affected bean is passed to closure arg

func (*Engine) BufferSize

func (engine *Engine) BufferSize(size int) *Session

BufferSize sets buffer size for iterate

func (*Engine) Cascade

func (engine *Engine) Cascade(trueOrFalse ...bool) *Session

Cascade use cascade or not

func (*Engine) Charset

func (engine *Engine) Charset(charset string) *Session

Charset set charset when create table, only support mysql now

func (*Engine) ClearCache

func (engine *Engine) ClearCache(beans ...interface{}) error

ClearCache if enabled cache, clear some tables' cache

func (*Engine) ClearCacheBean

func (engine *Engine) ClearCacheBean(bean interface{}, id string) error

ClearCacheBean if enabled cache, clear the cache bean

func (*Engine) ClearSqlMapCipher

func (engine *Engine) ClearSqlMapCipher()

func (*Engine) Clone

func (engine *Engine) Clone() (*Engine, error)

Clone clone an engine

func (*Engine) Close

func (engine *Engine) Close() error

Close the engine

func (*Engine) Cols

func (engine *Engine) Cols(columns ...string) *Session

Cols only use the parameters as select or update columns

func (*Engine) Context

func (engine *Engine) Context(ctx context.Context) *Session

ContextHook creates a session with the context

func (*Engine) Count

func (engine *Engine) Count(bean ...interface{}) (int64, error)

Count counts the records. bean's non-empty fields are conditions.

func (*Engine) CreateIndexes

func (engine *Engine) CreateIndexes(bean interface{}) error

CreateIndexes create indexes

func (*Engine) CreateTables

func (engine *Engine) CreateTables(beans ...interface{}) error

CreateTables create tabls according bean

func (*Engine) CreateUniques

func (engine *Engine) CreateUniques(bean interface{}) error

CreateUniques create uniques

func (*Engine) DB

func (engine *Engine) DB() *core.DB

DB return the wrapper of sql.DB

func (*Engine) DBMetas

func (engine *Engine) DBMetas() ([]*schemas.Table, error)

DBMetas Retrieve all tables, columns, indexes' informations from database.

func (*Engine) DataSourceName

func (engine *Engine) DataSourceName() string

DataSourceName return the current connection string

func (*Engine) Decr

func (engine *Engine) Decr(column string, args ...interface{}) *Session

Decr provides a update string like "column = column - ?"

func (*Engine) Delete

func (engine *Engine) Delete(bean interface{}) (int64, error)

Delete records, bean's non-empty fields are conditions

func (*Engine) Desc

func (engine *Engine) Desc(colNames ...string) *Session

Desc will generate "ORDER BY column1 DESC, column2 DESC"

func (*Engine) Dialect

func (engine *Engine) Dialect() dialects.Dialect

Dialect return database dialect

func (*Engine) Distinct

func (engine *Engine) Distinct(columns ...string) *Session

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) DriverName

func (engine *Engine) DriverName() string

DriverName return the current sql driver's name

func (*Engine) DropIndexes

func (engine *Engine) DropIndexes(bean interface{}) error

DropIndexes drop indexes of a table

func (*Engine) DropTables

func (engine *Engine) DropTables(beans ...interface{}) error

DropTables drop specify tables

func (*Engine) DumpAll

func (engine *Engine) DumpAll(w io.Writer, tp ...schemas.DBType) error

DumpAll dump database all table structs and data to w

func (*Engine) DumpAllToFile

func (engine *Engine) DumpAllToFile(fp string, tp ...schemas.DBType) error

DumpAllToFile dump database all table structs and data to a file

func (*Engine) DumpTables

func (engine *Engine) DumpTables(tables []*schemas.Table, w io.Writer, tp ...schemas.DBType) error

DumpTables dump specify tables to io.Writer

func (*Engine) DumpTablesToFile

func (engine *Engine) DumpTablesToFile(tables []*schemas.Table, fp string, tp ...schemas.DBType) error

DumpTablesToFile dump specified tables to SQL file.

func (*Engine) EnableSessionID

func (engine *Engine) EnableSessionID(enable bool)

EnableSessionID if enable session id

func (*Engine) Exec

func (engine *Engine) Exec(sqlOrArgs ...interface{}) (sql.Result, error)

Exec raw sql

func (*Engine) Exist

func (engine *Engine) Exist(bean ...interface{}) (bool, error)

Exist returns true if the record exist otherwise return false

func (*Engine) Find

func (engine *Engine) Find(beans interface{}, condiBeans ...interface{}) error

Find retrieve records from table, condiBeans's non-empty fields are conditions. beans could be []Struct, []*Struct, map[int64]Struct map[int64]*Struct

func (*Engine) FindAndCount

func (engine *Engine) FindAndCount(rowsSlicePtr interface{}, condiBean ...interface{}) (int64, error)

FindAndCount find the results and also return the counts

func (*Engine) Get

func (engine *Engine) Get(bean interface{}) (bool, error)

Get retrieve one record from table, bean's non-empty fields are conditions

func (*Engine) GetCacher

func (engine *Engine) GetCacher(tableName string) caches.Cacher

GetCacher returns the cachher of the special table

func (*Engine) GetColumnMapper

func (engine *Engine) GetColumnMapper() names.Mapper

GetColumnMapper returns the column name mapper

func (*Engine) GetDefaultCacher

func (engine *Engine) GetDefaultCacher() caches.Cacher

GetDefaultCacher returns the default cacher

func (*Engine) GetFirst

func (engine *Engine) GetFirst(bean interface{}) *ResultBean

Get retrieve one record from table, bean's non-empty fields are conditions

func (*Engine) GetSql

func (engine *Engine) GetSql(key string) string

func (*Engine) GetSqlMap

func (engine *Engine) GetSqlMap(keys ...interface{}) map[string]string

func (*Engine) GetTZDatabase

func (engine *Engine) GetTZDatabase() *time.Location

GetTZDatabase returns time zone of the database

func (*Engine) GetTZLocation

func (engine *Engine) GetTZLocation() *time.Location

GetTZLocation returns time zone of the application

func (*Engine) GetTableMapper

func (engine *Engine) GetTableMapper() names.Mapper

GetTableMapper returns the table name mapper

func (*Engine) GroupBy

func (engine *Engine) GroupBy(keys string) *Session

GroupBy generate group by statement

func (*Engine) Having

func (engine *Engine) Having(conditions string) *Session

Having generate having statement

func (*Engine) ID

func (engine *Engine) ID(id interface{}) *Session

ID method provoide a condition as (id) = ?

func (*Engine) Import

func (engine *Engine) Import(r io.Reader) ([]sql.Result, error)

Import SQL DDL from io.Reader

func (*Engine) ImportFile

func (engine *Engine) ImportFile(ddlPath string) ([]sql.Result, error)

ImportFile SQL DDL file

func (*Engine) In

func (engine *Engine) In(column string, args ...interface{}) *Session

In will generate "column IN (?, ?)"

func (*Engine) Incr

func (engine *Engine) Incr(column string, args ...interface{}) *Session

Incr provides a update string like "column = column + ?"

func (*Engine) Insert

func (engine *Engine) Insert(beans ...interface{}) (int64, error)

Insert one or more records

func (*Engine) InsertOne

func (engine *Engine) InsertOne(bean interface{}) (int64, error)

InsertOne insert only one record

func (*Engine) IsTableEmpty

func (engine *Engine) IsTableEmpty(bean interface{}) (bool, error)

IsTableEmpty if a table has any reocrd

func (*Engine) IsTableExist

func (engine *Engine) IsTableExist(beanOrTableName interface{}) (bool, error)

IsTableExist if a table is exist

func (*Engine) Iterate

func (engine *Engine) Iterate(bean interface{}, fun IterFunc) error

Iterate record by record handle records from table, bean's non-empty fields are conditions.

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) Limit

func (engine *Engine) Limit(limit int, start ...int) *Session

Limit will generate "LIMIT start, limit"

func (*Engine) LoadSqlMap

func (engine *Engine) LoadSqlMap(filepath string) error

func (*Engine) LoadSqlTemplate

func (engine *Engine) LoadSqlTemplate(filepath string) error

func (*Engine) Logger

func (engine *Engine) Logger() log.ContextLogger

Logger return the logger interface

func (*Engine) MapCacher

func (engine *Engine) MapCacher(bean interface{}, cacher caches.Cacher) error

MapCacher Set a table use a special cacher

func (*Engine) MustCols

func (engine *Engine) MustCols(columns ...string) *Session

MustCols specify some columns must use even if they are empty

func (*Engine) NewDB

func (engine *Engine) NewDB() (*core.DB, error)

NewDB provides an interface to operate database directly

func (*Engine) NewSession

func (engine *Engine) NewSession() *Session

NewSession New a session

func (*Engine) NoAutoCondition

func (engine *Engine) NoAutoCondition(no ...bool) *Session

NoAutoCondition disable auto generate Where condition from bean or not

func (*Engine) NoAutoTime

func (engine *Engine) NoAutoTime() *Session

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) NoCache

func (engine *Engine) NoCache() *Session

NoCache If you has set default cacher, and you want temporilly stop use cache, you can use NoCache()

func (*Engine) NoCascade

func (engine *Engine) NoCascade() *Session

NoCascade If you do not want to auto cascade load object

func (*Engine) NotIn

func (engine *Engine) NotIn(column string, args ...interface{}) *Session

NotIn will generate "column NOT IN (?, ?)"

func (*Engine) Nullable

func (engine *Engine) Nullable(columns ...string) *Session

Nullable set null when column is zero-value and nullable for update

func (*Engine) Omit

func (engine *Engine) Omit(columns ...string) *Session

Omit only not use the parameters as select or update columns

func (*Engine) OrderBy

func (engine *Engine) OrderBy(order string) *Session

OrderBy will generate "ORDER BY order"

func (*Engine) Ping

func (engine *Engine) Ping() error

Ping tests if database is alive

func (*Engine) PingContext

func (engine *Engine) PingContext(ctx context.Context) error

PingContext tests if database is alive

func (*Engine) Prepare

func (engine *Engine) Prepare() *Session

Prepare enables prepare statement

func (*Engine) QueryBytes

func (engine *Engine) QueryBytes(sqlOrArgs ...interface{}) (resultsSlice []map[string][]byte, err error)

Query a raw sql and return records as []map[string][]byte

func (*Engine) QueryInterface

func (engine *Engine) QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error)

QueryInterface runs a raw sql and return records as []map[string]interface{}

func (*Engine) QueryResult

func (engine *Engine) QueryResult(sqlOrArgs ...interface{}) (result *ResultValue)

Query a raw sql and return records as Result

func (*Engine) QueryString

func (engine *Engine) QueryString(sqlOrArgs ...interface{}) ([]map[string]string, error)

QueryString runs a raw sql and return records as []map[string]string

func (*Engine) QueryValue

func (engine *Engine) QueryValue(sqlOrArgs ...interface{}) (resultsSlice []map[string]Value, err error)

Query a raw sql and return records as []map[string]Value

func (*Engine) Quote

func (engine *Engine) Quote(value string) string

Quote Use QuoteStr quote the string sql

func (*Engine) QuoteTo

func (engine *Engine) QuoteTo(buf *strings.Builder, value string)

QuoteTo quotes string and writes into the buffer

func (*Engine) RegisterSqlMap

func (engine *Engine) RegisterSqlMap(sqlm SqlM, Cipher ...Cipher) error

func (*Engine) RegisterSqlTemplate

func (engine *Engine) RegisterSqlTemplate(sqlt SqlTemplate, Cipher ...Cipher) error

func (*Engine) ReloadSqlMap

func (engine *Engine) ReloadSqlMap(filepath string) error

func (*Engine) ReloadSqlTemplate

func (engine *Engine) ReloadSqlTemplate(filepath string) error

func (*Engine) RemoveSql

func (engine *Engine) RemoveSql(key string)

func (*Engine) RemoveSqlTemplate

func (engine *Engine) RemoveSqlTemplate(key string)

func (*Engine) Rows

func (engine *Engine) Rows(bean interface{}) (*Rows, error)

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 (*Engine) SQL

func (engine *Engine) SQL(query interface{}, args ...interface{}) *Session

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) SQLType

func (engine *Engine) SQLType(c *schemas.Column) string

SQLType A simple wrapper to dialect's core.SqlType method

func (*Engine) Search

func (engine *Engine) Search(beans interface{}, condiBeans ...interface{}) *ResultStructs

func (*Engine) Select

func (engine *Engine) Select(str string) *Session

Select customerize your select columns or contents

func (*Engine) SetCacher

func (engine *Engine) SetCacher(tableName string, cacher caches.Cacher)

SetCacher sets cacher for the table

func (*Engine) SetColumnMapper

func (engine *Engine) SetColumnMapper(mapper names.Mapper)

SetColumnMapper set the column name mapping rule

func (*Engine) SetConnMaxLifetime

func (engine *Engine) SetConnMaxLifetime(d time.Duration)

SetConnMaxLifetime sets the maximum amount of time a connection may be reused.

func (*Engine) SetDefaultCacher

func (engine *Engine) SetDefaultCacher(cacher caches.Cacher)

SetDefaultCacher set the default cacher. Xorm's default not enable cacher.

func (*Engine) SetDefaultContext

func (engine *Engine) SetDefaultContext(ctx context.Context)

SetDefaultContext set the default context

func (*Engine) SetDisableGlobalCache

func (engine *Engine) SetDisableGlobalCache(disable bool)

SetDisableGlobalCache disable global cache or not

func (*Engine) SetExpr

func (engine *Engine) SetExpr(column string, expression interface{}) *Session

SetExpr provides a update string like "column = {expression}"

func (*Engine) SetLogLevel

func (engine *Engine) SetLogLevel(level log.LogLevel)

SetLogLevel sets the logger level

func (*Engine) SetLogger

func (engine *Engine) SetLogger(logger interface{})

SetLogger set the new logger

func (*Engine) SetMapper

func (engine *Engine) SetMapper(mapper names.Mapper)

SetMapper set the name mapping rules

func (*Engine) SetMaxIdleConns

func (engine *Engine) SetMaxIdleConns(conns int)

SetMaxIdleConns set the max idle connections on pool, default is 2

func (*Engine) SetMaxOpenConns

func (engine *Engine) SetMaxOpenConns(conns int)

SetMaxOpenConns is only available for go 1.2+

func (*Engine) SetQuotePolicy

func (engine *Engine) SetQuotePolicy(quotePolicy dialects.QuotePolicy)

SetQuotePolicy sets the special quote policy

func (*Engine) SetSchema

func (engine *Engine) SetSchema(schema string)

SetSchema sets the schema of database

func (*Engine) SetSqlMapCipher

func (engine *Engine) SetSqlMapCipher(cipher Cipher)

func (*Engine) SetSqlMapRootDir

func (engine *Engine) SetSqlMapRootDir(sqlMapRootDir string) *Engine

func (*Engine) SetTZDatabase

func (engine *Engine) SetTZDatabase(tz *time.Location)

SetTZDatabase sets time zone of the database

func (*Engine) SetTZLocation

func (engine *Engine) SetTZLocation(tz *time.Location)

SetTZLocation sets time zone of the application

func (*Engine) SetTableMapper

func (engine *Engine) SetTableMapper(mapper names.Mapper)

SetTableMapper set the table name mapping rule

func (*Engine) ShowSQL

func (engine *Engine) ShowSQL(show ...bool)

ShowSQL show SQL statement or not on logger if log level is great than INFO

func (*Engine) SqlMapClient

func (engine *Engine) SqlMapClient(sqlTagName string, args ...interface{}) *Session

func (*Engine) SqlMapsClient

func (engine *Engine) SqlMapsClient(sqlkeys interface{}, parmas ...interface{}) *SqlMapsExecutor

func (*Engine) SqlTemplateClient

func (engine *Engine) SqlTemplateClient(sqlTagName string, args ...interface{}) *Session

func (*Engine) SqlTemplatesClient

func (engine *Engine) SqlTemplatesClient(sqlkeys interface{}, parmas ...interface{}) *SqlTemplatesExecutor

func (*Engine) Sqls

func (engine *Engine) Sqls(sqls interface{}, parmas ...interface{}) *SqlsExecutor

func (*Engine) StartFSWatcher

func (engine *Engine) StartFSWatcher() error

start filesystem watcher

func (*Engine) StopFSWatcher

func (engine *Engine) StopFSWatcher() error

stop filesystem watcher

func (*Engine) StoreEngine

func (engine *Engine) StoreEngine(storeEngine string) *Session

StoreEngine set store engine when create table, only support mysql now

func (*Engine) Sum

func (engine *Engine) Sum(bean interface{}, colName string) (float64, error)

Sum sum the records by some column. bean's non-empty fields are conditions.

func (*Engine) SumInt

func (engine *Engine) SumInt(bean interface{}, colName string) (int64, error)

SumInt sum the records by some column. bean's non-empty fields are conditions.

func (*Engine) Sums

func (engine *Engine) Sums(bean interface{}, colNames ...string) ([]float64, error)

Sums sum the records by some columns. bean's non-empty fields are conditions.

func (*Engine) SumsInt

func (engine *Engine) SumsInt(bean interface{}, colNames ...string) ([]int64, error)

SumsInt like Sums but return slice of int64 instead of float64.

func (*Engine) Sync

func (engine *Engine) Sync(beans ...interface{}) error

Sync the new struct changes to database, this method will automatically add table, column, index, unique. but will not delete or change anything. If you change some field, you should change the database manually.

func (*Engine) Sync2

func (engine *Engine) Sync2(beans ...interface{}) error

Sync2 synchronize structs to database tables

func (*Engine) Table

func (engine *Engine) Table(tableNameOrBean interface{}) *Session

Table temporarily change the Get, Find, Update's table

func (*Engine) TableInfo

func (engine *Engine) TableInfo(bean interface{}) (*schemas.Table, error)

TableInfo get table info according to bean's content

func (*Engine) TableName

func (engine *Engine) TableName(bean interface{}, includeSchema ...bool) string

TableName returns table name with schema prefix if has

func (*Engine) Transaction

func (engine *Engine) Transaction(f func(*Session) (interface{}, error)) (interface{}, error)

Transaction Execute sql wrapped in a transaction(abbr as tx), tx will automatic commit if no errors occurred

func (*Engine) UnMapType

func (engine *Engine) UnMapType(t reflect.Type)

UnMapType remove table from tables cache

func (*Engine) Unscoped

func (engine *Engine) Unscoped() *Session

Unscoped always disable struct tag "deleted"

func (*Engine) Update

func (engine *Engine) Update(bean interface{}, condiBeans ...interface{}) (int64, error)

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 (*Engine) UpdateSql

func (engine *Engine) UpdateSql(key string, sql string)

func (*Engine) UpdateSqlTemplate

func (engine *Engine) UpdateSqlTemplate(key string, sqlTemplateStr string) error

func (*Engine) UseBool

func (engine *Engine) UseBool(columns ...string) *Session

UseBool xorm 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

func (*Engine) Where

func (engine *Engine) Where(query interface{}, args ...interface{}) *Session

Where method provide a condition query

type EngineGroup

type EngineGroup struct {
	*Engine
	// contains filtered or unexported fields
}

EngineGroup defines an engine group

func NewEngineGroup

func NewEngineGroup(args1 interface{}, args2 interface{}, policies ...GroupPolicy) (*EngineGroup, error)

NewEngineGroup creates a new engine group

func (*EngineGroup) AddHook

func (eg *EngineGroup) AddHook(hook contexts.Hook)

func (*EngineGroup) Close

func (eg *EngineGroup) Close() error

Close the engine

func (*EngineGroup) Context

func (eg *EngineGroup) Context(ctx context.Context) *Session

ContextHook returned a group session

func (*EngineGroup) Main

func (eg *EngineGroup) Main() *Engine

Main returns the main engine

func (*EngineGroup) NewSession

func (eg *EngineGroup) NewSession() *Session

NewSession returned a group session

func (*EngineGroup) Ping

func (eg *EngineGroup) Ping() error

Ping tests if database is alive

func (*EngineGroup) RegisterSqlMap

func (eg *EngineGroup) RegisterSqlMap(sqlm SqlM, Cipher ...Cipher) error

func (*EngineGroup) RegisterSqlTemplate

func (eg *EngineGroup) RegisterSqlTemplate(sqlt SqlTemplate, Cipher ...Cipher) error

func (*EngineGroup) SetColumnMapper

func (eg *EngineGroup) SetColumnMapper(mapper names.Mapper)

SetColumnMapper set the column name mapping rule

func (*EngineGroup) SetConnMaxLifetime

func (eg *EngineGroup) SetConnMaxLifetime(d time.Duration)

SetConnMaxLifetime sets the maximum amount of time a connection may be reused.

func (*EngineGroup) SetDefaultCacher

func (eg *EngineGroup) SetDefaultCacher(cacher caches.Cacher)

SetDefaultCacher set the default cacher

func (*EngineGroup) SetLogLevel

func (eg *EngineGroup) SetLogLevel(level log.LogLevel)

SetLogLevel sets the logger level

func (*EngineGroup) SetLogger

func (eg *EngineGroup) SetLogger(logger interface{})

SetLogger set the new logger

func (*EngineGroup) SetMapper

func (eg *EngineGroup) SetMapper(mapper names.Mapper)

SetMapper set the name mapping rules

func (*EngineGroup) SetMaxIdleConns

func (eg *EngineGroup) SetMaxIdleConns(conns int)

SetMaxIdleConns set the max idle connections on pool, default is 2

func (*EngineGroup) SetMaxOpenConns

func (eg *EngineGroup) SetMaxOpenConns(conns int)

SetMaxOpenConns is only available for go 1.2+

func (*EngineGroup) SetPolicy

func (eg *EngineGroup) SetPolicy(policy GroupPolicy) *EngineGroup

SetPolicy set the group policy

func (*EngineGroup) SetQuotePolicy

func (eg *EngineGroup) SetQuotePolicy(quotePolicy dialects.QuotePolicy)

SetQuotePolicy sets the special quote policy

func (*EngineGroup) SetTableMapper

func (eg *EngineGroup) SetTableMapper(mapper names.Mapper)

SetTableMapper set the table name mapping rule

func (*EngineGroup) ShowSQL

func (eg *EngineGroup) ShowSQL(show ...bool)

ShowSQL show SQL statement or not on logger if log level is great than INFO

func (*EngineGroup) Subordinate

func (eg *EngineGroup) Subordinate() *Engine

Subordinate returns one of the physical databases which is a subordinate according the policy

func (*EngineGroup) Subordinates

func (eg *EngineGroup) Subordinates() []*Engine

Subordinates returns all the subordinates

type EngineInterface

type EngineInterface interface {
	Interface

	Before(func(interface{})) *Session
	Charset(charset string) *Session
	ClearCache(...interface{}) error
	Context(context.Context) *Session
	CreateTables(...interface{}) error
	DBMetas() ([]*schemas.Table, error)
	Dialect() dialects.Dialect
	DriverName() string
	DropTables(...interface{}) error
	DumpAllToFile(fp string, tp ...schemas.DBType) error
	GetCacher(string) caches.Cacher
	GetColumnMapper() names.Mapper
	GetDefaultCacher() caches.Cacher
	GetTableMapper() names.Mapper
	GetTZDatabase() *time.Location
	GetTZLocation() *time.Location
	ImportFile(fp string) ([]sql.Result, error)
	MapCacher(interface{}, caches.Cacher) error
	NewSession() *Session
	NoAutoTime() *Session
	Quote(string) string
	SetCacher(string, caches.Cacher)
	SetConnMaxLifetime(time.Duration)
	SetColumnMapper(names.Mapper)
	SetDefaultCacher(caches.Cacher)
	SetLogger(logger interface{})
	SetLogLevel(log.LogLevel)
	SetMapper(names.Mapper)
	SetMaxOpenConns(int)
	SetMaxIdleConns(int)
	SetQuotePolicy(dialects.QuotePolicy)
	SetSchema(string)
	SetTableMapper(names.Mapper)
	SetTZDatabase(tz *time.Location)
	SetTZLocation(tz *time.Location)
	AddHook(hook contexts.Hook)
	ShowSQL(show ...bool)
	Sync(...interface{}) error
	Sync2(...interface{}) error
	StoreEngine(storeEngine string) *Session
	TableInfo(bean interface{}) (*schemas.Table, error)
	TableName(interface{}, ...bool) string
	UnMapType(reflect.Type)
	EnableSessionID(bool)
}

EngineInterface defines the interface which Engine, EngineGroup will implementate.

type ErrFieldIsNotExist

type ErrFieldIsNotExist struct {
	FieldName string
	TableName string
}

ErrFieldIsNotExist columns does not exist

func (ErrFieldIsNotExist) Error

func (e ErrFieldIsNotExist) Error() string

type ErrFieldIsNotValid

type ErrFieldIsNotValid struct {
	FieldName string
	TableName string
}

ErrFieldIsNotValid is not valid

func (ErrFieldIsNotValid) Error

func (e ErrFieldIsNotValid) Error() string

type FuncMap

type FuncMap map[string]interface{}

type GroupPolicy

type GroupPolicy interface {
	Subordinate(*EngineGroup) *Engine
}

GroupPolicy is be used by chosing the current subordinate from subordinates

type GroupPolicyHandler

type GroupPolicyHandler func(*EngineGroup) *Engine

GroupPolicyHandler should be used when a function is a GroupPolicy

func LeastConnPolicy

func LeastConnPolicy() GroupPolicyHandler

LeastConnPolicy implements GroupPolicy, every time will get the least connections subordinate

func RandomPolicy

func RandomPolicy() GroupPolicyHandler

RandomPolicy implmentes randomly chose the subordinate of subordinates

func RoundRobinPolicy

func RoundRobinPolicy() GroupPolicyHandler

RoundRobinPolicy returns a group policy handler

func WeightRandomPolicy

func WeightRandomPolicy(weights []int) GroupPolicyHandler

WeightRandomPolicy implmentes randomly chose the subordinate of subordinates

func WeightRoundRobinPolicy

func WeightRoundRobinPolicy(weights []int) GroupPolicyHandler

WeightRoundRobinPolicy returns a group policy handler

func (GroupPolicyHandler) Subordinate

func (h GroupPolicyHandler) Subordinate(eg *EngineGroup) *Engine

Subordinate implements the chosen of subordinates

type HTMLTemplate

type HTMLTemplate struct {
	SqlTemplateRootDir string
	Template           map[string]*template.Template

	Capacity uint
	Cipher   Cipher
	Type     int
	Funcs    map[string]FuncMap
	// contains filtered or unexported fields
}

func Default

func Default(directory, extension string) *HTMLTemplate

func (*HTMLTemplate) AddSqlTemplate

func (sqlTemplate *HTMLTemplate) AddSqlTemplate(key string, sqlTemplateStr string) error

func (*HTMLTemplate) BatchAddSqlTemplate

func (sqlTemplate *HTMLTemplate) BatchAddSqlTemplate(key string, sqlTemplateStrMap map[string]string) error

func (*HTMLTemplate) BatchLoadSqlTemplate

func (sqlTemplate *HTMLTemplate) BatchLoadSqlTemplate(filepathSlice []string) error

func (*HTMLTemplate) BatchReloadSqlTemplate

func (sqlTemplate *HTMLTemplate) BatchReloadSqlTemplate(filepathSlice []string) error

func (*HTMLTemplate) BatchRemoveSqlTemplate

func (sqlTemplate *HTMLTemplate) BatchRemoveSqlTemplate(key []string)

func (*HTMLTemplate) BatchUpdateSqlTemplate

func (sqlTemplate *HTMLTemplate) BatchUpdateSqlTemplate(key string, sqlTemplateStrMap map[string]string) error

func (*HTMLTemplate) Execute

func (sqlTemplate *HTMLTemplate) Execute(key string, args ...interface{}) (string, error)

func (*HTMLTemplate) Extension

func (sqlTemplate *HTMLTemplate) Extension() string

func (*HTMLTemplate) GetSqlTemplate

func (sqlTemplate *HTMLTemplate) GetSqlTemplate(key string) *template.Template

func (*HTMLTemplate) GetSqlTemplates

func (sqlTemplate *HTMLTemplate) GetSqlTemplates(keys ...interface{}) map[string]*template.Template

func (*HTMLTemplate) LoadSqlTemplate

func (sqlTemplate *HTMLTemplate) LoadSqlTemplate(filepath string) error

-------------------------------------------------------------------------------------------------------------

func (*HTMLTemplate) ReadTemplate

func (sqlTemplate *HTMLTemplate) ReadTemplate(filepath string) ([]byte, error)

func (*HTMLTemplate) ReloadSqlTemplate

func (sqlTemplate *HTMLTemplate) ReloadSqlTemplate(filepath string) error

func (*HTMLTemplate) RemoveSqlTemplate

func (sqlTemplate *HTMLTemplate) RemoveSqlTemplate(key string)

func (*HTMLTemplate) RootDir

func (sqlTemplate *HTMLTemplate) RootDir() string

func (*HTMLTemplate) SetFuncs

func (sqlTemplate *HTMLTemplate) SetFuncs(key string, funcMap FuncMap)

func (*HTMLTemplate) SetSqlTemplateCipher

func (sqlTemplate *HTMLTemplate) SetSqlTemplateCipher(cipher Cipher)

func (*HTMLTemplate) UpdateSqlTemplate

func (sqlTemplate *HTMLTemplate) UpdateSqlTemplate(key string, sqlTemplateStr string) error

func (*HTMLTemplate) WalkFunc

func (sqlTemplate *HTMLTemplate) WalkFunc(path string, info os.FileInfo, err error) error

type Interface

type Interface interface {
	AllCols() *Session
	Alias(alias string) *Session
	Asc(colNames ...string) *Session
	BufferSize(size int) *Session
	Cols(columns ...string) *Session
	Count(...interface{}) (int64, error)
	CreateIndexes(bean interface{}) error
	CreateUniques(bean interface{}) error
	Decr(column string, arg ...interface{}) *Session
	Desc(...string) *Session
	Delete(interface{}) (int64, error)
	Distinct(columns ...string) *Session
	DropIndexes(bean interface{}) error
	Exec(sqlOrArgs ...interface{}) (sql.Result, error)
	Exist(bean ...interface{}) (bool, error)
	Find(interface{}, ...interface{}) error
	FindAndCount(interface{}, ...interface{}) (int64, error)
	Get(interface{}) (bool, error)
	GroupBy(keys string) *Session
	ID(interface{}) *Session
	In(string, ...interface{}) *Session
	Incr(column string, arg ...interface{}) *Session
	Insert(...interface{}) (int64, error)
	InsertOne(interface{}) (int64, error)
	IsTableEmpty(bean interface{}) (bool, error)
	IsTableExist(beanOrTableName interface{}) (bool, error)
	Iterate(interface{}, IterFunc) error
	Limit(int, ...int) *Session
	MustCols(columns ...string) *Session
	NoAutoCondition(...bool) *Session
	NotIn(string, ...interface{}) *Session
	Join(joinOperator string, tablename interface{}, condition string, args ...interface{}) *Session
	Omit(columns ...string) *Session
	OrderBy(order string) *Session
	Ping() error
	QueryBytes(sqlOrArgs ...interface{}) (resultsSlice []map[string][]byte, err error)
	QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error)
	QueryString(sqlOrArgs ...interface{}) ([]map[string]string, error)
	QueryValue(sqlOrArgs ...interface{}) ([]map[string]Value, error)
	QueryResult(sqlOrArgs ...interface{}) (result *ResultValue)
	Rows(bean interface{}) (*Rows, error)
	SetExpr(string, interface{}) *Session
	Select(string) *Session
	SQL(interface{}, ...interface{}) *Session
	Sum(bean interface{}, colName string) (float64, error)
	SumInt(bean interface{}, colName string) (int64, error)
	Sums(bean interface{}, colNames ...string) ([]float64, error)
	SumsInt(bean interface{}, colNames ...string) ([]int64, error)
	Table(tableNameOrBean interface{}) *Session
	Unscoped() *Session
	Update(bean interface{}, condiBeans ...interface{}) (int64, error)
	UseBool(...string) *Session
	Where(interface{}, ...interface{}) *Session
}

Interface defines the interface which Engine, EngineGroup and Session will implementate.

type IterFunc

type IterFunc func(idx int, bean interface{}) error

IterFunc only use by Iterate

type JSONInterface

type JSONInterface interface {
	Marshal(v interface{}) ([]byte, error)
	Unmarshal(data []byte, v interface{}) error
}

JSONInterface represents an interface to handle json data

var (
	// DefaultJSONHandler default json handler
	DefaultJSONHandler JSONInterface = StdJSON{}
)

type JetTemplate

type JetTemplate struct {
	SqlTemplateRootDir string
	Template           map[string]*jet.Template

	Capacity uint
	Cipher   Cipher
	Funcs    map[string]FuncMap
	// contains filtered or unexported fields
}

func Jet

func Jet(directory, extension string) *JetTemplate

func (*JetTemplate) AddSqlTemplate

func (sqlTemplate *JetTemplate) AddSqlTemplate(key string, sqlTemplateStr string) error

func (*JetTemplate) BatchAddSqlTemplate

func (sqlTemplate *JetTemplate) BatchAddSqlTemplate(key string, sqlTemplateStrMap map[string]string) error

func (*JetTemplate) BatchLoadSqlTemplate

func (sqlTemplate *JetTemplate) BatchLoadSqlTemplate(filepathSlice []string) error

func (*JetTemplate) BatchReloadSqlTemplate

func (sqlTemplate *JetTemplate) BatchReloadSqlTemplate(filepathSlice []string) error

func (*JetTemplate) BatchRemoveSqlTemplate

func (sqlTemplate *JetTemplate) BatchRemoveSqlTemplate(key []string)

func (*JetTemplate) BatchUpdateSqlTemplate

func (sqlTemplate *JetTemplate) BatchUpdateSqlTemplate(key string, sqlTemplateStrMap map[string]string) error

func (*JetTemplate) Execute

func (sqlTemplate *JetTemplate) Execute(key string, args ...interface{}) (string, error)

func (*JetTemplate) Extension

func (sqlTemplate *JetTemplate) Extension() string

func (*JetTemplate) GetSqlTemplate

func (sqlTemplate *JetTemplate) GetSqlTemplate(key string) *jet.Template

func (*JetTemplate) GetSqlTemplates

func (sqlTemplate *JetTemplate) GetSqlTemplates(keys ...interface{}) map[string]*jet.Template

func (*JetTemplate) LoadSqlTemplate

func (sqlTemplate *JetTemplate) LoadSqlTemplate(filepath string) error

-------------------------------------------------------------------------------------------------------------

func (*JetTemplate) ReadTemplate

func (sqlTemplate *JetTemplate) ReadTemplate(filepath string) ([]byte, error)

func (*JetTemplate) ReloadSqlTemplate

func (sqlTemplate *JetTemplate) ReloadSqlTemplate(filepath string) error

func (*JetTemplate) RemoveSqlTemplate

func (sqlTemplate *JetTemplate) RemoveSqlTemplate(key string)

func (*JetTemplate) RootDir

func (sqlTemplate *JetTemplate) RootDir() string

func (*JetTemplate) SetFuncs

func (sqlTemplate *JetTemplate) SetFuncs(key string, funcMap FuncMap)

func (*JetTemplate) SetSqlTemplateCipher

func (sqlTemplate *JetTemplate) SetSqlTemplateCipher(cipher Cipher)

func (*JetTemplate) UpdateSqlTemplate

func (sqlTemplate *JetTemplate) UpdateSqlTemplate(key string, sqlTemplateStr string) error

func (*JetTemplate) WalkFunc

func (sqlTemplate *JetTemplate) WalkFunc(path string, info os.FileInfo, err error) error

type JsonSqlMap

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

func Json

func Json(directory, extension string) *JsonSqlMap

func (*JsonSqlMap) Extension

func (sqlMap *JsonSqlMap) Extension() string

func (*JsonSqlMap) RootDir

func (sqlMap *JsonSqlMap) RootDir() string

type NullBool

type NullBool struct {
	Bool  bool
	Valid bool
}

func (NullBool) IsNil

func (nb NullBool) IsNil() bool

func (NullBool) MarshalJSON

func (nb NullBool) MarshalJSON() ([]byte, error)

func (NullBool) MarshalText

func (nb NullBool) MarshalText() ([]byte, error)

func (NullBool) Ptr

func (nb NullBool) Ptr() *bool

func (*NullBool) UnmarshalJSON

func (nb *NullBool) UnmarshalJSON(data []byte) error

func (*NullBool) UnmarshalText

func (nb *NullBool) UnmarshalText(text []byte) error

func (NullBool) ValueOrZero

func (nb NullBool) ValueOrZero() bool

type NullFloat32

type NullFloat32 struct {
	Float32 float32
	Valid   bool
}

func (NullFloat32) IsNil

func (nf NullFloat32) IsNil() bool

func (NullFloat32) MarshalJSON

func (nf NullFloat32) MarshalJSON() ([]byte, error)

func (NullFloat32) MarshalText

func (nf NullFloat32) MarshalText() ([]byte, error)

func (NullFloat32) Ptr

func (nf NullFloat32) Ptr() *float32

func (*NullFloat32) UnmarshalJSON

func (nf *NullFloat32) UnmarshalJSON(data []byte) error

func (*NullFloat32) UnmarshalText

func (nf *NullFloat32) UnmarshalText(text []byte) error

func (NullFloat32) ValueOrZero

func (nf NullFloat32) ValueOrZero() float32

type NullFloat64

type NullFloat64 struct {
	Float64 float64
	Valid   bool
}

func (NullFloat64) IsNil

func (nf NullFloat64) IsNil() bool

func (NullFloat64) MarshalJSON

func (nf NullFloat64) MarshalJSON() ([]byte, error)

func (NullFloat64) MarshalText

func (nf NullFloat64) MarshalText() ([]byte, error)

func (NullFloat64) Ptr

func (nf NullFloat64) Ptr() *float64

func (*NullFloat64) UnmarshalJSON

func (nf *NullFloat64) UnmarshalJSON(data []byte) error

func (*NullFloat64) UnmarshalText

func (nf *NullFloat64) UnmarshalText(text []byte) error

func (NullFloat64) ValueOrZero

func (nf NullFloat64) ValueOrZero() float64

type NullInt

type NullInt struct {
	Int   int
	Valid bool
}

func (NullInt) IsNil

func (ni NullInt) IsNil() bool

func (NullInt) MarshalJSON

func (ni NullInt) MarshalJSON() ([]byte, error)

func (NullInt) MarshalText

func (ni NullInt) MarshalText() ([]byte, error)

func (NullInt) Ptr

func (ni NullInt) Ptr() *int

func (*NullInt) UnmarshalJSON

func (ni *NullInt) UnmarshalJSON(data []byte) error

func (*NullInt) UnmarshalText

func (ni *NullInt) UnmarshalText(text []byte) error

func (NullInt) ValueOrZero

func (ni NullInt) ValueOrZero() int

type NullInt16

type NullInt16 struct {
	Int16 int16
	Valid bool
}

func (NullInt16) IsNil

func (ni NullInt16) IsNil() bool

func (NullInt16) MarshalJSON

func (ni NullInt16) MarshalJSON() ([]byte, error)

func (NullInt16) MarshalText

func (ni NullInt16) MarshalText() ([]byte, error)

func (NullInt16) Ptr

func (ni NullInt16) Ptr() *int16

func (*NullInt16) UnmarshalJSON

func (ni *NullInt16) UnmarshalJSON(data []byte) error

func (*NullInt16) UnmarshalText

func (ni *NullInt16) UnmarshalText(text []byte) error

func (NullInt16) ValueOrZero

func (ni NullInt16) ValueOrZero() int16

type NullInt32

type NullInt32 struct {
	Int32 int32
	Valid bool
}

func (NullInt32) IsNil

func (ni NullInt32) IsNil() bool

func (NullInt32) MarshalJSON

func (ni NullInt32) MarshalJSON() ([]byte, error)

func (NullInt32) MarshalText

func (ni NullInt32) MarshalText() ([]byte, error)

func (NullInt32) Ptr

func (ni NullInt32) Ptr() *int32

func (*NullInt32) UnmarshalJSON

func (ni *NullInt32) UnmarshalJSON(data []byte) error

func (*NullInt32) UnmarshalText

func (ni *NullInt32) UnmarshalText(text []byte) error

func (NullInt32) ValueOrZero

func (ni NullInt32) ValueOrZero() int32

type NullInt64

type NullInt64 struct {
	Int64 int64
	Valid bool
}

func (NullInt64) IsNil

func (ni NullInt64) IsNil() bool

func (NullInt64) MarshalJSON

func (ni NullInt64) MarshalJSON() ([]byte, error)

func (NullInt64) MarshalText

func (ni NullInt64) MarshalText() ([]byte, error)

func (NullInt64) Ptr

func (ni NullInt64) Ptr() *int64

func (*NullInt64) UnmarshalJSON

func (ni *NullInt64) UnmarshalJSON(data []byte) error

func (*NullInt64) UnmarshalText

func (ni *NullInt64) UnmarshalText(text []byte) error

func (NullInt64) ValueOrZero

func (ni NullInt64) ValueOrZero() int64

type NullInt8

type NullInt8 struct {
	Int8  int8
	Valid bool
}

func (NullInt8) IsNil

func (ni NullInt8) IsNil() bool

func (NullInt8) MarshalJSON

func (ni NullInt8) MarshalJSON() ([]byte, error)

func (NullInt8) MarshalText

func (ni NullInt8) MarshalText() ([]byte, error)

func (NullInt8) Ptr

func (ni NullInt8) Ptr() *int8

func (*NullInt8) UnmarshalJSON

func (ni *NullInt8) UnmarshalJSON(data []byte) error

func (*NullInt8) UnmarshalText

func (ni *NullInt8) UnmarshalText(text []byte) error

func (NullInt8) ValueOrZero

func (ni NullInt8) ValueOrZero() int8

type NullString

type NullString struct {
	String string
	Valid  bool
}

func (NullString) IsNil

func (ns NullString) IsNil() bool

func (NullString) MarshalJSON

func (ns NullString) MarshalJSON() ([]byte, error)

func (NullString) MarshalText

func (ns NullString) MarshalText() ([]byte, error)

func (NullString) Ptr

func (ns NullString) Ptr() *string

func (*NullString) UnmarshalJSON

func (ns *NullString) UnmarshalJSON(data []byte) error

func (*NullString) UnmarshalText

func (ns *NullString) UnmarshalText(text []byte) error

func (NullString) ValueOrZero

func (ns NullString) ValueOrZero() string

type NullTime

type NullTime struct {
	Time  time.Time
	Valid bool
}

func (NullTime) IsNil

func (nt NullTime) IsNil() bool

func (NullTime) Ptr

func (nt NullTime) Ptr() *time.Time

func (NullTime) ValueOrZero

func (nt NullTime) ValueOrZero() time.Time

type NullType

type NullType interface {
	IsNil() bool
}

type NullUint

type NullUint struct {
	Uint  uint
	Valid bool
}

func (NullUint) IsNil

func (nu NullUint) IsNil() bool

func (NullUint) MarshalJSON

func (ni NullUint) MarshalJSON() ([]byte, error)

func (NullUint) MarshalText

func (ni NullUint) MarshalText() ([]byte, error)

func (NullUint) Ptr

func (nu NullUint) Ptr() *uint

func (*NullUint) UnmarshalJSON

func (nu *NullUint) UnmarshalJSON(data []byte) error

func (*NullUint) UnmarshalText

func (nu *NullUint) UnmarshalText(text []byte) error

func (NullUint) ValueOrZero

func (nu NullUint) ValueOrZero() uint

type NullUint16

type NullUint16 struct {
	Uint16 uint16
	Valid  bool
}

func (NullUint16) IsNil

func (nu NullUint16) IsNil() bool

func (NullUint16) MarshalJSON

func (nu NullUint16) MarshalJSON() ([]byte, error)

func (NullUint16) MarshalText

func (nu NullUint16) MarshalText() ([]byte, error)

func (NullUint16) Ptr

func (nu NullUint16) Ptr() *uint16

func (*NullUint16) UnmarshalJSON

func (nu *NullUint16) UnmarshalJSON(data []byte) error

func (*NullUint16) UnmarshalText

func (nu *NullUint16) UnmarshalText(text []byte) error

func (NullUint16) ValueOrZero

func (nu NullUint16) ValueOrZero() uint16

type NullUint32

type NullUint32 struct {
	Uint32 uint32
	Valid  bool
}

func (NullUint32) IsNil

func (nu NullUint32) IsNil() bool

func (NullUint32) MarshalJSON

func (nu NullUint32) MarshalJSON() ([]byte, error)

func (NullUint32) MarshalText

func (nu NullUint32) MarshalText() ([]byte, error)

func (NullUint32) Ptr

func (nu NullUint32) Ptr() *uint32

func (*NullUint32) UnmarshalJSON

func (nu *NullUint32) UnmarshalJSON(data []byte) error

func (*NullUint32) UnmarshalText

func (nu *NullUint32) UnmarshalText(text []byte) error

func (NullUint32) ValueOrZero

func (nu NullUint32) ValueOrZero() uint32

type NullUint64

type NullUint64 struct {
	Uint64 uint64
	Valid  bool
}

func (NullUint64) IsNil

func (nu NullUint64) IsNil() bool

func (NullUint64) MarshalJSON

func (nu NullUint64) MarshalJSON() ([]byte, error)

func (NullUint64) MarshalText

func (nu NullUint64) MarshalText() ([]byte, error)

func (NullUint64) Ptr

func (nu NullUint64) Ptr() *uint64

func (*NullUint64) UnmarshalJSON

func (nu *NullUint64) UnmarshalJSON(data []byte) error

func (*NullUint64) UnmarshalText

func (nu *NullUint64) UnmarshalText(text []byte) error

func (NullUint64) ValueOrZero

func (nu NullUint64) ValueOrZero() uint64

type NullUint8

type NullUint8 struct {
	Uint8 uint8
	Valid bool
}

func (NullUint8) IsNil

func (nu NullUint8) IsNil() bool

func (NullUint8) MarshalJSON

func (nu NullUint8) MarshalJSON() ([]byte, error)

func (NullUint8) MarshalText

func (nu NullUint8) MarshalText() ([]byte, error)

func (NullUint8) Ptr

func (nu NullUint8) Ptr() *uint8

func (*NullUint8) UnmarshalJSON

func (nu *NullUint8) UnmarshalJSON(data []byte) error

func (*NullUint8) UnmarshalText

func (nu *NullUint8) UnmarshalText(text []byte) error

func (NullUint8) ValueOrZero

func (nu NullUint8) ValueOrZero() uint8

type Pongo2Template

type Pongo2Template struct {
	SqlTemplateRootDir string
	Template           map[string]*pongo2.Template

	Capacity uint
	Cipher   Cipher
	Type     int
	Funcs    map[string]FuncMap
	// contains filtered or unexported fields
}

func Pongo2

func Pongo2(directory, extension string) *Pongo2Template

func (*Pongo2Template) AddSqlTemplate

func (sqlTemplate *Pongo2Template) AddSqlTemplate(key string, sqlTemplateStr string) error

func (*Pongo2Template) BatchAddSqlTemplate

func (sqlTemplate *Pongo2Template) BatchAddSqlTemplate(key string, sqlTemplateStrMap map[string]string) error

func (*Pongo2Template) BatchLoadSqlTemplate

func (sqlTemplate *Pongo2Template) BatchLoadSqlTemplate(filepathSlice []string) error

func (*Pongo2Template) BatchReloadSqlTemplate

func (sqlTemplate *Pongo2Template) BatchReloadSqlTemplate(filepathSlice []string) error

func (*Pongo2Template) BatchRemoveSqlTemplate

func (sqlTemplate *Pongo2Template) BatchRemoveSqlTemplate(key []string)

func (*Pongo2Template) BatchUpdateSqlTemplate

func (sqlTemplate *Pongo2Template) BatchUpdateSqlTemplate(key string, sqlTemplateStrMap map[string]string) error

func (*Pongo2Template) Execute

func (sqlTemplate *Pongo2Template) Execute(key string, args ...interface{}) (string, error)

func (*Pongo2Template) Extension

func (sqlTemplate *Pongo2Template) Extension() string

func (*Pongo2Template) GetSqlTemplate

func (sqlTemplate *Pongo2Template) GetSqlTemplate(key string) *pongo2.Template

func (*Pongo2Template) GetSqlTemplates

func (sqlTemplate *Pongo2Template) GetSqlTemplates(keys ...interface{}) map[string]*pongo2.Template

func (*Pongo2Template) LoadSqlTemplate

func (sqlTemplate *Pongo2Template) LoadSqlTemplate(filepath string) error

-------------------------------------------------------------------------------------------------------------

func (*Pongo2Template) ReadTemplate

func (sqlTemplate *Pongo2Template) ReadTemplate(filepath string) ([]byte, error)

func (*Pongo2Template) ReloadSqlTemplate

func (sqlTemplate *Pongo2Template) ReloadSqlTemplate(filepath string) error

func (*Pongo2Template) RemoveSqlTemplate

func (sqlTemplate *Pongo2Template) RemoveSqlTemplate(key string)

func (*Pongo2Template) RootDir

func (sqlTemplate *Pongo2Template) RootDir() string

func (*Pongo2Template) SetFuncs

func (sqlTemplate *Pongo2Template) SetFuncs(key string, funcMap FuncMap)

func (*Pongo2Template) SetSqlTemplateCipher

func (sqlTemplate *Pongo2Template) SetSqlTemplateCipher(cipher Cipher)

func (*Pongo2Template) UpdateSqlTemplate

func (sqlTemplate *Pongo2Template) UpdateSqlTemplate(key string, sqlTemplateStr string) error

func (*Pongo2Template) WalkFunc

func (sqlTemplate *Pongo2Template) WalkFunc(path string, info os.FileInfo, err error) error

type Record

type Record map[string]Value

type Result

type Result []Record

type ResultBean

type ResultBean struct {
	Has    bool
	Result interface{}
	Error  error
}

func (*ResultBean) GetResult

func (resultBean *ResultBean) GetResult() (bool, interface{}, error)

func (*ResultBean) Json

func (resultBean *ResultBean) Json() (bool, string, error)

func (*ResultBean) Xml

func (resultBean *ResultBean) Xml() (bool, string, error)

func (*ResultBean) XmlIndent

func (resultBean *ResultBean) XmlIndent(prefix string, indent string, recordTag string) (bool, string, error)

type ResultMap

type ResultMap struct {
	Result []map[string]interface{}
	Error  error
}

func (*ResultMap) Count

func (resultMap *ResultMap) Count() (int, error)

func (*ResultMap) Json

func (resultMap *ResultMap) Json() (string, error)

func (*ResultMap) List

func (resultMap *ResultMap) List() ([]map[string]interface{}, error)

func (*ResultMap) ListPage

func (resultMap *ResultMap) ListPage(firstResult int, maxResults int) ([]map[string]interface{}, error)

func (*ResultMap) SaveAsCSV

func (resultMap *ResultMap) SaveAsCSV(filename string, headers []string, perm os.FileMode) error

func (*ResultMap) SaveAsHTML

func (resultMap *ResultMap) SaveAsHTML(filename string, headers []string, perm os.FileMode) error

func (*ResultMap) SaveAsJSON

func (resultMap *ResultMap) SaveAsJSON(filename string, headers []string, perm os.FileMode) error

func (*ResultMap) SaveAsTSV

func (resultMap *ResultMap) SaveAsTSV(filename string, headers []string, perm os.FileMode) error

func (*ResultMap) SaveAsXLSX

func (resultMap *ResultMap) SaveAsXLSX(filename string, headers []string, perm os.FileMode) error

func (*ResultMap) SaveAsXML

func (resultMap *ResultMap) SaveAsXML(filename string, headers []string, perm os.FileMode) error

func (*ResultMap) SaveAsXMLWithTagNamePrefixIndent

func (resultMap *ResultMap) SaveAsXMLWithTagNamePrefixIndent(tagName string, prifix string, indent string, filename string, headers []string, perm os.FileMode) error

func (*ResultMap) SaveAsYAML

func (resultMap *ResultMap) SaveAsYAML(filename string, headers []string, perm os.FileMode) error

func (*ResultMap) Xml

func (resultMap *ResultMap) Xml() (string, error)

func (*ResultMap) XmlIndent

func (resultMap *ResultMap) XmlIndent(prefix string, indent string, recordTag string) (string, error)

type ResultStructs

type ResultStructs struct {
	Result interface{}
	Error  error
}

func (*ResultStructs) Json

func (resultStructs *ResultStructs) Json() (string, error)

func (*ResultStructs) Xml

func (resultStructs *ResultStructs) Xml() (string, error)

func (*ResultStructs) XmlIndent

func (resultStructs *ResultStructs) XmlIndent(prefix string, indent string, recordTag string) (string, error)

type ResultValue

type ResultValue struct {
	Result Result
	Error  error
}

func (*ResultValue) Count

func (resultValue *ResultValue) Count() (int, error)

func (*ResultValue) List

func (resultValue *ResultValue) List() (Result, error)

func (*ResultValue) ListPage

func (resultValue *ResultValue) ListPage(firstResult int, maxResults int) (Result, error)

type Rows

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

Rows rows wrapper a rows to

func (*Rows) Close

func (rows *Rows) Close() error

Close session if session.IsAutoClose is true, and claimed any opened resources

func (*Rows) Err

func (rows *Rows) Err() error

Err returns the error, if any, that was encountered during iteration. Err may be called after an explicit or implicit Close.

func (*Rows) Next

func (rows *Rows) Next() bool

Next move cursor to next record, return false if end has reached

func (*Rows) Scan

func (rows *Rows) Scan(bean interface{}) error

Scan row record to bean properties

type RsaEncrypt

type RsaEncrypt struct {
	PubKey string
	PriKey string

	EncryptMode int
	DecryptMode int
	// contains filtered or unexported fields
}

func (*RsaEncrypt) Byte

func (this *RsaEncrypt) Byte(in []byte, mode int) ([]byte, error)

func (*RsaEncrypt) Decrypt

func (this *RsaEncrypt) Decrypt(crypted []byte) (decrypted []byte, err error)

func (*RsaEncrypt) Encrypt

func (this *RsaEncrypt) Encrypt(strMesg string) ([]byte, error)

func (*RsaEncrypt) IO

func (this *RsaEncrypt) IO(in io.Reader, out io.Writer, mode int) error

type Scanner

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

func (*Scanner) Run

func (s *Scanner) Run(io *bufio.Scanner) map[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 (*Session) After

func (session *Session) After(closures func(interface{})) *Session

After Apply after Processor, affected bean is passed to closure arg

func (*Session) Alias

func (session *Session) Alias(alias string) *Session

Alias set the table alias

func (*Session) AllCols

func (session *Session) AllCols() *Session

AllCols ask all columns

func (*Session) And

func (session *Session) And(query interface{}, args ...interface{}) *Session

And provides custom query condition.

func (*Session) Asc

func (session *Session) Asc(colNames ...string) *Session

Asc provide asc order by query condition, the input parameters are columns.

func (*Session) Before

func (session *Session) Before(closures func(interface{})) *Session

Before Apply before Processor, affected bean is passed to closure arg

func (*Session) Begin

func (session *Session) Begin() error

Begin a transaction

func (*Session) BeginTrans

func (session *Session) BeginTrans(transactionDefinition ...int) (*Transaction, error)

func (*Session) BufferSize

func (session *Session) BufferSize(size int) *Session

BufferSize sets the buffersize for iterate

func (*Session) Cascade

func (session *Session) Cascade(trueOrFalse ...bool) *Session

Cascade indicates if loading sub Struct

func (*Session) Charset

func (session *Session) Charset(charset string) *Session

Charset is only avialble mysql dialect currently

func (*Session) Close

func (session *Session) Close() error

Close release the connection from pool

func (*Session) Cols

func (session *Session) Cols(columns ...string) *Session

Cols provides some columns to special

func (*Session) Commit

func (session *Session) Commit() error

Commit When using transaction, Commit will commit all operations.

func (*Session) Conds

func (session *Session) Conds() builder.Cond

Conds returns session query conditions except auto bean conditions

func (*Session) Context

func (session *Session) Context(ctx context.Context) *Session

ContextHook 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

func (session *Session) Count(bean ...interface{}) (int64, error)

Count counts the records. bean's non-empty fields are conditions.

func (*Session) CreateIndexes

func (session *Session) CreateIndexes(bean interface{}) error

CreateIndexes create indexes

func (*Session) CreateTable

func (session *Session) CreateTable(bean interface{}) error

CreateTable create a table according a bean

func (*Session) CreateUniques

func (session *Session) CreateUniques(bean interface{}) error

CreateUniques create uniques

func (*Session) DB

func (session *Session) DB() *core.DB

DB db return the wrapper of sql.DB

func (*Session) Decr

func (session *Session) Decr(column string, arg ...interface{}) *Session

Decr provides a query string like "count = count - 1"

func (*Session) Delete

func (session *Session) Delete(bean interface{}) (int64, error)

Delete records, bean's non-empty fields are conditions

func (*Session) Desc

func (session *Session) Desc(colNames ...string) *Session

Desc provide desc order by query condition, the input parameters are columns.

func (*Session) Distinct

func (session *Session) Distinct(columns ...string) *Session

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

func (session *Session) DropIndexes(bean interface{}) error

DropIndexes drop indexes

func (*Session) DropTable

func (session *Session) DropTable(beanOrTableName interface{}) error

DropTable drop table will drop table if exist, if drop failed, it will return error

func (*Session) Engine

func (session *Session) Engine() *Engine

func (*Session) Exec

func (session *Session) Exec(sqlOrArgs ...interface{}) (sql.Result, error)

Exec raw sql

func (*Session) Execute

func (session *Session) Execute() (sql.Result, error)

Execute raw sql

func (*Session) Exist

func (session *Session) Exist(bean ...interface{}) (bool, error)

Exist returns true if the record exist otherwise return false

func (*Session) Find

func (session *Session) Find(rowsSlicePtr interface{}, condiBean ...interface{}) error

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

func (session *Session) ForUpdate() *Session

ForUpdate Set Read/Write locking for UPDATE

func (*Session) Get

func (session *Session) Get(bean interface{}) (bool, error)

Get retrieve one record from database, bean's non-empty fields will be as conditions

func (*Session) GetFirst

func (session *Session) GetFirst(bean interface{}) *ResultBean

func (*Session) GroupBy

func (session *Session) GroupBy(keys string) *Session

GroupBy Generate Group By statement

func (*Session) Having

func (session *Session) Having(conditions string) *Session

Having Generate Having statement

func (*Session) ID

func (session *Session) ID(id interface{}) *Session

ID provides converting id as a query condition

func (*Session) Import

func (session *Session) Import(r io.Reader) ([]sql.Result, error)

Import SQL DDL from io.Reader

func (*Session) ImportFile

func (session *Session) ImportFile(ddlPath string) ([]sql.Result, error)

ImportFile SQL DDL file

func (*Session) In

func (session *Session) In(column string, args ...interface{}) *Session

In provides a query string like "id in (1, 2, 3)"

func (*Session) Incr

func (session *Session) Incr(column string, arg ...interface{}) *Session

Incr provides a query string like "count = count + 1"

func (*Session) Insert

func (session *Session) Insert(beans ...interface{}) (int64, error)

Insert insert one or more beans

func (*Session) InsertMulti

func (session *Session) InsertMulti(rowsSlicePtr interface{}) (int64, error)

InsertMulti insert multiple records

func (*Session) InsertOne

func (session *Session) InsertOne(bean interface{}) (int64, error)

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) IsClosed

func (session *Session) IsClosed() bool

IsClosed returns if session is closed

func (*Session) IsTableEmpty

func (session *Session) IsTableEmpty(bean interface{}) (bool, error)

IsTableEmpty if table have any records

func (*Session) IsTableExist

func (session *Session) IsTableExist(beanOrTableName interface{}) (bool, error)

IsTableExist if a table is exist

func (*Session) Iterate

func (session *Session) Iterate(bean interface{}, fun IterFunc) error

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 string, args ...interface{}) *Session

Join join_operator should be one of INNER, LEFT OUTER, CROSS etc - this will be prepended to JOIN

func (*Session) LastSQL

func (session *Session) LastSQL() (string, []interface{})

LastSQL returns last query information

func (*Session) Limit

func (session *Session) Limit(limit int, start ...int) *Session

Limit provide limit and offset query condition

func (*Session) MustCols

func (session *Session) MustCols(columns ...string) *Session

MustCols specify some columns must use even if they are empty

func (*Session) MustLogSQL

func (session *Session) MustLogSQL(logs ...bool) *Session

MustLogSQL means record SQL or not and don't follow engine's setting

func (*Session) NoAutoCondition

func (session *Session) NoAutoCondition(no ...bool) *Session

NoAutoCondition disable generate SQL condition from beans

func (*Session) NoAutoTime

func (session *Session) NoAutoTime() *Session

NoAutoTime means do not automatically give created field and updated field the current time on the current session temporarily

func (*Session) NoCache

func (session *Session) NoCache() *Session

NoCache ask this session do not retrieve data from cache system and get data from database directly.

func (*Session) NoCascade

func (session *Session) NoCascade() *Session

NoCascade indicate that no cascade load child object

func (*Session) NotIn

func (session *Session) NotIn(column string, args ...interface{}) *Session

NotIn provides a query string like "id in (1, 2, 3)"

func (*Session) Nullable

func (session *Session) Nullable(columns ...string) *Session

Nullable Set null when column is zero-value and nullable for update

func (*Session) Omit

func (session *Session) Omit(columns ...string) *Session

Omit Only not use the parameters as select or update columns

func (*Session) OmitConditions added in v1.2.10

func (session *Session) OmitConditions(columns ...string) *Session

OmitConditions omit condition when generate SQL condition from beans

func (*Session) Or

func (session *Session) Or(query interface{}, args ...interface{}) *Session

Or provides custom query condition.

func (*Session) OrderBy

func (session *Session) OrderBy(order string) *Session

OrderBy provide order by query condition, the input parameter is the content after order by on a sql statement.

func (*Session) Ping

func (session *Session) Ping() error

Ping test if database is ok

func (*Session) PingContext

func (session *Session) PingContext(ctx context.Context) error

PingContext test if database is ok

func (*Session) Prepare

func (session *Session) Prepare() *Session

Prepare set a flag to session that should be prepare statement before execute query

func (*Session) Query

func (session *Session) Query() *ResultMap

Exec a raw sql and return records as ResultMap

func (*Session) QueryBytes

func (session *Session) QueryBytes(sqlOrArgs ...interface{}) ([]map[string][]byte, error)

Query runs a raw sql and return records as []map[string][]byte

func (*Session) QueryExpr

func (session *Session) QueryExpr(sqlOrArgs ...interface{}) sqlExpr

QueryExpr returns the query as bound SQL

func (*Session) QueryInterface

func (session *Session) QueryInterface(sqlOrArgs ...interface{}) ([]map[string]interface{}, error)

QueryInterface runs a raw sql and return records as []map[string]interface{}

func (*Session) QueryResult

func (session *Session) QueryResult(sqlOrArgs ...interface{}) *ResultValue

Query runs a raw sql and return records as ResultValue

func (*Session) QueryRows

func (session *Session) QueryRows(sqlOrArgs ...interface{}) (*core.Rows, error)

func (*Session) QuerySliceString

func (session *Session) QuerySliceString(sqlOrArgs ...interface{}) ([][]string, error)

QuerySliceString runs a raw sql and return records as [][]string

func (*Session) QueryString

func (session *Session) QueryString(sqlOrArgs ...interface{}) ([]map[string]string, error)

QueryString runs a raw sql and return records as []map[string]string

func (*Session) QueryValue

func (session *Session) QueryValue(sqlOrArgs ...interface{}) ([]map[string]Value, error)

func (*Session) QueryWithDateFormat

func (session *Session) QueryWithDateFormat(dateFormat string) *ResultMap

Exec a raw sql and return records as ResultMap

func (*Session) Rollback

func (session *Session) Rollback() error

Rollback When using transaction, you can rollback if any error

func (*Session) Rows

func (session *Session) Rows(bean interface{}) (*Rows, error)

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

func (session *Session) SQL(query interface{}, args ...interface{}) *Session

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) Search

func (session *Session) Search(rowsSlicePtr interface{}, condiBean ...interface{}) *ResultStructs

func (*Session) Select

func (session *Session) Select(str string) *Session

Select provides some columns to special

func (*Session) SetExpr

func (session *Session) SetExpr(column string, expression interface{}) *Session

SetExpr provides a query string like "column = {expression}"

func (*Session) SqlMapClient

func (session *Session) SqlMapClient(sqlTagName string, args ...interface{}) *Session

func (*Session) SqlMapsClient

func (session *Session) SqlMapsClient(sqlkeys interface{}, parmas ...interface{}) *SqlMapsExecutor

func (*Session) SqlTemplateClient

func (session *Session) SqlTemplateClient(sqlTagName string, args ...interface{}) *Session

func (*Session) SqlTemplatesClient

func (session *Session) SqlTemplatesClient(sqlkeys interface{}, parmas ...interface{}) *SqlTemplatesExecutor

func (*Session) Sqls

func (session *Session) Sqls(sqls interface{}, parmas ...interface{}) *SqlsExecutor

func (*Session) StoreEngine

func (session *Session) StoreEngine(storeEngine string) *Session

StoreEngine is only avialble mysql dialect currently

func (*Session) Sum

func (session *Session) Sum(bean interface{}, columnName string) (res float64, err error)

Sum call sum some column. bean's non-empty fields are conditions.

func (*Session) SumInt

func (session *Session) SumInt(bean interface{}, columnName string) (res int64, err error)

SumInt call sum some column. bean's non-empty fields are conditions.

func (*Session) Sums

func (session *Session) Sums(bean interface{}, columnNames ...string) ([]float64, error)

Sums call sum some columns. bean's non-empty fields are conditions.

func (*Session) SumsInt

func (session *Session) SumsInt(bean interface{}, columnNames ...string) ([]int64, error)

SumsInt sum specify columns and return as []int64 instead of []float64

func (*Session) Sync2

func (session *Session) Sync2(beans ...interface{}) error

Sync2 synchronize structs to database tables

func (*Session) Table

func (session *Session) Table(tableNameOrBean interface{}) *Session

Table can input a string or pointer to struct for special a table to operate.

func (*Session) Unscoped

func (session *Session) Unscoped() *Session

Unscoped always disable struct tag "deleted"

func (*Session) Update

func (session *Session) Update(bean interface{}, condiBean ...interface{}) (int64, error)

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

func (session *Session) UseBool(columns ...string) *Session

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

func (*Session) Where

func (session *Session) Where(query interface{}, args ...interface{}) *Session

Where provides custom query condition.

type Sql

type Sql struct {
	Value string `xml:",chardata"`
	Id    string `xml:"id,attr"`
}

type SqlM

type SqlM interface {
	RootDir() string
	Extension() string
}

type SqlMap

type SqlMap struct {
	SqlMapRootDir string
	Sql           map[string]string
	Extension     map[string]string
	Capacity      uint
	Cipher        Cipher
}

type SqlMapsExecutor

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

func (*SqlMapsExecutor) Execute

func (sqlMapsExecutor *SqlMapsExecutor) Execute() ([][]map[string]interface{}, map[string][]map[string]interface{}, error)

type SqlTemplate

type SqlTemplate interface {
	WalkFunc(path string, info os.FileInfo, err error) error

	ReadTemplate(filepath string) ([]byte, error)
	Execute(key string, args ...interface{}) (string, error)
	RootDir() string
	Extension() string
	SetSqlTemplateCipher(cipher Cipher)
	LoadSqlTemplate(filepath string) error
	BatchLoadSqlTemplate(filepathSlice []string) error
	ReloadSqlTemplate(filepath string) error
	BatchReloadSqlTemplate(filepathSlice []string) error
	AddSqlTemplate(key string, sqlTemplateStr string) error
	UpdateSqlTemplate(key string, sqlTemplateStr string) error
	RemoveSqlTemplate(key string)
	BatchAddSqlTemplate(key string, sqlTemplateStrMap map[string]string) error
	BatchUpdateSqlTemplate(key string, sqlTemplateStrMap map[string]string) error
	BatchRemoveSqlTemplate(key []string)
	SetFuncs(key string, funcMap FuncMap)
	// contains filtered or unexported methods
}

type SqlTemplatesExecutor

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

func (*SqlTemplatesExecutor) Execute

func (sqlTemplatesExecutor *SqlTemplatesExecutor) Execute() ([][]map[string]interface{}, map[string][]map[string]interface{}, error)

type SqlsExecutor

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

func (*SqlsExecutor) Execute

func (sqlsExecutor *SqlsExecutor) Execute() ([][]map[string]interface{}, map[string][]map[string]interface{}, error)

type StdJSON

type StdJSON struct{}

StdJSON implements JSONInterface via encoding/json

func (StdJSON) Marshal

func (StdJSON) Marshal(v interface{}) ([]byte, error)

Marshal implements JSONInterface

func (StdJSON) Unmarshal

func (StdJSON) Unmarshal(data []byte, v interface{}) error

Unmarshal implements JSONInterface

type StringBuilder

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

A StringBuilder is used to efficiently build a string using Write methods. It minimizes memory copying. The zero value is ready to use. Do not copy a non-zero Builder.

func (*StringBuilder) Grow

func (b *StringBuilder) Grow(n int)

Grow grows b's capacity, if necessary, to guarantee space for another n bytes. After Grow(n), at least n bytes can be written to b without another allocation. If n is negative, Grow panics.

func (*StringBuilder) Len

func (b *StringBuilder) Len() int

Len returns the number of accumulated bytes; b.Len() == len(b.String()).

func (*StringBuilder) Reset

func (b *StringBuilder) Reset()

Reset resets the Builder to be empty.

func (*StringBuilder) String

func (b *StringBuilder) String() string

String returns the accumulated string.

func (*StringBuilder) Write

func (b *StringBuilder) Write(p []byte) (int, error)

Write appends the contents of p to b's buffer. Write always returns len(p), nil.

func (*StringBuilder) WriteByte

func (b *StringBuilder) WriteByte(c byte) error

WriteByte appends the byte c to b's buffer. The returned error is always nil.

func (*StringBuilder) WriteRune

func (b *StringBuilder) WriteRune(r rune) (int, error)

WriteRune appends the UTF-8 encoding of Unicode code point r to b's buffer. It returns the length of r and a nil error.

func (*StringBuilder) WriteString

func (b *StringBuilder) WriteString(s string) (int, error)

WriteString appends the contents of s to b's buffer. It returns the length of s and a nil error.

type Table

type Table struct {
	*schemas.Table
	Name string
}

Table table struct

func (*Table) IsValid

func (t *Table) IsValid() bool

IsValid if table is valid

type Transaction

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

func (*Transaction) BeginTrans

func (transaction *Transaction) BeginTrans() error

Begin a transaction

func (*Transaction) CommitTrans

func (transaction *Transaction) CommitTrans() error

Commit When using transaction, Commit will commit all operations.

func (*Transaction) Do

func (transaction *Transaction) Do(doFunc func(params ...interface{}), params ...interface{})

func (*Transaction) GetSavePointID

func (transaction *Transaction) GetSavePointID() string

func (*Transaction) IsExistingTransaction

func (transaction *Transaction) IsExistingTransaction() bool

func (*Transaction) RollbackToSavePoint

func (transaction *Transaction) RollbackToSavePoint(savePointID string) error

func (*Transaction) RollbackTrans

func (transaction *Transaction) RollbackTrans() error

Rollback When using transaction, you can rollback if any error

func (*Transaction) SavePoint

func (transaction *Transaction) SavePoint(savePointID string) error

func (*Transaction) Session

func (transaction *Transaction) Session() *Session

func (*Transaction) TransactionDefinition

func (transaction *Transaction) TransactionDefinition() int

func (*Transaction) WaitForDo

func (transaction *Transaction) WaitForDo(doFunc func(params ...interface{}), params ...interface{})

type TripleDesEncrypt

type TripleDesEncrypt struct {
	PubKey string
}

func (*TripleDesEncrypt) Decrypt

func (this *TripleDesEncrypt) Decrypt(crypted []byte) ([]byte, error)

3DES解密

func (*TripleDesEncrypt) Encrypt

func (this *TripleDesEncrypt) Encrypt(strMesg string) ([]byte, error)

3DES加密

type Value

type Value []byte

func (Value) Bool

func (v Value) Bool() bool

func (Value) Bytes

func (v Value) Bytes() []byte

func (Value) Float32

func (v Value) Float32() float32

func (Value) Float64

func (v Value) Float64() float64

func (Value) Int

func (v Value) Int() int

func (Value) Int16

func (v Value) Int16() int16

func (Value) Int32

func (v Value) Int32() int32

func (Value) Int64

func (v Value) Int64() int64

func (Value) Int8

func (v Value) Int8() int8

func (Value) NullBool

func (v Value) NullBool() NullBool

func (Value) NullFloat32

func (v Value) NullFloat32() NullFloat32

func (Value) NullFloat64

func (v Value) NullFloat64() NullFloat64

func (Value) NullInt

func (v Value) NullInt() NullInt

func (Value) NullInt16

func (v Value) NullInt16() NullInt16

func (Value) NullInt32

func (v Value) NullInt32() NullInt32

func (Value) NullInt64

func (v Value) NullInt64() NullInt64

func (Value) NullInt8

func (v Value) NullInt8() NullInt8

func (Value) NullString

func (v Value) NullString() NullString

func (Value) NullTime

func (v Value) NullTime(format string, TZLocation ...*time.Location) NullTime

func (Value) NullUint

func (v Value) NullUint() NullUint

func (Value) NullUint16

func (v Value) NullUint16() NullUint16

func (Value) NullUint32

func (v Value) NullUint32() NullUint32

func (Value) NullUint64

func (v Value) NullUint64() NullUint64

func (Value) NullUint8

func (v Value) NullUint8() NullUint8

func (Value) String

func (v Value) String() string

func (Value) Time

func (v Value) Time(format string, TZLocation ...*time.Location) time.Time

func (Value) TimeDuration

func (v Value) TimeDuration() time.Duration

func (Value) Uint

func (v Value) Uint() uint

func (Value) Uint16

func (v Value) Uint16() uint16

func (Value) Uint32

func (v Value) Uint32() uint32

func (Value) Uint64

func (v Value) Uint64() uint64

func (Value) Uint8

func (v Value) Uint8() uint8

type XSqlMap

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

func XSql

func XSql(directory, extension string) *XSqlMap

func (*XSqlMap) Extension

func (sqlMap *XSqlMap) Extension() string

func (*XSqlMap) RootDir

func (sqlMap *XSqlMap) RootDir() string

type XmlSql

type XmlSql struct {
	Sql []Sql `xml:"sql"`
}

type XmlSqlMap

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

func Xml

func Xml(directory, extension string) *XmlSqlMap

func (*XmlSqlMap) Extension

func (sqlMap *XmlSqlMap) Extension() string

func (*XmlSqlMap) RootDir

func (sqlMap *XmlSqlMap) RootDir() string

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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