xorm

package module
v0.0.0-...-7fa1ede Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2023 License: BSD-3-Clause Imports: 52 Imported by: 0

README

Documentation

Index

Constants

View Source
const (
	DEFAULT_LOG_PREFIX = "[xorm]"
	DEFAULT_LOG_FLAG   = log.Ldate | log.Lmicroseconds
	DEFAULT_LOG_LEVEL  = core.LOG_DEBUG
)
View Source
const (
	RSA_PUBKEY_ENCRYPT_MODE = iota //公钥加密
	RSA_PUBKEY_DECRYPT_MODE        //公钥解密
	RSA_PRIKEY_ENCRYPT_MODE        //私钥加密
	RSA_PRIKEY_DECRYPT_MODE        //私钥解密
)
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 = "goracle"
	SQLITE3_DRIVER    string = "sqlite3"
)
View Source
const (
	// Version show the xorm's version
	Version string = "0.6.0.1022"
)

Variables

View Source
var (
	ErrParamsType      error = errors.New("Params type error")
	ErrParamsFormat    error = errors.New("Params format error")
	ErrTableNotFound   error = errors.New("Not found table")
	ErrUnSupportedType error = errors.New("Unsupported type error")
	ErrNotExist        error = errors.New("Not exist error")
	ErrCacheFailed     error = errors.New("Cache failed")
	ErrNeedDeletedCond error = errors.New("Delete need at least one condition")
	ErrNotImplemented  error = errors.New("Not implemented.")
)
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 (
	// NIL is defined in RFC 4122 section 4.1.7.
	// The nil UUID is special form of UUID that is specified to have all 128 bits set to zero.
	NIL = &UUID{
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
		0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
	}
	// NameSpaceDNS assume name to be a fully-qualified domain name.
	// Declared in RFC 4122 Appendix C.
	NameSpaceDNS = &UUID{
		0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1,
		0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
	}
	// NameSpaceURL assume name to be a URL.
	// Declared in RFC 4122 Appendix C.
	NameSpaceURL = &UUID{
		0x6b, 0xa7, 0xb8, 0x11, 0x9d, 0xad, 0x11, 0xd1,
		0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
	}
	// NameSpaceOID assume name to be an ISO OID.
	// Declared in RFC 4122 Appendix C.
	NameSpaceOID = &UUID{
		0x6b, 0xa7, 0xb8, 0x12, 0x9d, 0xad, 0x11, 0xd1,
		0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
	}
	// NameSpaceX500 assume name to be a X.500 DN (in DER or a text output format).
	// Declared in RFC 4122 Appendix C.
	NameSpaceX500 = &UUID{
		0x6b, 0xa7, 0xb8, 0x14, 0x9d, 0xad, 0x11, 0xd1,
		0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4, 0x30, 0xc8,
	}
)

Functions

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{}) (*tablib.Dataset, error)

NewDatasetWithData creates a new Dataset.

func PKCS5Padding

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

func PKCS5UnPadding

func PKCS5UnPadding(origData []byte) []byte

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 AfterSetProcessor

type AfterSetProcessor interface {
	AfterSet(string, Cell)
}

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

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 Databook

type Databook struct {
	XDatabook *tablib.Databook
}

func NewDatabook

func NewDatabook() *Databook

func NewDatabookWithData

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

func (*Databook) AddSheet

func (databook *Databook) AddSheet(title string, data interface{}, 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 DiscardLogger

type DiscardLogger struct{}

func (DiscardLogger) Debug

func (DiscardLogger) Debug(v ...interface{})

func (DiscardLogger) Debugf

func (DiscardLogger) Debugf(format string, v ...interface{})

func (DiscardLogger) Error

func (DiscardLogger) Error(v ...interface{})

func (DiscardLogger) Errorf

func (DiscardLogger) Errorf(format string, v ...interface{})

func (DiscardLogger) Info

func (DiscardLogger) Info(v ...interface{})

func (DiscardLogger) Infof

func (DiscardLogger) Infof(format string, v ...interface{})

func (DiscardLogger) IsShowSQL

func (DiscardLogger) IsShowSQL() bool

func (DiscardLogger) Level

func (DiscardLogger) Level() core.LogLevel

func (DiscardLogger) SetLevel

func (DiscardLogger) SetLevel(l core.LogLevel)

func (DiscardLogger) ShowSQL

func (DiscardLogger) ShowSQL(show ...bool)

func (DiscardLogger) Warn

func (DiscardLogger) Warn(v ...interface{})

func (DiscardLogger) Warnf

func (DiscardLogger) Warnf(format string, v ...interface{})

type Engine

type Engine struct {
	ColumnMapper  core.IMapper
	TableMapper   core.IMapper
	TagIdentifier string
	Tables        map[reflect.Type]*core.Table

	Cacher core.Cacher

	TZLocation *time.Location
	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 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) 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) 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) ClearSqlTemplateCipher

