本文整理匯總了Golang中github.com/eaciit/dbox.And函數的典型用法代碼示例。如果您正苦於以下問題:Golang And函數的具體用法?Golang And怎麽用?Golang And使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了And函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetLdapdataAddress
func (a *GroupController) GetLdapdataAddress(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
autoFilters := []*dbox.Filter{}
var query *dbox.Filter
if len(autoFilters) > 0 {
query = dbox.And(autoFilters...)
}
cursor, err := colonycore.Find(new(colonycore.Ldap), query)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
data := []colonycore.Ldap{}
err = cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}
示例2: Find
func (d *DataContext) Find(m IModel, parms tk.M) (dbox.ICursor, error) {
////_ = "breakpoint"
q := d.Connection.NewQuery().From(m.TableName())
if qe := parms.Get(ConfigSelect); qe != nil {
fields := qe.(string)
selectFields := strings.Split(fields, ",")
q = q.Select(selectFields...)
}
if qe := parms.Get(ConfigWhere, nil); qe != nil {
//q = q.Where(qe.(*dbox.Filter))
filters := qe.([]*dbox.Filter)
if len(filters) > 0 {
q = q.Where(dbox.And(filters...))
}
}
if qe := parms.Get(ConfigOrder, nil); qe != nil {
q = q.Order(qe.([]string)...)
}
if qe := parms.Get(ConfigSkip, nil); qe != nil {
q = q.Skip(qe.(int))
}
if qe := parms.Get(ConfigLimit, nil); qe != nil {
q = q.Take(qe.(int))
}
//fmt.Printf("Debug Q: %s\n", tk.JsonString(q))
return q.Cursor(nil)
//return c
}
示例3: 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
// }
}
示例4: 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)
}
}
示例5: 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
}
示例6: FindConnection
func (d *DataSourceController) FindConnection(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
//~ payload := map[string]string{"inputText":"tes","inputDrop":""}
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
text := payload["inputText"].(string)
pilih := payload["inputDrop"].(string)
textLow := strings.ToLower(text)
// == try useing Contains for support autocomplite
var query *dbox.Filter
if text != "" {
query = dbox.Or(dbox.Contains("_id", text), dbox.Contains("_id", textLow), dbox.Contains("Database", text), dbox.Contains("Database", textLow), dbox.Contains("Driver", text), dbox.Contains("Driver", textLow), dbox.Contains("Host", text), dbox.Contains("Host", textLow), dbox.Contains("UserName", text), dbox.Contains("UserName", textLow), dbox.Contains("Password", text), dbox.Contains("Password", textLow))
}
if pilih != "" {
query = dbox.And(query, dbox.Eq("Driver", pilih))
}
data := []colonycore.Connection{}
cursor, err := colonycore.Find(new(colonycore.Connection), query)
cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}
示例7: FindWebGrabber
func (d *WebGrabberController) FindWebGrabber(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
//~ payload := map[string]string{"inputText": "GRAB_TEST", "inputRequest": "", "inputType": ""}
payload := map[string]interface{}{}
err := r.GetPayload(&payload)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
text := payload["inputText"].(string)
req := payload["inputRequest"].(string)
tipe := payload["inputType"].(string)
textLow := strings.ToLower(text)
// == bug, cant find if autocomplite, just full text can be get result
var query *dbox.Filter
if text != "" {
valueInt, errv := strconv.Atoi(text)
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("Calltype", text), dbox.Contains("Calltype", textLow), dbox.Contains("SourceType", text), dbox.Contains("SourceType", textLow), dbox.Contains("IntervalType", text), dbox.Contains("IntervalType", textLow))
}
}
if req != "" {
query = dbox.And(query, dbox.Eq("Calltype", req))
}
if tipe != "" {
query = dbox.And(query, dbox.Eq("SourceType", tipe))
}
data := []colonycore.WebGrabber{}
cursor, err := colonycore.Find(new(colonycore.WebGrabber), query)
cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, payload, "")
}
示例8: 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, "")
}
示例9: GetScrapperData
func (w *WebGrabberController) GetScrapperData(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())
}
search := payload["search"].(string)
requesttype := payload["requesttype"].(string)
sourcetype := payload["sourcetype"].(string)
var query *dbox.Filter
query = dbox.Or(dbox.Contains("_id", search))
if sourcetype == "" {
//default sourcetype == "SourceType_HttpHtml"
query = dbox.And(query, dbox.Eq("sourcetype", "SourceType_HttpHtml"))
} else {
query = dbox.And(query, dbox.Eq("sourcetype", sourcetype))
}
if requesttype != "" {
query = dbox.And(query, dbox.Eq("grabconf.calltype", requesttype))
}
cursor, err := colonycore.Find(new(colonycore.WebGrabber), query)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
data := []colonycore.WebGrabber{}
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: TestSelect
func TestSelect(t *testing.T) {
// t.Skip()
skipIfConnectionIsNil(t)
cursor, e := ctx.NewQuery().
Select("id", "nama", "amount").
From(tableName).
Where(dbox.And(dbox.Gt("amount", 150), dbox.Eq("nama", "buku"))).
// Where(dbox.Contains("nama", "tem", "pe")).
// Order("nama").
// Skip(2).
// Take(1).
Cursor(nil)
// Where(dbox.And(dbox.Gt("price", "@price"), dbox.Eq("status", "@status"))).
// Cursor(toolkit.M{}.Set("@price", 100000).Set("@status", "available"))
// Where(dbox.And(dbox.Or(dbox.Eq("nama", "@name1"), dbox.Eq("nama", "@name2"),
// dbox.Eq("nama", "@name3")), dbox.Lt("quantity", "@quantity"))).
// Cursor(toolkit.M{}.Set("@name1", "buku").Set("@name2", "tas").
// Set("@name3", "dompet").Set("@quantity", 4))
if e != nil {
t.Fatalf("Cursor error: " + e.Error())
}
defer cursor.Close()
var results []toolkit.M
e = cursor.Fetch(&results, 0, false)
operation = "Test Select Filter"
sintaks = `
ctx.NewQuery().
Select("id", "nama", "amount").
From(tableName).
Where(dbox.And(dbox.Gt("amount", 150000),
dbox.Eq("nama", "buku"))).
Cursor(nil)`
if e != nil {
t.Errorf("Unable to fetch: %s \n", e.Error())
} else {
toolkit.Println("======================")
toolkit.Println(operation)
toolkit.Println("======================")
toolkit.Println(sintaks)
toolkit.Println("Fetch OK. Result:")
for _, val := range results {
toolkit.Printf("%v \n",
toolkit.JsonString(val))
}
}
}
示例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: TestSelectFilter
// if e != nil {
// t.Errorf("Unable to fetch: %s \n", e.Error())
// } else {
// toolkit.Println("======================")
// toolkit.Println(operation)
// toolkit.Println("======================")
// toolkit.Println(sintaks)
// toolkit.Println("Fetch OK. Result:")
// for _, val := range results {
// toolkit.Printf("%v \n",
// toolkit.JsonString(val))
// }
// }
// }
func TestSelectFilter(t *testing.T) {
// t.Skip()
skipIfConnectionIsNil(t)
cursor, e := ctx.NewQuery().
Select("_id", "nama", "amount").
From(tableName).
Where(dbox.And(dbox.Gt("amount", 150), dbox.Eq("nama", "buku"))).
Cursor(nil)
operation = "TestSelectFilter"
sintaks = `
ctx.NewQuery().
Select("_id", "nama", "amount").
From(tableName).
Where(dbox.And(dbox.Gt("amount", 150000),
dbox.Eq("nama", "buku"))).
Cursor(nil)`
if e != nil {
t.Fatalf("Cursor error: " + e.Error())
}
defer cursor.Close()
if cursor.Count() == 0 {
t.Fatalf("No record found")
}
var results []toolkit.M
e = cursor.Fetch(&results, 0, false)
if e != nil {
t.Errorf("Unable to fetch: %s \n", e.Error())
} else {
toolkit.Println("======================")
toolkit.Println(operation)
toolkit.Println("======================")
toolkit.Println(sintaks)
toolkit.Println("Fetch OK. Result:")
for _, val := range results {
toolkit.Printf("%v \n",
toolkit.JsonString(val))
}
}
}
示例14: DaemonStat
func (w *WebGrabberController) DaemonStat(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
if runtime.GOOS == "windows" {
sedotandExist := GetSedotandWindows()
if sedotandExist == false {
return helper.CreateResult(true, false, "")
}
return helper.CreateResult(true, true, "")
} else {
filters := dbox.And(dbox.Eq("serverType", "node"), dbox.Eq("os", "linux"))
cursor, err := colonycore.Find(new(colonycore.Server), filters)
if err != nil {
return helper.CreateResult(false, false, err.Error())
}
all := []colonycore.Server{}
err = cursor.Fetch(&all, 0, true)
if err != nil {
return helper.CreateResult(false, false, err.Error())
}
if len(all) == 0 {
return helper.CreateResult(false, false, "No server registered")
}
serverC := &ServerController{}
var howManyOn = 0
for _, server := range all {
isOn, _ := serverC.ToggleSedotanService("stat", server.ID)
if isOn {
howManyOn = howManyOn + 1
}
}
if howManyOn > 0 {
return helper.CreateResult(true, true, "")
}
return helper.CreateResult(false, false, "")
}
}
示例15: GetConnections
func (d *DataSourceController) GetConnections(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())
}
search := ""
if payload["search"] != nil {
search = payload["search"].(string)
}
driver := ""
if payload["driver"] != nil {
search = payload["driver"].(string)
}
// search := payload["search"]
// driver := payload["driver"]
var query *dbox.Filter
query = dbox.Or(dbox.Contains("_id", search), dbox.Contains("Driver", search), dbox.Contains("Host", search), dbox.Contains("Database", search), dbox.Contains("UserName", search))
if driver != "" {
query = dbox.And(query, dbox.Eq("Driver", driver))
}
data := []colonycore.Connection{}
cursor, err := colonycore.Find(new(colonycore.Connection), query)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
err = cursor.Fetch(&data, 0, false)
if err != nil {
return helper.CreateResult(false, nil, err.Error())
}
defer cursor.Close()
return helper.CreateResult(true, data, "")
}