本文整理匯總了Golang中github.com/eaciit/dbox.Eq函數的典型用法代碼示例。如果您正苦於以下問題:Golang Eq函數的具體用法?Golang Eq怎麽用?Golang Eq使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Eq函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: ConnectToSedotanServer
func (w *WebGrabberController) ConnectToSedotanServer() (*SshSetting, *colonycore.Server, error) {
filter := dbox.And(dbox.Eq("os", "linux"), dbox.Eq("serverType", "node"))
cursor, err := colonycore.Find(new(colonycore.Server), filter)
if err != nil {
return nil, nil, err
}
data := []colonycore.Server{}
err = cursor.Fetch(&data, 0, true)
if err != nil {
return nil, nil, err
}
if len(data) == 0 {
return nil, nil, errors.New("No sedotan server found")
}
server := data[0]
var client SshSetting
client.SSHHost = server.Host
client.SSHAuthType = SSHAuthType_Password
client.SSHUser = server.SSHUser
client.SSHPassword = server.SSHPass
return &client, &server, nil
}
示例2: FindDataGrabber
func (d *DataGrabberController) FindDataGrabber(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
//~ payload := map[string]string{"inputText":"test"}
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
text := payload["inputText"].(string)
textLow := strings.ToLower(text)
var query *dbox.Filter
valueInt, errv := strconv.Atoi(text)
fmt.Printf("", valueInt)
fmt.Printf("", errv)
if errv == nil {
// == try useing Eq for support integer
query = dbox.Or(dbox.Eq("GrabInterval", valueInt), dbox.Eq("TimeoutInterval", valueInt))
} else {
// == try useing Contains for support autocomplite
query = dbox.Or(dbox.Contains("_id", text), dbox.Contains("_id", textLow), dbox.Contains("DataSourceOrigin", text), dbox.Contains("DataSourceOrigin", textLow), dbox.Contains("DataSourceDestination", text), dbox.Contains("DataSourceDestination", textLow), dbox.Contains("IntervalType", text), dbox.Contains("IntervalType", textLow))
}
data := []colonycore.DataGrabber{}
cursor, err := colonycore.Find(new(colonycore.DataGrabber), query)
cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}
示例3: TestSelectFilter
func TestSelectFilter(t *testing.T) {
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
return
}
defer c.Close()
csr, e := c.NewQuery().
Select("id", "name").
Where(dbox.And(dbox.Eq("id", "1"), (dbox.Eq("name", "a")))).
From("tes").Cursor(nil)
if e != nil {
t.Errorf("Cursor pre error: %s \n", e.Error())
return
}
if csr == nil {
t.Errorf("Cursor not initialized")
return
}
defer csr.Close()
//rets := []toolkit.M{}
ds, e := csr.Fetch(nil, 0, false)
if e != nil {
t.Errorf("Unable to fetch: %s \n", e.Error())
} else {
fmt.Printf("Fetch N OK. Result: %v \n",
ds.Data)
}
}
示例4: TestSelectFilter
func TestSelectFilter(t *testing.T) {
t.Skip()
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
return
}
defer c.Close()
csr, e := c.NewQuery().
Select("empno", "ename", "mgr", "hiredate").
Where(dbox.Or(dbox.Eq("empno", 7521), dbox.Eq("ename", "ADAMS"))).
From(tableName).Cursor(nil)
if e != nil {
t.Errorf("Cursor pre error: %s \n", e.Error())
return
}
if csr == nil {
t.Errorf("Cursor not initialized")
return
}
defer csr.Close()
rets := /*[]customers{}*/ []toolkit.M{}
e = csr.Fetch(&rets, 0, false)
if e != nil {
t.Errorf("Unable to fetch: %s \n", e.Error())
} else {
toolkit.Printf("Filter OK. Result: %v \n", toolkit.JsonString(rets))
}
}
示例5: RemoveDataSource
func (d *DataSourceController) RemoveDataSource(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
id := payload["_id"].(string)
dg := new(colonycore.DataGrabber)
filter := dbox.Or(dbox.Eq("DataSourceOrigin", id), dbox.Eq("DataSourceDestination", id))
cursor, err := colonycore.Find(dg, filter)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
if cursor.Count() > 0 {
return helper.CreateResult(false, nil, "Cannot delete data source because used on data grabber")
}
o := new(colonycore.DataSource)
o.ID = id
err = colonycore.Delete(o)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
return helper.CreateResult(true, nil, "")
}
示例6: TestDelete
func TestDelete(t *testing.T) {
t.Skip()
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
return
}
defer c.Close()
e = c.NewQuery().From("students").Where(dbox.And(dbox.Eq("name", "dwayne johnson"), dbox.Eq("age", 32))).Delete().Exec(nil)
// e = c.NewQuery().From("students").Where(dbox.Eq("name", "dwayne johnson")).Delete().Exec(nil)
if e != nil {
t.Errorf("Unable to delete table %s\n", e.Error())
return
}
/* ===============================CLEAR ALL TABLE DATA==============================*/
// e = c.NewQuery().SetConfig("multiexec", true).
// From("coba").Delete().Exec(nil)
// if e != nil {
// t.Errorf("Unable to clear table %s\n", e.Error())
// return
// }
}
示例7: UninstallLang
func (l *LangenvironmentController) UninstallLang(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := new(colonycore.LanguageEnvironmentPayload)
err := r.GetPayload(payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
dataServers := new(colonycore.Server)
err = colonycore.Get(dataServers, payload.ServerId)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
serverPathSeparator := CreateApplicationController(l.Server).GetServerPathSeparator(dataServers)
sshSetting, sshClient, err := dataServers.Connect()
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer sshClient.Close()
var query *dbox.Filter
if payload.Lang == LANG_SCALA {
var IsInstalled bool
for _, eachLang := range dataServers.InstalledLang {
if eachLang.Lang == LANG_JAVA {
IsInstalled = eachLang.IsInstalled
break
}
}
if !IsInstalled {
query = dbox.Or(dbox.Eq("language", LANG_JAVA), dbox.Eq("language", LANG_SCALA))
} else {
query = dbox.Eq("language", payload.Lang)
}
} else {
query = dbox.Eq("language", payload.Lang)
}
result, err := l.ProcessSetup(dataServers, query, serverPathSeparator, sshSetting)
if err != nil {
helper.CreateResult(false, nil, err.Error())
}
fmt.Println("result :: ", result)
for _, eachLang := range dataServers.InstalledLang {
if eachLang.Lang == payload.Lang {
eachLang.IsInstalled = false
break
}
}
err = colonycore.Save(dataServers)
if err != nil {
helper.CreateResult(false, nil, err.Error())
}
return helper.CreateResult(true, payload, "")
}
示例8: TestFilter
func TestFilter(t *testing.T) {
fb := dbox.NewFilterBuilder(new(FilterBuilder))
fb.AddFilter(dbox.Or(
dbox.Eq("_id", 1),
dbox.Eq("group", "administrators")))
b, e := fb.Build()
if e != nil {
t.Errorf("Error %s", e.Error())
} else {
fmt.Printf("Result:\n%v\n", toolkit.JsonString(b))
}
}
示例9: GetServers
func (s *ServerController) GetServers(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
payload := struct {
Search string `json:"search"`
ServerOS string `json:"serverOS"`
ServerType string `json:"serverType"`
SSHType string `json:"sshType"`
}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
filters := []*dbox.Filter{}
if payload.Search != "" {
filters = append(filters, dbox.Or(
dbox.Contains("_id", payload.Search),
dbox.Contains("os", payload.Search),
dbox.Contains("host", payload.Search),
dbox.Contains("serverType", payload.Search),
dbox.Contains("sshtype", payload.Search),
))
}
if payload.ServerOS != "" {
filters = append(filters, dbox.Eq("os", payload.ServerOS))
}
if payload.ServerType != "" {
filters = append(filters, dbox.Eq("serverType", payload.ServerType))
}
if payload.SSHType != "" {
filters = append(filters, dbox.Eq("sshtype", payload.SSHType))
}
var query *dbox.Filter
if len(filters) > 0 {
query = dbox.And(filters...)
}
cursor, err := colonycore.Find(new(colonycore.Server), query)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
data := []colonycore.Server{}
err = cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}
示例10: filterCondition
func filterCondition(cond toolkit.M) *dbox.Filter {
fb := new(dbox.Filter)
for key, val := range cond {
if key == "$and" || key == "$or" {
afb := []*dbox.Filter{}
for _, sVal := range val.([]interface{}) {
rVal := sVal.(map[string]interface{})
mVal := toolkit.M{}
for rKey, mapVal := range rVal {
mVal.Set(rKey, mapVal)
}
afb = append(afb, filterCondition(mVal))
}
if key == "$and" {
fb = dbox.And(afb...)
} else {
fb = dbox.Or(afb...)
}
} else {
if reflect.ValueOf(val).Kind() == reflect.Map {
mVal := val.(map[string]interface{})
tomVal, _ := toolkit.ToM(mVal)
switch {
case tomVal.Has("$eq"):
fb = dbox.Eq(key, tomVal["$eq"].(string))
case tomVal.Has("$ne"):
fb = dbox.Ne(key, tomVal["$ne"].(string))
case tomVal.Has("$regex"):
fb = dbox.Contains(key, tomVal["$regex"].(string))
case tomVal.Has("$gt"):
fb = dbox.Gt(key, tomVal["$gt"].(string))
case tomVal.Has("$gte"):
fb = dbox.Gte(key, tomVal["$gte"].(string))
case tomVal.Has("$lt"):
fb = dbox.Lt(key, tomVal["$lt"].(string))
case tomVal.Has("$lte"):
fb = dbox.Lte(key, tomVal["$lte"].(string))
}
} else {
fb = dbox.Eq(key, val)
}
}
}
return fb
}
示例11: GetPowerVsFuelConsumtion
func (c *DashboardController) GetPowerVsFuelConsumtion(k *knot.WebContext) interface{} {
//c.LoadBase(k)
k.Config.OutputType = knot.OutputJson
d := struct {
StartDate string
EndDate string
Period int
Plant []string
}{}
e := k.GetPayload(&d)
r := new(tk.Result)
r.Run(func(in interface{}) (interface{}, error) {
var (
filter []*dbox.Filter
)
selectedPeriod := d.Period
filter = append(filter, dbox.Eq("Year", selectedPeriod))
if len(d.Plant) > 0 {
filter = append(filter, dbox.Eq("Plant", d.Plant[0]))
}
result := make([]tk.M, 0)
cursor, e := c.DB().Connection.NewQuery().
Select("Plant as _id").
From("ValueEquation_Dashboard").
Where(filter...).
Group("Plant").
Aggr(dbox.AggrSum, "UpdatedFuelConsumption", "FuelConsumtion").
Aggr(dbox.AggrSum, "NetGeneration", "Power").
Order("_id").
Cursor(nil)
defer cursor.Close()
e = cursor.Fetch(&result, 0, true)
e = c.CheckNotError(e)
return result, e
}, nil)
return ResultInfo(r, e)
}
示例12: TestCRUD
func TestCRUD(t *testing.T) {
//t.Skip()
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
return
}
defer c.Close()
e = c.NewQuery().From("tes").Where(dbox.And(dbox.Eq("id", "1133331"), dbox.Eq("name", "testing"))).Delete().Exec(nil)
if e != nil {
t.Errorf("Unablet to delete table %s\n", e.Error())
return
}
defer c.Close()
e = c.NewQuery().From("tes").Delete().Exec(nil)
if e != nil {
t.Errorf("Unablet to clear table %s\n", e.Error())
return
}
defer c.Close()
// q := c.NewQuery().SetConfig("multiexec", true).From("tes").Save()
type user struct {
// Id int
Name string
// Date time.Time
}
// // //go func(q dbox.IQuery, i int) {
data := user{}
// data.Id =111
data.Name = "testingupdate2222"
// data.Date = time.Now()
// e = q.Exec(toolkit.M{
// "data": data,
// })
// if e != nil {
// t.Errorf("Unable to save: %s \n", e.Error())
// }
e = c.NewQuery().From("tes").Where(dbox.Eq("id", "111")).Update().Exec(toolkit.M{"data": data})
if e != nil {
t.Errorf("Unable to update: %s \n", e.Error())
}
}
示例13: Getquery
func Getquery(nameid string) ([]interface{}, error) {
ci := &dbox.ConnectionInfo{filename, "", "", "", nil}
c, e := dbox.NewConnection("json", ci)
if e != nil {
return nil, e
}
e = c.Connect()
if e != nil {
return nil, e
}
defer c.Close()
csr, e := c.NewQuery().Where(dbox.Eq("nameid", nameid)).Cursor(nil)
if e != nil {
return nil, e
}
result := []interface{}{}
data := []toolkit.M{}
e = csr.Fetch(&data, 0, false)
if e != nil {
return nil, e
}
for _, v := range data {
result = append(result, v)
}
return result, nil
}
示例14: TestSelect
func TestSelect(t *testing.T) {
skipIfConnectionIsNil(t)
cursor, e := ctx.NewQuery().From(tableName).Where(dbox.Eq("Enable", false)).Cursor(nil)
if e != nil {
t.Fatalf("Cursor error: " + e.Error())
}
defer cursor.Close()
if cursor.Count() == 0 {
t.Fatalf("No record found")
}
var datas []toolkit.M
e = cursor.Fetch(&datas, 0, false)
if e != nil {
t.Fatalf("Fetch error: %s", e.Error())
}
if len(datas) != cursor.Count() {
t.Fatalf("Expect %d records got %d\n%s\n", cursor.Count(), len(datas), toolkit.JsonString(datas))
}
toolkit.Printf("Record found: %d\nData:\n%s\n", len(datas),
func() string {
var ret []string
for _, v := range datas {
ret = append(ret, v.GetString("_id"))
}
return strings.Join(ret, ",")
}())
}
示例15: Delete
func (a *ConfigurationController) Delete(k *knot.WebContext) interface{} {
var (
filename string
)
d := struct {
NameID string
}{}
e := k.GetPayload(&d)
k.Config.OutputType = knot.OutputJson
filename = wd + filepath.Join("data", "Config", "config.json")
ci := &dbox.ConnectionInfo{filename, "", "", "", nil}
c, e := dbox.NewConnection("json", ci)
defer c.Close()
e = c.Connect()
e = c.NewQuery().Where(dbox.Eq("nameid", d.NameID)).Delete().Exec(nil)
if e != nil {
fmt.Println("Found : ", e)
}
if e != nil {
return e.Error()
} else {
return "OK"
}
}