func (engine *Engine) ClearSqlTemplateCipher()

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 paramters as select or update columns

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() ([]*core.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, arg ...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() core.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) DropTables

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

DropTables drop specify tables

func (*Engine) DumpAll

func (engine *Engine) DumpAll(w io.Writer) error

DumpAll dump database all table structs and data to w

func (*Engine) DumpAllToFile

func (engine *Engine) DumpAllToFile(fp string) error

DumpAllToFile dump database all table structs and data to a file

func (*Engine) DumpTables

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

DumpTables dump specify tables to io.Writer

func (*Engine) DumpTablesToFile

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

DumpTablesToFile dump specified tables to SQL file.

func (*Engine) Exec

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

Exec raw sql

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

func (engine *Engine) FormatTime(sqlTypeName string, t time.Time) (v interface{})

FormatTime format time

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

func (engine *Engine) GetSqlTemplate(key string) *pongo2.Template

func (*Engine) GetSqlTemplates

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

func (*Engine) GobRegister

func (engine *Engine) GobRegister(v interface{}) *Engine

GobRegister register one struct to gob for cache use

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 mehtod provoide a condition as (id) = ?

func (*Engine) Id

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

Id will be depracated, please use ID instead

func (*Engine) IdOf

func (engine *Engine) IdOf(bean interface{}) core.PK

IdOf get id from one struct

func (*Engine) IdOfV

func (engine *Engine) IdOfV(rv reflect.Value) core.PK

IdOfV get id from one value of struct

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

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

func (*Engine) InitSqlMap

func (engine *Engine) InitSqlMap(options ...SqlMapOptions) error

func (*Engine) InitSqlTemplate

func (engine *Engine) InitSqlTemplate(options ...SqlTemplateOptions) error

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() core.ILogger

Logger return the logger interface

func (*Engine) MapCacher

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

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

func (engine *Engine) NowTime(sqlTypeName string) interface{}

NowTime return current time

func (*Engine) NowTime2

func (engine *Engine) NowTime2(sqlTypeName string) (interface{}, time.Time)

NowTime2 return current time

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 paramters 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) Query

func (engine *Engine) Query(sql string, paramStr ...interface{}) (resultsSlice []map[string][]byte, err error)

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

func (*Engine) Query2

func (engine *Engine) Query2(sql string, paramStr ...interface{}) (resultsSlice []map[string]string, err error)

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

func (*Engine) Quote

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

Quote Use QuoteStr quote the string sql

func (*Engine) QuoteStr

func (engine *Engine) QuoteStr() string

QuoteStr Engine's database use which charactor as quote. mysql, sqlite use ` and postgres use "

func (*Engine) QuoteTo

func (engine *Engine) QuoteTo(buf *bytes.Buffer, value string)

QuoteTo quotes string and writes into the buffer

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 manualy 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 *core.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) SetColumnMapper

func (engine *Engine) SetColumnMapper(mapper core.IMapper)

SetColumnMapper set the column name mapping rule

func (*Engine) SetDefaultCacher

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

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

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 string) *Session

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

func (*Engine) SetLogger

func (engine *Engine) SetLogger(logger core.ILogger)

SetLogger set the new logger

func (*Engine) SetMapper

func (engine *Engine) SetMapper(mapper core.IMapper)

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

func (engine *Engine) SetSqlMapCipher(cipher Cipher)

func (*Engine) SetSqlMapRootDir

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

func (*Engine) SetSqlTemplateCipher

func (engine *Engine) SetSqlTemplateCipher(cipher Cipher)

func (*Engine) SetSqlTemplateRootDir

