Documentation ¶
Index ¶
- Constants
- type AdapterType
- type Decimal
- func (d Decimal) Abs() Decimal
- func (d Decimal) Add(d2 Decimal) Decimal
- func (d Decimal) Cmp(d2 Decimal) int
- func (d Decimal) Cos() Decimal
- func (d Decimal) Div(d2 Decimal) Decimal
- func (d Decimal) Equal(d2 Decimal) bool
- func (d Decimal) Float64() (f float64)
- func (d *Decimal) FromFloat(v float64)
- func (d *Decimal) FromInt(v int64)
- func (d *Decimal) FromString(v string)
- func (d Decimal) GreaterThan(d2 Decimal) bool
- func (d Decimal) GreaterThanOrEqual(d2 Decimal) bool
- func (d Decimal) IntPart() int64
- func (d Decimal) IsNegative() bool
- func (d Decimal) IsPositive() bool
- func (d Decimal) IsZero() bool
- func (d Decimal) LessThan(d2 Decimal) bool
- func (d Decimal) LessThanOrEqual(d2 Decimal) bool
- func (d Decimal) MarshalBinary() (data []byte, err error)
- func (d Decimal) MarshalJSON() ([]byte, error)
- func (d Decimal) MarshalText() (text []byte, err error)
- func (d Decimal) Max(rest ...Decimal) Decimal
- func (d Decimal) Min(rest ...Decimal) Decimal
- func (d Decimal) Mod(d2 Decimal) Decimal
- func (d Decimal) Mul(d2 Decimal) Decimal
- func (d Decimal) Neg() Decimal
- func (d Decimal) Pow(d2 Decimal) Decimal
- func (d Decimal) Round(places int32) Decimal
- func (d *Decimal) Scan(value interface{}) error
- func (d Decimal) Sign() int
- func (d Decimal) Sin() Decimal
- func (d Decimal) String() string
- func (d Decimal) StringFixed(places int32) string
- func (d Decimal) StringScaled(exp int32) string
- func (d Decimal) Sub(d2 Decimal) Decimal
- func (d Decimal) Sum(rest ...Decimal) Decimal
- func (d Decimal) Tan() Decimal
- func (d Decimal) Truncate(precision int32) Decimal
- func (d *Decimal) UnmarshalBinary(data []byte) error
- func (d *Decimal) UnmarshalJSON(decimalBytes []byte) error
- func (d *Decimal) UnmarshalText(text []byte) error
- func (d Decimal) Value() (driver.Value, error)
- type Engine
- func (e *Engine) And(strFmt string, args ...interface{}) *Engine
- func (e *Engine) Asc(strColumns ...string) *Engine
- func (e *Engine) Attach(strDatabaseName string, db *sqlx.DB) *Engine
- func (e *Engine) Cache(indexes ...string) *Engine
- func (e *Engine) Count() (count int64, err error)
- func (e *Engine) Debug(ok bool)
- func (e *Engine) Delete() (rowsAffected int64, err error)
- func (e *Engine) Desc(strColumns ...string) *Engine
- func (e *Engine) Distinct() *Engine
- func (e *Engine) ExecRaw(strQuery string, args ...interface{}) (rowsAffected, lastInsertId int64, err error)
- func (e *Engine) Find(conditions map[string]interface{}) (rowsAffected int64, err error)
- func (e *Engine) Force() *Engine
- func (e *Engine) GetPkName() string
- func (e *Engine) GroupBy(strColumns ...string) *Engine
- func (e *Engine) Having(strFmt string, args ...interface{}) *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, options ...interface{}) *Engine
- func (e *Engine) Or(strFmt string, args ...interface{}) *Engine
- func (e *Engine) OrderBy(strColumns ...string) *Engine
- func (e *Engine) Ping() (err error)
- 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) SetReadOnly(columns ...string)
- func (e *Engine) Slave() *Engine
- func (e *Engine) Table(strNames ...string) *Engine
- func (e *Engine) ToSQL(operType OperType) (strSql string)
- 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) SQLCA_TAG_VALUE_IGNORE = "-" //ignore )
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" DATABASE_KEY_NAME_FOR_UPDATE = "FOR UPDATE" DATABASE_KEY_NAME_ORDER_BY = "ORDER BY" DATABASE_KEY_NAME_ASC = "ASC" DATABASE_KEY_NAME_DESC = "DESC" DATABASE_KEY_NAME_HAVING = "HAVING" )
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 ( URL_SCHEME_SEP = "://" URL_QUERY_SLAVE = "slave" URL_QUERY_MAX = "max" )
const (
PROTOBUF_VALUE_NAME = "name"
)
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 Decimal ¶ added in v1.1.5
type Decimal struct {
// contains filtered or unexported fields
}
func NewDecimal ¶ added in v1.1.5
func NewDecimal(v interface{}) (d Decimal)
func (Decimal) Cmp ¶ added in v1.1.5
Cmp compares the numbers represented by d and d2 and returns:
-1 if d < d2 0 if d == d2 +1 if d > d2
func (Decimal) Div ¶ added in v1.1.5
Div returns d / d2. If it doesn't divide exactly, the result will have DivisionPrecision digits after the decimal point.
func (Decimal) Equal ¶ added in v1.1.5
Equal returns whether the numbers represented by d and d2 are equal.
func (Decimal) Float64 ¶ added in v1.1.5
Float64 returns the nearest float64 value for d and a bool indicating whether f represents d exactly.
func (*Decimal) FromString ¶ added in v1.1.5
func (Decimal) GreaterThan ¶ added in v1.1.5
GreaterThan (GT) returns true when d is greater than d2.
func (Decimal) GreaterThanOrEqual ¶ added in v1.1.5
GreaterThanOrEqual (GTE) returns true when d is greater than or equal to d2.
func (Decimal) IsNegative ¶ added in v1.1.5
IsNegative return
true if d < 0 false if d == 0 false if d > 0
func (Decimal) IsPositive ¶ added in v1.1.5
IsPositive return
true if d > 0 false if d == 0 false if d < 0
func (Decimal) LessThanOrEqual ¶ added in v1.1.5
LessThanOrEqual (LTE) returns true when d is less than or equal to d2.
func (Decimal) MarshalBinary ¶ added in v1.1.5
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (Decimal) MarshalJSON ¶ added in v1.1.5
MarshalJSON implements the json.Marshaler interface.
func (Decimal) MarshalText ¶ added in v1.1.5
MarshalText implements the encoding.TextMarshaler interface for XML serialization.
func (Decimal) Max ¶ added in v1.1.5
Max returns the largest Decimal that was passed in the arguments. To call this function with an array, you must do: This makes it harder to accidentally call Max with 0 arguments.
func (Decimal) Min ¶ added in v1.1.5
Min returns the smallest Decimal that was passed in the arguments. To call this function with an array, you must do: This makes it harder to accidentally call Min with 0 arguments.
func (Decimal) Round ¶ added in v1.1.5
Round rounds the decimal to places decimal places. If places < 0, it will round the integer part to the nearest 10^(-places).
Example:
NewFromFloat(5.45).Round(1).String() // output: "5.5" NewFromFloat(545).Round(-1).String() // output: "550"
func (*Decimal) Scan ¶ added in v1.1.5
Scan implements the sql.Scanner interface for database deserialization.
func (Decimal) String ¶ added in v1.1.5
String returns the string representation of the decimal with the fixed point.
Example:
d := New(-12345, -3) println(d.String())
Output:
-12.345
func (Decimal) StringFixed ¶ added in v1.1.5
StringFixed returns a rounded fixed-point string with places digits after the decimal point.
Example:
NewFromFloat(0).StringFixed(2) // output: "0.00" NewFromFloat(0).StringFixed(0) // output: "0" NewFromFloat(5.45).StringFixed(0) // output: "5" NewFromFloat(5.45).StringFixed(1) // output: "5.5" NewFromFloat(5.45).StringFixed(2) // output: "5.45" NewFromFloat(5.45).StringFixed(3) // output: "5.450" NewFromFloat(545).StringFixed(-1) // output: "550"
func (Decimal) StringScaled ¶ added in v1.1.5
StringScaled first scales the decimal then calls .String() on it. NOTE: buggy, unintuitive, and DEPRECATED! Use StringFixed instead.
func (Decimal) Sum ¶ added in v1.1.5
Sum returns the combined total of the provided first and rest Decimals
func (Decimal) Truncate ¶ added in v1.1.5
Truncate truncates off digits from the number, without rounding.
NOTE: precision is the last digit that will not be truncated (must be >= 0).
Example:
decimal.NewFromString("123.456").Truncate(2).String() // "123.45"
func (*Decimal) UnmarshalBinary ¶ added in v1.1.5
UnmarshalBinary implements the encoding.BinaryUnmarshaler interface. As a string representation is already used when encoding to text, this method stores that string as []byte
func (*Decimal) UnmarshalJSON ¶ added in v1.1.5
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Decimal) UnmarshalText ¶ added in v1.1.5
UnmarshalText implements the encoding.TextUnmarshaler interface for XML deserialization.
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func NewEngine ¶
func NewEngine(strUrl ...interface{}) *Engine
args: a url format string for database driver eg. "mysql://root:123456@127.0.0.1/test?charset=utf8mb4" more detail see Open method
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) Count ¶ added in v1.1.18
orm count records SELECT COUNT(*) FROM table WHERE ... count, err := e.Model(nil).Table("users").Where("delete=1").Count()
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 database or cache connection pool strUrl:
data source name
[mysql] Open("mysql://root:123456@127.0.0.1:3306/test?charset=utf8mb4&slave=false&max=100") [postgres] Open("postgres://root:123456@127.0.0.1:5432/test?sslmode=disable&slave=false&max=100") [mssql] Open("mssql://sa:123456@127.0.0.1:1433/mydb?instance=SQLExpress&windows=false&max=100") [sqlite] Open("sqlite:///var/lib/test.db")
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")
options:
- specify master or slave, MySQL/Postgres (bool)
- cache data expire seconds, just for redis (integer)
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 if slave == true, try query from a slave connection, if not exist query from master
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) SetReadOnly ¶ added in v1.1.14
set read only columns
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(tagNames ...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 OperType_ForUpdate OperType = 10 // orm: select ... for update sql )