Documentation ¶
Index ¶
- Constants
- func All(expr interface{}) bson.M
- func ContextWithTimeout(timeoutSeconds int) (context.Context, context.CancelFunc)
- func ConvertValue(column string, value interface{}) (v interface{})
- func MakeObjectID(v interface{}) (id interface{})
- func Radian(meters uint64) float64
- func RoundColumn(strColumn string, place int) bson.M
- func Str2ObjectID(strId string) (id interface{})
- func Sum(expr interface{}) bson.M
- func ToBool(expr interface{}) bson.M
- func ToDate(expr interface{}) bson.M
- func ToDecimal(expr interface{}) bson.M
- func ToDouble(expr interface{}) bson.M
- func ToInt(expr interface{}) bson.M
- func ToLong(expr interface{}) bson.M
- func ToLower(expr interface{}) bson.M
- func ToObjectId(expr interface{}) bson.M
- func ToString(expr interface{}) bson.M
- func ToUpper(expr interface{}) bson.M
- type Coordinate
- type DateTime
- type Decimal
- func (d Decimal) Abs() Decimal
- func (d Decimal) Add(d2 interface{}) Decimal
- func (d Decimal) Amount2Btc() Decimal
- func (d Decimal) Amount2Coin(prec int) Decimal
- func (d Decimal) Amount2Ether() Decimal
- func (d Decimal) Amount2FIL() Decimal
- func (d Decimal) BigInt() (b *big.Int, ok bool)
- func (d Decimal) Btc2Amount() Decimal
- func (d Decimal) Cmp(d2 interface{}) int
- func (d Decimal) Coin2Amount(prec int) Decimal
- func (d Decimal) Cos() Decimal
- func (d Decimal) Div(d2 interface{}) Decimal
- func (d Decimal) Equal(d2 interface{}) bool
- func (d Decimal) Ether2Amount() Decimal
- func (d Decimal) FIL2Amount() Decimal
- 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 interface{}) bool
- func (d Decimal) GreaterThanOrEqual(d2 interface{}) 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 interface{}) bool
- func (d Decimal) LessThanOrEqual(d2 interface{}) bool
- func (d Decimal) MarshalBSON() ([]byte, error)
- func (d Decimal) MarshalBSONValue() (bsontype.Type, []byte, error)
- 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 interface{}) Decimal
- func (d Decimal) Mul(d2 interface{}) Decimal
- func (d Decimal) Neg() Decimal
- func (d Decimal) Pow(d2 interface{}) Decimal
- func (d Decimal) Round(places int32) Decimal
- func (d *Decimal) Scan(src 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 interface{}) Decimal
- func (d Decimal) Sum(rest ...Decimal) Decimal
- func (d Decimal) Tan() Decimal
- func (d Decimal) Truncate(precision int32) Decimal
- func (d *Decimal) UnmarshalBSON(data []byte) error
- func (d *Decimal) UnmarshalBSONValue(bt bsontype.Type, data []byte) error
- 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 Decimal128
- type Engine
- func (e *Engine) Aggregate() (err error)
- func (e *Engine) And(strColumn string, value interface{}) *Engine
- func (e *Engine) Array(strColumn string, value []interface{}) *Engine
- func (e *Engine) Asc(strColumns ...string) *Engine
- func (e *Engine) Avg(strColumn string, values ...interface{}) *Engine
- func (e *Engine) Close() error
- func (e *Engine) Collection(strName string, opts ...*options.CollectionOptions) *mongo.Collection
- func (e *Engine) Count() (rows int64, err error)
- func (e *Engine) Database() *mongo.Database
- func (e *Engine) Debug(on bool)
- func (e *Engine) Delete() (rows int64, err error)
- func (e *Engine) Desc(strColumns ...string) *Engine
- func (e *Engine) ElemMatch(strColumn string, value interface{}) *Engine
- func (e *Engine) Eq(strColumn string, value interface{}) *Engine
- func (e *Engine) Equal(strColumn string, value interface{}) *Engine
- func (e *Engine) Except(strColumns ...string) *Engine
- func (e *Engine) Exists(strColumn string, value bool) *Engine
- func (e *Engine) Filter(filter bson.M) *Engine
- func (e *Engine) FindOne() (err error)
- func (e *Engine) FindOneDelete() (res *mongo.SingleResult, err error)
- func (e *Engine) FindOneReplace() (res *mongo.SingleResult, err error)
- func (e *Engine) FindOneUpdate() (res *mongo.SingleResult, err error)
- func (e *Engine) GeoCenterSphere(strColumn string, pos Coordinate, distance int) *Engine
- func (e *Engine) GeoNearByPoint(strColumn string, pos Coordinate, maxDistance int, disFieldName string) *Engine
- func (e *Engine) Geometry(strColumn string, geometry *Geometry) *Engine
- func (e *Engine) GroupBy(exprs ...interface{}) *Engine
- func (e *Engine) Gt(strColumn string, value interface{}) *Engine
- func (e *Engine) GtLt(strColumn string, value1, value2 interface{}) *Engine
- func (e *Engine) GtLte(strColumn string, value1, value2 interface{}) *Engine
- func (e *Engine) Gte(strColumn string, value interface{}) *Engine
- func (e *Engine) GteLt(strColumn string, value1, value2 interface{}) *Engine
- func (e *Engine) GteLte(strColumn string, value1, value2 interface{}) *Engine
- func (e *Engine) Id(v interface{}) *Engine
- func (e *Engine) In(strColumn string, value interface{}) *Engine
- func (e *Engine) Insert() ([]interface{}, error)
- func (e *Engine) Limit(n int) *Engine
- func (e *Engine) Lt(strColumn string, value interface{}) *Engine
- func (e *Engine) Lte(strColumn string, value interface{}) *Engine
- func (e *Engine) Max(strColumn string, values ...interface{}) *Engine
- func (e *Engine) Min(strColumn string, values ...interface{}) *Engine
- func (e *Engine) Model(args ...interface{}) *Engine
- func (e *Engine) Ne(strColumn string, value interface{}) *Engine
- func (e *Engine) Options(options ...interface{}) *Engine
- func (e *Engine) Or(strColumn string, value interface{}) *Engine
- func (e *Engine) Page(pageNo, pageSize int) *Engine
- func (e *Engine) Pipeline(pipelines ...bson.D) *Engine
- func (e *Engine) PrimaryKey() string
- func (e *Engine) Query() (err error)
- func (e *Engine) QueryEx() (total int64, err error)
- func (e *Engine) Regex(strColumn string, value interface{}) *Engine
- func (e *Engine) Round(strColumn string, place int, alias ...string) *Engine
- func (e *Engine) Select(strColumns ...string) *Engine
- func (e *Engine) Set(strColumn string, value interface{}) *Engine
- func (e *Engine) SetReadTimeout(timeoutSeconds int)
- func (e *Engine) SetWriteTimeout(timeoutSeconds int)
- func (e *Engine) Sum(strColumn string, values ...interface{}) *Engine
- func (e *Engine) Table(strName string) *Engine
- func (e *Engine) Unwind(obj interface{}) *Engine
- func (e *Engine) Update() (rows int64, err error)
- func (e *Engine) UpdateOne() (rows int64, err error)
- func (e *Engine) Upsert() (rows int64, err error)
- func (e *Engine) Use(strDatabase string, opts ...*options.DatabaseOptions) *Engine
- type FloatArray
- type FloatArray2
- type FloatArray3
- type FloatArray4
- type GeoLineString
- type GeoMultiLineString
- type GeoMultiPoint
- type GeoMultiPolygon
- type GeoPoint
- type GeoPolygon
- type GeoType
- type Geometry
- type ModelReflector
- type ModelType
- type ObjectID
- type Option
- type SSH
- type UrlInfo
Constants ¶
const ( KeyIn = "$in" KeyEqual = "$eq" KeyAnd = "$and" KeyOr = "$or" KeyGreaterThan = "$gt" KeyGreaterThanEqual = "$gte" KeyLessThan = "$lt" KeyLessThanEqual = "$lte" KeyNotEqual = "$ne" KeyExists = "$exists" KeyRegex = "$regex" KeySet = "$set" KeyElemMatch = "$elemMatch" KeyMatch = "$match" KeyGroup = "$group" KeyHaving = "$having" KeyProject = "$project" KeySort = "$sort" KeySkip = "$skip" KeyLimit = "$limit" KeySum = "$sum" KeyAll = "$all" KeyNear = "$near" KeyGeoNear = "$geoNear" KeyGeoWithin = "$geoWithin" KeyCenter = "$center" KeyCenterSphere = "$centerSphere" KeyGeoIntersects = "$geoIntersects" KeyNearSphere = "$nearSphere" KeyGeoMetry = "$geometry" KeyMaxDistance = "$maxDistance" KeyMax = "$max" KeyMin = "$min" KeyAvg = "$avg" KeyMod = "$mod" KeyAbs = "$abs" KeyUnwind = "$unwind" KeyRound = "$round" )
const ( ModelType_Struct = 1 ModelType_Slice = 2 ModelType_Map = 3 ModelType_BaseType = 4 )
const ( TAG_VALUE_NULL = "" TAG_VALUE_IGNORE = "-" //ignore )
const ( URL_SCHEME_SEP = "://" URL_QUERY_SLAVE = "slave" URL_QUERY_MAX = "max" URL_QUERY_IDLE = "idle" URL_QUERY_CHARSET = "charset" )
const ( OfficalObjectIdSize = 24 MgoV2ObjectIdSize = 48 )
const (
TAG_NAME_BSON = "bson"
)
Variables ¶
This section is empty.
Functions ¶
func ContextWithTimeout ¶
func ContextWithTimeout(timeoutSeconds int) (context.Context, context.CancelFunc)
func ConvertValue ¶ added in v0.5.0
func ConvertValue(column string, value interface{}) (v interface{})
func MakeObjectID ¶ added in v1.0.0
func MakeObjectID(v interface{}) (id interface{})
func Str2ObjectID ¶ added in v0.5.0
func Str2ObjectID(strId string) (id interface{})
func ToObjectId ¶ added in v0.5.4
Types ¶
type Coordinate ¶ added in v0.6.0
type DateTime ¶ added in v0.7.2
func NewDateTimeFromTime ¶ added in v0.7.2
type Decimal ¶
type Decimal struct {
// contains filtered or unexported fields
}
func NewDecimal ¶
func NewDecimal(v interface{}) (d Decimal)
func (Decimal) Amount2Btc ¶
func (Decimal) Amount2Coin ¶
func (Decimal) Amount2Ether ¶
func (Decimal) Amount2FIL ¶
func (Decimal) Btc2Amount ¶
func (Decimal) Cmp ¶
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) Coin2Amount ¶
func (Decimal) Div ¶
Div returns d / d2. If it doesn't divide exactly, the result will have DivisionPrecision digits after the decimal point.
func (Decimal) Ether2Amount ¶
func (Decimal) FIL2Amount ¶
func (Decimal) Float64 ¶
Float64 returns the nearest float64 value for d and a bool indicating whether f represents d exactly.
func (*Decimal) FromString ¶
func (Decimal) GreaterThan ¶
GreaterThan (GT) returns true when d is greater than d2.
func (Decimal) GreaterThanOrEqual ¶
GreaterThanOrEqual (GTE) returns true when d is greater than or equal to d2.
func (Decimal) LessThanOrEqual ¶
LessThanOrEqual (LTE) returns true when d is less than or equal to d2.
func (Decimal) MarshalBSON ¶ added in v0.1.1
MarshalBSON implements the bson.Marshaler interface.
func (Decimal) MarshalBSONValue ¶ added in v0.1.7
MarshalBSONValue implements the bson.Marshaler interface.
func (Decimal) MarshalBinary ¶
MarshalBinary implements the encoding.BinaryMarshaler interface.
func (Decimal) MarshalJSON ¶
MarshalJSON implements the json.Marshaler interface.
func (Decimal) MarshalText ¶
MarshalText implements the encoding.TextMarshaler interface for XML serialization.
func (Decimal) Max ¶
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 ¶
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 ¶
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) String ¶
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 ¶
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 ¶
StringScaled first scales the decimal then calls .String() on it. NOTE: buggy, unintuitive, and DEPRECATED! Use StringFixed instead.
func (Decimal) Truncate ¶
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) UnmarshalBSON ¶ added in v0.1.1
func (*Decimal) UnmarshalBSONValue ¶ added in v0.1.7
UnmarshalBSONValue implements the bson.Unmarshaler interface.
func (*Decimal) UnmarshalBinary ¶
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 ¶
UnmarshalJSON implements the json.Unmarshaler interface.
func (*Decimal) UnmarshalText ¶
UnmarshalText implements the encoding.TextUnmarshaler interface for XML deserialization.
type Decimal128 ¶ added in v0.7.2
type Decimal128 = primitive.Decimal128
func NewDecimal128 ¶ added in v0.7.2
func NewDecimal128(high, low uint64) Decimal128
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
func (*Engine) Collection ¶
func (e *Engine) Collection(strName string, opts ...*options.CollectionOptions) *mongo.Collection
Collection get collection instance specified
func (*Engine) FindOneDelete ¶ added in v0.6.0
func (e *Engine) FindOneDelete() (res *mongo.SingleResult, err error)
FindOneDelete find single document and delete
func (*Engine) FindOneReplace ¶ added in v0.6.0
func (e *Engine) FindOneReplace() (res *mongo.SingleResult, err error)
FindOneReplace find single document and replace
func (*Engine) FindOneUpdate ¶ added in v0.6.0
func (e *Engine) FindOneUpdate() (res *mongo.SingleResult, err error)
FindOneUpdate find single document and update
func (*Engine) GeoCenterSphere ¶ added in v0.6.0
func (e *Engine) GeoCenterSphere(strColumn string, pos Coordinate, distance int) *Engine
GeoCenterSphere query by coordinate and distance in meters (sphere)
func (*Engine) GeoNearByPoint ¶ added in v0.6.1
func (e *Engine) GeoNearByPoint(strColumn string, pos Coordinate, maxDistance int, disFieldName string) *Engine
GeoNearByPoint query and return matched records with max distance in meters (just one index, 2d or 2dshpere) strColumn: the column which include location pos: the position to query maxDistance: the maximum distance nearby pos (meters) includeLocs: the column name which include location disFieldName: distance column name to return
func (*Engine) GroupBy ¶ added in v0.9.0
GroupBy group by expressions with string, bson.M and bson.D
func (*Engine) Model ¶
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) PrimaryKey ¶ added in v0.1.12
func (*Engine) Query ¶
Query orm query return error if err is not nil must be something wrong NOTE: Model function is must be called before call this function
func (*Engine) QueryEx ¶
QueryEx orm query and return total records count return total and error, if err is not nil must be something wrong NOTE: Model function is must be called before call this function, do not call this on aggregate operations
func (*Engine) Round ¶ added in v1.2.0
Round aggregation round number for $project, place number range -20 ~ 100
func (*Engine) SetReadTimeout ¶ added in v0.9.4
func (*Engine) SetWriteTimeout ¶ added in v0.9.4
type FloatArray ¶ added in v0.6.0
type FloatArray = []float64
type FloatArray2 ¶ added in v0.6.0
type FloatArray2 = []FloatArray
type FloatArray3 ¶ added in v0.6.0
type FloatArray3 = []FloatArray2
type FloatArray4 ¶ added in v0.6.0
type FloatArray4 = []FloatArray3
type GeoLineString ¶ added in v0.6.0
type GeoLineString struct { Type GeoType `json:"type" bson:"type"` Coordinates FloatArray2 `json:"coordinates" bson:"coordinates"` }
func NewGeoLineString ¶ added in v0.6.0
func NewGeoLineString(coords []Coordinate) *GeoLineString
type GeoMultiLineString ¶ added in v0.6.0
type GeoMultiLineString struct { Type GeoType `json:"type" bson:"type"` Coordinates FloatArray3 `json:"coordinates" bson:"coordinates"` }
func NewGeoMultiLineString ¶ added in v0.6.0
func NewGeoMultiLineString(coords [][]Coordinate) *GeoMultiLineString
type GeoMultiPoint ¶ added in v0.6.0
type GeoMultiPoint struct { Type GeoType `json:"type" bson:"type"` Coordinates FloatArray2 `json:"coordinates" bson:"coordinates"` }
func NewGeoMultiPoint ¶ added in v0.6.0
func NewGeoMultiPoint(coords []Coordinate) *GeoMultiPoint
type GeoMultiPolygon ¶ added in v0.6.0
type GeoMultiPolygon struct { Type GeoType `json:"type" bson:"type"` Coordinates FloatArray4 `json:"coordinates" bson:"coordinates"` }
func NewGeoMultiPolygon ¶ added in v0.6.0
func NewGeoMultiPolygon(coords [][][]Coordinate) *GeoMultiPolygon
type GeoPoint ¶ added in v0.6.0
type GeoPoint struct { Type GeoType `json:"type" bson:"type"` Coordinates FloatArray `json:"coordinates" bson:"coordinates"` }
func NewGeoPoint ¶ added in v0.6.0
func NewGeoPoint(coord Coordinate) *GeoPoint
type GeoPolygon ¶ added in v0.6.0
type GeoPolygon struct { Type GeoType `json:"type" bson:"type"` Coordinates FloatArray3 `json:"coordinates" bson:"coordinates"` }
func NewGeoPolygon ¶ added in v0.6.0
func NewGeoPolygon(coords [][]Coordinate) *GeoPolygon
type Geometry ¶ added in v0.6.0
type Geometry struct { Type GeoType `json:"type" bson:"type"` Coordinates interface{} `json:"coordinates" bson:"coordinates"` }
func NewGeoMetry ¶ added in v0.6.0
type ModelReflector ¶
type ModelReflector struct {
// contains filtered or unexported fields
}
func (*ModelReflector) ToMap ¶
func (s *ModelReflector) ToMap() map[string]interface{}
parse struct tag and value to map
type ObjectID ¶ added in v0.5.0
func NewObjectID ¶ added in v0.7.0
func NewObjectID() ObjectID
func NewObjectIDFromString ¶ added in v0.7.2
func NewObjectIDFromTimestamp ¶ added in v0.7.2
type Option ¶ added in v0.1.1
type Option struct { Debug bool // enable debug mode Max int // max active connections Idle int // max idle connections SSH *SSH // SSH tunnel server config ConnectTimeout int // connect timeout WriteTimeout int // write timeout seconds ReadTimeout int // read timeout seconds DatabaseOpt *options.DatabaseOptions // database options }
type SSH ¶
type SSH struct { User string //SSH tunnel server login account Password string //SSH tunnel server login password PrivateKey string //SSH tunnel server private key, eg. "/home/test/.ssh/private-key.pem" Host string //SSH tunnel server host [ip or domain], default port 22 if not specified // contains filtered or unexported fields }