func (engine *Engine) SetSqlTemplateRootDir(sqlTemplateRootDir string) *Engine

func (*Engine) SetTableMapper

func (engine *Engine) SetTableMapper(mapper core.IMapper)

SetTableMapper set the table name mapping rule

func (*Engine) ShowExecTime

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

ShowExecTime show SQL statment and execute time or not on logger if log level is great than INFO

func (*Engine) ShowSQL

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

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

func (*Engine) Sql

func (engine *Engine) Sql(querystring string, args ...interface{}) *Session

Sql will be depracated, please use SQL instead

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

func (engine *Engine) SqlType(c *core.Column) string

SqlType will be depracated, please use SQLType instead

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

func (engine *Engine) SupportInsertMany() bool

SupportInsertMany If engine's database support batch insert records like "insert into user values (name, age), (name, age)". When the return is ture, then engine.Insert(&users) will generate batch sql and exeute.

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

func (engine *Engine) TZTime(t time.Time) time.Time

TZTime change one time to xorm time location

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{}) *Table

TableInfo get table info according to bean's content

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 paramters, it will use all the bool field of struct, or it will use paramters'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 NewPostgresEngineGroup

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

NewEngineGroup creates a new engine group

func (*EngineGroup) Close

func (eg *EngineGroup) Close() error

Close the engine

func (*EngineGroup) InitSqlTemplate

func (engine *EngineGroup) InitSqlTemplate(options SqlTemplateOptions) error

func (*EngineGroup) NewSession

func (eg *EngineGroup) NewSession() *Session

NewSession returned a group session

func (*EngineGroup) SetLogLevel

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

SetLogLevel sets the logger level

func (*EngineGroup) SetLogger

func (eg *EngineGroup) SetLogger(logger core.ILogger)

SetLogger set the new logger

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

func (engine *EngineGroup) SetSqlTemplateRootDir(sqlTemplateRootDir string) *EngineGroup

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 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 RandomPolicy

func RandomPolicy() GroupPolicyHandler

RandomPolicy implmentes randomly chose the subordinate of subordinates

func RoundRobinPolicy

func RoundRobinPolicy() GroupPolicyHandler

RoundRobinPolicy returns a group policy handler

func (GroupPolicyHandler) Subordinate

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

Subordinate implements the chosen of subordinates

type IterFunc

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

IterFunc only use by Iterate

type LRUCacher

type LRUCacher struct {

	// maxSize    int
	MaxElementSize int
	Expired        time.Duration
	GcInterval     time.Duration
	// contains filtered or unexported fields
}

func NewLRUCacher

func NewLRUCacher(store core.CacheStore, maxElementSize int) *LRUCacher

func NewLRUCacher2

func NewLRUCacher2(store core.CacheStore, expired time.Duration, maxElementSize int) *LRUCacher

func (*LRUCacher) ClearBeans

func (m *LRUCacher) ClearBeans(tableName string)

func (*LRUCacher) ClearIds

func (m *LRUCacher) ClearIds(tableName string)

func (*LRUCacher) DelBean

func (m *LRUCacher) DelBean(tableName string, id string)

func (*LRUCacher) DelIds

func (m *LRUCacher) DelIds(tableName, sql string)

func (*LRUCacher) GC

func (m *LRUCacher) GC()

GC check ids lit and sql list to remove all element expired

func (*LRUCacher) GetBean

func (m *LRUCacher) GetBean(tableName string, id string) interface{}

GetBean returns bean according tableName and id from cache

func (*LRUCacher) GetIds

func (m *LRUCacher) GetIds(tableName, sql string) interface{}

GetIds returns all bean's ids according to sql and parameter from cache

func (*LRUCacher) PutBean

func (m *LRUCacher) PutBean(tableName string, id string, obj interface{})

func (*LRUCacher) PutIds

func (m *LRUCacher) PutIds(tableName, sql string, ids interface{})

func (*LRUCacher) RunGC

func (m *LRUCacher) RunGC()

RunGC run once every m.GcInterval

type MemoryStore

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

MemoryStore represents in-memory store

func NewMemoryStore

func NewMemoryStore() *MemoryStore

func (*MemoryStore) Del

func (s *MemoryStore) Del(key string) error

func (*MemoryStore) Get

func (s *MemoryStore) Get(key string) (interface{}, error)

