Documentation ¶
Index ¶
- Constants
- type AdapterType
- type Engine
- func (e *Engine) Asc() *Engine
- func (e *Engine) Debug(ok bool)
- func (e *Engine) Desc() *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) Index(strColumn string, value 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) Offset(offset int) *Engine
- func (e *Engine) OnConflict(strColumns ...string) *Engine
- func (e *Engine) Open(adapterType AdapterType, 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) SetPkName(strName string) *Engine
- func (e *Engine) Table(strName string) *Engine
- func (e *Engine) Update() (rowsAffected int64, err error)
- func (e *Engine) Upsert() (lastInsertId int64, err error)
- func (e *Engine) UseCache() *Engine
- func (e *Engine) Where(strWhere string) *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 = "sqlx:cache" )
const ( ValueType_Data valueType = 1 // data of table ValueType_Index valueType = 2 // index of data )
const ( TAG_NAME_DB = "db" DRIVER_NAME_MYSQL = "mysql" DRIVER_NAME_POSTGRES = "postgres" DRIVER_NAME_SQLITE = "sqlite3" DRIVER_NAME_MSSQL = "adodb" DRIVER_NAME_REDIS = "redis" )
const ( ORDER_BY_ASC = "asc" ORDER_BY_DESC = "desc" DEFAULT_CAHCE_EXPIRE_SECONDS = 60 * 60 DEFAULT_PRIMARY_KEY_NAME = "id" SQLX_IGNORE_CREATED_AT = "created_at" SQLX_IGNORE_UPDATED_AT = "updated_at" )
const ( ModelType_Struct = 1 ModelType_Slice = 2 ModelType_Map = 3 ModelType_BaseType = 4 )
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) 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) Index ¶
index which select from cache or update to cache if your index is not a primary key, it will create a cache index and pointer to primary key data index or data in cache key is 'sqlx:cache:[table name]:[column name]:[column value]', eg. 'sqlx:cache:users:phone:8613055556666'
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 ¶
func (e *Engine) Open(adapterType AdapterType, strUrl string, expireSeconds ...int) *Engine
open a sqlx database or cache connection strUrl:
data source name
[mysql] Open(AdapterSqlx_MySQL, "mysql://root:123456@127.0.0.1:3306/mydb?charset=utf8mb4") [postgres] Open(AdapterSqlx_Postgres, "postgres://root:123456@127.0.0.1:5432/mydb?sslmode=disable") [sqlite] Open(AdapterSqlx_Sqlite, "sqlite:///var/lib/my.db") [mssql] Open(AdapterSqlx_Mssql, "mssql://sa:123456@127.0.0.1:1433/mydb?instance=&windows=false")
cache config [redis-alone] Open(AdapterTypeCache_Redis, "redis://123456@127.0.0.1:6379/cluster?db=0") [redis-cluster] Open(AdapterTypeCache_Redis, "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 AdapterTypeCache_XXX
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) 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_QueryRaw OperType = 5 // raw: query sql into model OperType_ExecRaw OperType = 6 // raw: insert/update sql OperType_QueryMap OperType = 7 // raw: query sql into map )