Documentation ¶
Index ¶
- Constants
- type AdapterType
- type Engine
- func (e *Engine) And(strFmt string, args ...interface{}) *Engine
- func (e *Engine) Asc() *Engine
- func (e *Engine) Attach(strDatabaseName string, db *sqlx.DB) *Engine
- func (e *Engine) Cache(indexes ...string) *Engine
- func (e *Engine) DB() *sqlx.DB
- func (e *Engine) Debug(ok bool)
- func (e *Engine) Delete() (rowsAffected int64, err error)
- func (e *Engine) Desc() *Engine
- func (e *Engine) Distinct() *Engine
- func (e *Engine) ExecRaw(strQuery string, args ...interface{}) (rowsAffected, lastInsertId int64, err error)
- func (e *Engine) GetPkName() string
- func (e *Engine) GroupBy(strColumns ...string) *Engine
- func (e *Engine) Id(value interface{}) *Engine
- func (e *Engine) In(strColumn string, args ...interface{}) *Engine
- func (e *Engine) Insert() (lastInsertId int64, err error)
- func (e *Engine) Limit(args ...int) *Engine
- func (e *Engine) Model(args ...interface{}) *Engine
- func (e *Engine) Not(strColumn string, args ...interface{}) *Engine
- func (e *Engine) Offset(offset int) *Engine
- func (e *Engine) OnConflict(strColumns ...string) *Engine
- func (e *Engine) Open(strUrl string, expireSeconds ...int) *Engine
- func (e *Engine) OrderBy(strColumns ...string) *Engine
- func (e *Engine) Query() (rowsAffected int64, err error)
- func (e *Engine) QueryMap(strQuery string, args ...interface{}) (rowsAffected int64, err error)
- func (e *Engine) QueryRaw(strQuery string, args ...interface{}) (rowsAffected int64, err error)
- func (e *Engine) Select(strColumns ...string) *Engine
- func (e *Engine) SetCacheBefore(ok bool)
- func (e *Engine) SetCustomTag(tagNames ...string) *Engine
- func (e *Engine) SetLogFile(strPath string)
- func (e *Engine) SetPkName(strName string) *Engine
- func (e *Engine) Table(strNames ...string) *Engine
- func (e *Engine) TxBegin() (*Engine, error)
- func (e *Engine) TxCommit() error
- func (e *Engine) TxExec(strQuery string, args ...interface{}) (lastInsertId, rowsAffected int64, err error)
- func (e *Engine) TxGet(dest interface{}, strQuery string, args ...interface{}) (count int64, err error)
- func (e *Engine) TxRollback() error
- func (e *Engine) Update() (rowsAffected int64, err error)
- func (e *Engine) Upsert() (lastInsertId int64, err error)
- func (e *Engine) Where(strWhere string, args ...interface{}) *Engine
- type Fetcher
- type ModelReflector
- type ModelType
- type OperType
- type UrlInfo
Constants ¶
const ( CACHE_INDEX_DEEP = 1 // index deep in cache CACHE_REPLICATE = "replicate" //replicate host [ip:port,...] CACHE_DB_INDEX = "db" CAHCE_SQLX_PREFIX = "sqlca:cache" )
const ( ValueType_Data valueType = 1 // data of table ValueType_Index valueType = 2 // index of data )
const ( TAG_NAME_DB = "db" TAG_NAME_JSON = "json" TAG_NAME_PROTOBUF = "protobuf" TAG_NAME_SQLCA = "sqlca" )
const ( SQLCA_TAG_VALUE_AUTO_INCR = "autoincr" //auto increment SQLCA_TAG_VALUE_READ_ONLY = "readonly" //read only (eg. created_at) )
const ( DRIVER_NAME_MYSQL = "mysql" DRIVER_NAME_POSTGRES = "postgres" DRIVER_NAME_SQLITE = "sqlite3" DRIVER_NAME_MSSQL = "mssql" DRIVER_NAME_REDIS = "redis" )
const ( DATABASE_KEY_NAME_WHERE = "WHERE" DATABASE_KEY_NAME_UPDATE = "UPDATE" DATABASE_KEY_NAME_SET = "SET" DATABASE_KEY_NAME_FROM = "FROM" DATABASE_KEY_NAME_DELETE = "DELETE" DATABASE_KEY_NAME_SELECT = "SELECT" DATABASE_KEY_NAME_DISTINCT = "DISTINCT" DATABASE_KEY_NAME_IN = "IN" DATABASE_KEY_NAME_NOT_IN = "NOT IN" DATABASE_KEY_NAME_OR = "OR" DATABASE_KEY_NAME_AND = "AND" DATABASE_KEY_NAME_INSERT = "INSERT INTO" DATABASE_KEY_NAME_VALUE = "VALUE" DATABASE_KEY_NAME_VALUES = "VALUES" )
const ( ORDER_BY_ASC = "asc" ORDER_BY_DESC = "desc" DEFAULT_CAHCE_EXPIRE_SECONDS = 24 * 60 * 60 DEFAULT_PRIMARY_KEY_NAME = "id" )
const ( ModelType_Struct = 1 ModelType_Slice = 2 ModelType_Map = 3 ModelType_BaseType = 4 )
const (
PROTOBUF_VALUE_NAME = "name"
)
const (
URL_SCHEME_SEP = "://"
)
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AdapterType ¶
type AdapterType int
const ( AdapterSqlx_MySQL AdapterType = 1 //sqlx: mysql AdapterSqlx_Postgres AdapterType = 2 //sqlx: postgresql AdapterSqlx_Sqlite AdapterType = 3 //sqlx: sqlite AdapterSqlx_Mssql AdapterType = 4 //sqlx: mssql server AdapterCache_Redis AdapterType = 11 //cache: redis )
func (AdapterType) DriverName ¶
func (a AdapterType) DriverName() string
func (AdapterType) GoString ¶
func (a AdapterType) GoString() string
func (AdapterType) String ¶
func (a AdapterType) String() string
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) Cache ¶ added in v1.0.2
set cache indexes. if null, the primary key (eg. 'id') will be cached to redis
func (*Engine) Debug ¶
debug mode on or off if debug on, some method will panic if your condition illegal
func (*Engine) ExecRaw ¶
func (e *Engine) ExecRaw(strQuery string, args ...interface{}) (rowsAffected, lastInsertId int64, err error)
use raw sql to insert/update database, results can not be cached to redis/memcached/memory... return rows affected and error, if err is not nil must be something wrong
func (*Engine) Insert ¶
orm insert return last insert id and error, if err is not nil must be something wrong NOTE: Model function is must be called before call this function
func (*Engine) Model ¶
orm model use to get result set, support single struct object or slice [pointer type] notice: will clone a new engine object for orm operations(query/update/insert/upsert)
func (*Engine) OnConflict ¶
set the conflict columns for upsert only for postgresql
func (*Engine) Open ¶
open a sqlx database or cache connection strUrl:
data source name
[mysql] Open("mysql://root:123456@127.0.0.1:3306/mydb?charset=utf8mb4") [postgres] Open("postgres://root:123456@127.0.0.1:5432/mydb?sslmode=disable") [sqlite] Open("sqlite:///var/lib/my.db") [mssql] Open("mssql://sa:123456@127.0.0.1:1433/mydb?instance=SQLExpress&windows=false")
cache config [redis-alone] Open("redis://123456@127.0.0.1:6379/cluster?db=0") [redis-cluster] Open("redis://123456@127.0.0.1:6379/cluster?db=0&replicate=127.0.0.1:6380,127.0.0.1:6381")
expireSeconds cache data expire seconds, just for redis
func (*Engine) Query ¶
orm query return rows affected and error, if err is not nil must be something wrong NOTE: Model function is must be called before call this function
func (*Engine) QueryMap ¶
use raw sql to query results into a map slice (model type is []map[string]string) return results and error NOTE: Model function is must be called before call this function
func (*Engine) QueryRaw ¶
use raw sql to query results return rows affected and error, if err is not nil must be something wrong NOTE: Model function is must be called before call this function
func (*Engine) SetCacheBefore ¶ added in v1.0.4
set cache update before database
func (*Engine) SetCustomTag ¶ added in v1.0.6
set your customer tag for db query/insert/update (eg. go structure generated by protobuf not contain 'db' tag) this function must calls before Model()
func (*Engine) SetLogFile ¶ added in v1.0.7
set log file
func (*Engine) TxRollback ¶ added in v1.0.3
func (*Engine) Update ¶
orm update from model strColumns... if set, columns will be updated, if none all columns in model will be updated except primary key return rows affected and error, if err is not nil must be something wrong NOTE: Model function is must be called before call this function
func (*Engine) Upsert ¶
orm insert or update if key(s) conflict return last insert id and error, if err is not nil must be something wrong, if your primary key is not a int/int64 type, maybe id return 0 NOTE: Model function is must be called before call this function and call OnConflict function when you are on postgresql
type ModelReflector ¶
type ModelReflector struct {
// contains filtered or unexported fields
}
func (*ModelReflector) ToMap ¶
func (s *ModelReflector) ToMap(tagName string) map[string]interface{}
parse struct tag and value to map
type OperType ¶
type OperType int
const ( OperType_Query OperType = 1 // orm: query sql OperType_Update OperType = 2 // orm: update sql OperType_Insert OperType = 3 // orm: insert sql OperType_Upsert OperType = 4 // orm: insert or update sql OperType_Tx OperType = 5 // orm: tx sql OperType_QueryRaw OperType = 6 // raw: query sql into model OperType_ExecRaw OperType = 7 // raw: insert/update sql OperType_QueryMap OperType = 8 // raw: query sql into map OperType_Delete OperType = 9 // orm: delete sql )