func (*MemoryStore) Put

func (s *MemoryStore) Put(key string, value interface{}) error

type Result

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

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 {
	Results []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 Rows

type Rows struct {
	NoTypeCheck bool
	// 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 Session

type Session struct {
	Engine                 *Engine
	Tx                     *core.Tx
	Statement              Statement
	IsAutoCommit           bool
	IsCommitedOrRollbacked bool
	IsSqlFuc               bool
	TransType              string
	IsAutoClose            bool

	// Automatically reset the statement after operations that execute a SQL
	// query such as Count(), Find(), Get(), ...
	AutoResetStatement bool
	// 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) 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) Clone

func (session *Session) Clone() *Session

Clone copy all the session's content and return a new session.

func (*Session) Close

func (session *Session) Close()

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

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

func (session *Session) Exec(sqlStr string, args ...interface{}) (sql.Result, error)

Exec raw sql

func (*Session) Execute

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

Execute raw sql

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

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

Id will be deprecated, please use ID instead

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

func (session *Session) Init()

Init reset the session as the init status.

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) 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) 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 paramters as select or update columns

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

func (session *Session) Prepare() *Session

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

func (*Session) Query

func (session *Session) Query() *ResultMap

Exec a raw sql and return records as ResultMap

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 string) *Session

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

func (*Session) Sql

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

Sql !DEPRECIATED! will be deprecated, please use SQL instead.

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) (float64, error)

Sum 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 paramters, it will use all the bool field of struct, or it will use paramters's columns

func (*Session) Where

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

Where provides custom query condition.

type SimpleLogger

type SimpleLogger struct {
	DEBUG *log.Logger
	ERR   *log.Logger
	INFO  *log.Logger
	WARN  *log.Logger
	// contains filtered or unexported fields
}

SimpleLogger is the default implment of core.ILogger

func NewSimpleLogger

func NewSimpleLogger(out io.Writer) *SimpleLogger

NewSimpleLogger use a special io.Writer as logger output

func NewSimpleLogger2

func NewSimpleLogger2(out io.Writer, prefix string, flag int) *SimpleLogger

NewSimpleLogger2 let you customrize your logger prefix and flag

func NewSimpleLogger3

func NewSimpleLogger3(out io.Writer, prefix string, flag int, l core.LogLevel) *SimpleLogger

NewSimpleLogger3 let you customrize your logger prefix and flag and logLevel

func (*SimpleLogger) Debug

func (s *SimpleLogger) Debug(v ...interface{})

Debug implement core.ILogger

func (*SimpleLogger) Debugf

func (s *SimpleLogger) Debugf(format string, v ...interface{})

Debugf implement core.ILogger

func (*SimpleLogger) Error

func (s *SimpleLogger) Error(v ...interface{})

Error implement core.ILogger

func (*SimpleLogger) Errorf

func (s *SimpleLogger) Errorf(format string, v ...interface{})

Errorf implement core.ILogger

func (*SimpleLogger) Info

func (s *SimpleLogger) Info(v ...interface{})

Info implement core.ILogger

func (*SimpleLogger) Infof

func (s *SimpleLogger) Infof(format string, v ...interface{})

Infof implement core.ILogger

func (*SimpleLogger) IsShowSQL

func (s *SimpleLogger) IsShowSQL() bool

IsShowSQL implement core.ILogger

func (*SimpleLogger) Level

func (s *SimpleLogger) Level() core.LogLevel

Level implement core.ILogger

func (*SimpleLogger) SetLevel

func (s *SimpleLogger) SetLevel(l core.LogLevel)

SetLevel implement core.ILogger

func (*SimpleLogger) ShowSQL

func (s *SimpleLogger) ShowSQL(show ...bool)

ShowSQL implement core.ILogger

func (*SimpleLogger) Warn

func (s *SimpleLogger) Warn(v ...interface{})

Warn implement core.ILogger

func (*SimpleLogger) Warnf

func (s *SimpleLogger) Warnf(format string, v ...interface{})

Warnf implement core.ILogger

type Sql

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

type SqlMap

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

type SqlMapOptions

type SqlMapOptions struct {
	Capacity  uint
	Extension string
	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 struct {
	SqlTemplateRootDir string
	Template           map[string]*pongo2.Template
	Extension          string
	Capacity           uint
	Cipher             Cipher
}

type SqlTemplateOptions

type SqlTemplateOptions struct {
	Capacity  uint
	Extension string
	Cipher    Cipher
}

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 Statement

type Statement struct {
	RefTable *core.Table
	Engine   *Engine
	Start    int
	LimitN   int
	IdParam  *core.PK
	OrderStr string
	JoinStr  string

	GroupByStr string
	HavingStr  string
	ColumnStr  string

	OmitStr      string
	AltTableName string

	RawSQL      string
	RawParams   []interface{}
	UseCascade  bool
	UseAutoJoin bool
	StoreEngine string
	Charset     string
	UseCache    bool
	UseAutoTime bool

	IsDistinct  bool
	IsForUpdate bool
	TableAlias  string
	// contains filtered or unexported fields
}

Statement save all the sql info for executing SQL

func (*Statement) Alias

func (statement *Statement) Alias(alias string) *Statement

Alias set the table alias

func (*Statement) AllCols

func (statement *Statement) AllCols() *Statement

AllCols update use only: update all columns

func (*Statement) And

func (statement *Statement) And(query interface{}, args ...interface{}) *Statement

And add Where & and statment

func (*Statement) Asc

func (statement *Statement) Asc(colNames ...string) *Statement

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

func (*Statement) Cols

func (statement *Statement) Cols(columns ...string) *Statement

Cols generate "col1, col2" statement

func (*Statement) Decr

func (statement *Statement) Decr(column string, arg ...interface{}) *Statement

Decr Generate "Update ... Set column = column - arg" statment

func (*Statement) Desc

func (statement *Statement) Desc(colNames ...string) *Statement

Desc generate `ORDER BY xx DESC`

func (*Statement) Distinct

func (statement *Statement) Distinct(columns ...string) *Statement

Distinct generates "DISTINCT col1, col2 " statement

func (*Statement) ForUpdate

func (statement *Statement) ForUpdate() *Statement

ForUpdate generates "SELECT ... FOR UPDATE" statement

func (*Statement) GroupBy

func (statement *Statement) GroupBy(keys string) *Statement

GroupBy generate "Group By keys" statement

func (*Statement) Having

func (statement *Statement) Having(conditions string) *Statement

Having generate "Having conditions" statement

func (*Statement) Id

func (statement *Statement) Id(id interface{}) *Statement

Id generate "where id = ? " statment or for composite key "where key1 = ? and key2 = ?"

func (*Statement) In

func (statement *Statement) In(column string, args ...interface{}) *Statement

In generate "Where column IN (?) " statment

func (*Statement) Incr

func (statement *Statement) Incr(column string, arg ...interface{}) *Statement

Incr Generate "Update ... Set column = column + arg" statment

func (*Statement) Init

func (statement *Statement) Init()

Init reset all the statment's fields

func (*Statement) Join

func (statement *Statement) Join(joinOP string, tablename interface{}, condition string, args ...interface{}) *Statement

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

func (*Statement) Limit

func (statement *Statement) Limit(limit int, start ...int) *Statement

Limit generate LIMIT start, limit statement

func (*Statement) MustCols

func (statement *Statement) MustCols(columns ...string) *Statement

MustCols update use only: must update columns

func (*Statement) NoAutoCondition

func (statement *Statement) NoAutoCondition(no ...bool) *Statement

NoAutoCondition if you do not want convert bean's field as query condition, then use this function

func (*Statement) NotIn

func (statement *Statement) NotIn(column string, args ...interface{}) *Statement

NotIn generate "Where column NOT IN (?) " statment

func (*Statement) Nullable

func (statement *Statement) Nullable(columns ...string)

Nullable Update use only: update columns to null when value is nullable and zero-value

func (*Statement) Omit

func (statement *Statement) Omit(columns ...string)

Omit do not use the columns

func (*Statement) Or

func (statement *Statement) Or(query interface{}, args ...interface{}) *Statement

Or add Where & Or statment

func (*Statement) OrderBy

func (statement *Statement) OrderBy(order string) *Statement

OrderBy generate "Order By order" statement

func (*Statement) SQL

func (statement *Statement) SQL(query interface{}, args ...interface{}) *Statement

SQL adds raw sql statement

func (*Statement) Select

func (statement *Statement) Select(str string) *Statement

Select replace select

func (*Statement) SetExpr

func (statement *Statement) SetExpr(column string, expression string) *Statement

SetExpr Generate "Update ... Set column = {expression}" statment

func (*Statement) Table

func (statement *Statement) Table(tableNameOrBean interface{}) *Statement

Table tempororily set table name, the parameter could be a string or a pointer of struct

func (*Statement) TableName

func (statement *Statement) TableName() string

TableName return current tableName

func (*Statement) Top

func (statement *Statement) Top(limit int) *Statement

Top generate LIMIT limit statement

func (*Statement) Unscoped

func (statement *Statement) Unscoped() *Statement

Unscoped always disable struct tag "deleted"

func (*Statement) UseBool

func (statement *Statement) UseBool(columns ...string) *Statement

UseBool indicates that use bool fields as update contents and query contiditions

func (*Statement) Where

func (statement *Statement) Where(query interface{}, args ...interface{}) *Statement

Where add Where statment

type SyslogLogger

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

SyslogLogger will be depricated

func NewSyslogLogger

func NewSyslogLogger(w *syslog.Writer) *SyslogLogger

func (*SyslogLogger) Debug

func (s *SyslogLogger) Debug(v ...interface{})

func (*SyslogLogger) Debugf

func (s *SyslogLogger) Debugf(format string, v ...interface{})

func (*SyslogLogger) Error

func (s *SyslogLogger) Error(v ...interface{})

func (*SyslogLogger) Errorf

func (s *SyslogLogger) Errorf(format string, v ...interface{})

func (*SyslogLogger) Info

func (s *SyslogLogger) Info(v ...interface{})

func (*SyslogLogger) Infof

func (s *SyslogLogger) Infof(format string, v ...interface{})

func (*SyslogLogger) IsShowSQL

func (s *SyslogLogger) IsShowSQL() bool

func (*SyslogLogger) Level

func (s *SyslogLogger) Level() core.LogLevel

func (*SyslogLogger) SetLevel

func (s *SyslogLogger) SetLevel(l core.LogLevel)

SetLevel always return error, as current log/syslog package doesn't allow to set priority level after syslog.Writer created

func (*SyslogLogger) ShowSQL

func (s *SyslogLogger) ShowSQL(show ...bool)

func (*SyslogLogger) Warn

func (s *SyslogLogger) Warn(v ...interface{})

func (*SyslogLogger) Warnf

func (s *SyslogLogger) Warnf(format string, v ...interface{})

type Table

type Table struct {
	*core.Table
	Name string
}

Table table struct

type TableName

type TableName interface {
	TableName() string
}

TableName table name interface to define customerize table name

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 UUID

type UUID [16]byte

The UUID represents Universally Unique IDentifier (which is 128 bit long).

func NewNamespaceUUID

func NewNamespaceUUID(namespace string) *UUID

NewNamespaceUUID creates a namespace UUID by using the namespace name in the NIL name space. This is a different approach as the 4 "standard" namespace UUIDs which are timebased UUIDs (V1).

func NewV1

func NewV1() *UUID

NewV1 creates a new UUID with variant 1 as described in RFC 4122. Variant 1 is based on hosts MAC address and actual timestamp (as count of 100-nanosecond intervals since 00:00:00.00, 15 October 1582 (the date of Gregorian reform to the Christian calendar).

func NewV3

func NewV3(namespace *UUID, name []byte) *UUID

NewV3 creates a new UUID with variant 3 as described in RFC 4122. Variant 3 based namespace-uuid and name and MD-5 hash calculation.

func NewV4

func NewV4() *UUID

NewV4 creates a new UUID with variant 4 as described in RFC 4122. Variant 4 based on pure random bytes.

func NewV5

func NewV5(namespaceUUID *UUID, name []byte) *UUID

NewV5 creates a new UUID with variant 5 as described in RFC 4122. Variant 5 based namespace-uuid and name and SHA-1 hash calculation.

func (*UUID) String

func (u *UUID) String() string

String returns the human readable form of the UUID.

func (*UUID) Version

func (u *UUID) Version() int

Version of the UUID represents a kind of subtype specifier.

Directories

Path Synopsis
internal

Jump to

Keyboard shortcuts

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