本文整理匯總了Golang中github.com/eaciit/crowd.From函數的典型用法代碼示例。如果您正苦於以下問題:Golang From函數的具體用法?Golang From怎麽用?Golang From使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了From函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestFrom
func TestFrom(t *testing.T) {
for i := 0; i < sampleCount; i++ {
obj := Obj{}
obj.F = toolkit.ToFloat64(toolkit.RandInt(1000), 2, toolkit.RoundingAuto)
obj.I = toolkit.RandInt(1000) + 5
objs = append(objs, obj)
if i == 0 {
min = obj.I
max = obj.I
sum = obj.I
avg = toolkit.ToFloat64(obj.I, 4, toolkit.RoundingAuto)
} else {
sum += obj.I
avg = toolkit.ToFloat64(sum, 4, toolkit.RoundingAuto) /
toolkit.ToFloat64(i+1, 4, toolkit.RoundingAuto)
if min > obj.I {
min = obj.I
}
if max < obj.I {
max = obj.I
}
}
}
c = crowd.From(&objs)
check(t, c.Error, "")
toolkit.Printf("Data len: %d, max: %d, min: %d, sum: %d, avg: %5.4f\n",
c.Len(), max, min, sum, avg)
}
示例2: Filters
func (q *Query) Filters(parm toolkit.M) (toolkit.M, error) {
filters := toolkit.M{}
parts := crowd.From(q.Parts()).Group(func(x interface{}) interface{} {
qp := x.(*dbox.QueryPart)
return qp.PartType
}, nil).Data
var fields []string
selectParts, hasSelect := parts[dbox.QueryPartSelect]
if hasSelect {
// fields = toolkit.M{}
for _, sl := range selectParts.([]interface{}) {
qp := sl.(*dbox.QueryPart)
for _, fid := range qp.Value.([]string) {
fields = append(fields, fid)
// fields.Set(fid, fid)
}
}
filters.Set("cmdType", dbox.QueryPartSelect)
} else {
_, hasDelete := parts[dbox.QueryPartDelete]
_, hasInsert := parts[dbox.QueryPartInsert]
_, hasUpdate := parts[dbox.QueryPartUpdate]
_, hasSave := parts[dbox.QueryPartSave]
if hasDelete {
filters.Set("cmdType", dbox.QueryPartDelete)
} else if hasInsert {
filters.Set("cmdType", dbox.QueryPartInsert)
} else if hasUpdate {
filters.Set("cmdType", dbox.QueryPartUpdate)
} else if hasSave {
filters.Set("cmdType", dbox.QueryPartSave)
} else {
filters.Set("cmdType", dbox.QueryPartSelect)
}
}
filters.Set("select", fields)
whereParts, hasWhere := parts[dbox.QueryPartWhere]
var where []*dbox.Filter
if hasWhere {
for _, p := range whereParts.([]interface{}) {
fs := p.(*dbox.QueryPart).Value.([]*dbox.Filter)
for _, f := range fs {
where = append(where, f)
}
}
filters.Set("where", where)
}
return filters, nil
}
示例3: TestJoin
func TestJoin(t *testing.T) {
a := []string{"satu", "dua", "tiga", "empat", "lima", "enam", "tujuh", "delapan", "sembilan", "sepuluh"}
b := []int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
cjoin := crowd.From(&a).Join(&b, func(x, y interface{}) bool {
xi := len(x.(string))
yi := y.(int)
return xi == yi
}, nil).Group(func(x interface{}) interface{} {
return x.(toolkit.M).Get("data2")
}, func(x interface{}) interface{} {
return x.(toolkit.M).Get("data1")
}).Exec()
check(t, cjoin.Error, "")
toolkit.Printfn("Data:\n%s", toolkit.JsonString(cjoin.Result.Data()))
}
示例4: TestStorageGet
func TestStorageGet(t *testing.T) {
skipIfClientNil(t)
in := toolkit.M{}
in.Set("key", "dataku")
getResult := client.Call("get", in)
if getResult.Status != toolkit.Status_OK {
t.Errorf(getResult.Message)
return
}
data := []int{}
e := toolkit.FromBytes(getResult.Data.([]byte), "", &data)
if e != nil {
t.Errorf("Unable to decode: " + e.Error())
}
fmt.Println("Result received: %s \n", toolkit.JsonString(data))
total := int(crowd.From(data).Sum(nil))
if total != totalInt {
t.Errorf("Wrong summation expecting %d got %d", totalInt, total)
}
}
示例5: Cursor
func (q *Query) Cursor(in toolkit.M) (dbox.ICursor, error) {
var e error
/*
if q.Parts == nil {
return nil, errorlib.Error(packageName, modQuery,
"Cursor", fmt.Sprintf("No Query Parts"))
}
*/
aggregate := false
dbname := q.Connection().Info().Database
tablename := ""
/*
parts will return E - map{interface{}}interface{}
where each interface{} returned is slice of interfaces --> []interface{}
*/
parts := crowd.From(q.Parts()).Group(func(x interface{}) interface{} {
qp := x.(*dbox.QueryPart)
return qp.PartType
}, nil).Data
//return nil, errorlib.Error(packageName, modQuery, "Cursor", "asdaa")
//fmt.Printf("Query parts: %s\n", toolkit.JsonString(q.Parts()))
fromParts, hasFrom := parts[dbox.QueryPartFrom]
if hasFrom == false {
return nil, errorlib.Error(packageName, "Query", "Cursor", "Invalid table name")
}
tablename = fromParts.([]interface{})[0].(*dbox.QueryPart).Value.(string)
skip := 0
if skipParts, hasSkip := parts[dbox.QueryPartSkip]; hasSkip {
skip = skipParts.([]interface{})[0].(*dbox.QueryPart).
Value.(int)
}
take := 0
if takeParts, has := parts[dbox.QueryPartTake]; has {
take = takeParts.([]interface{})[0].(*dbox.QueryPart).
Value.(int)
}
aggrParts, hasAggr := parts[dbox.QueryPartAggr]
aggrExpression := toolkit.M{}
if hasAggr {
aggregate = true
aggrElements := func() []*dbox.QueryPart {
var qps []*dbox.QueryPart
for _, v := range aggrParts.([]interface{}) {
qps = append(qps, v.(*dbox.QueryPart))
}
return qps
}()
for _, el := range aggrElements {
aggr := el.Value.(dbox.AggrInfo)
//if aggr.Op == dbox.AggrSum {
aggrExpression.Set(aggr.Alias, toolkit.M{}.Set(aggr.Op, aggr.Field))
//}
}
//toolkit.Printf("Aggr: %s\n", toolkit.JsonString(aggrExpression))
}
partGroup, hasGroup := parts[dbox.QueryPartGroup]
if hasGroup {
aggregate = true
groups := func() toolkit.M {
s := toolkit.M{}
for _, v := range partGroup.([]interface{}) {
gs := v.(*dbox.QueryPart).Value.([]string)
for _, g := range gs {
if strings.TrimSpace(g) != "" {
s.Set(g, "$"+g)
}
}
}
return s
}()
if len(groups) == 0 {
aggrExpression.Set("_id", "")
} else {
aggrExpression.Set("_id", groups)
}
}
var fields toolkit.M
selectParts, hasSelect := parts[dbox.QueryPartSelect]
if hasSelect {
fields = toolkit.M{}
for _, sl := range selectParts.([]interface{}) {
qp := sl.(*dbox.QueryPart)
for _, fid := range qp.Value.([]string) {
fields.Set(fid, 1)
}
}
} else {
_, hasUpdate := parts[dbox.QueryPartUpdate]
_, hasInsert := parts[dbox.QueryPartInsert]
_, hasDelete := parts[dbox.QueryPartDelete]
_, hasSave := parts[dbox.QueryPartSave]
if hasUpdate || hasInsert || hasDelete || hasSave {
//.........這裏部分代碼省略.........
示例6: Exec
func (q *Query) Exec(parm toolkit.M) error {
var e error
if parm == nil {
parm = toolkit.M{}
}
/*
if q.Parts == nil {
return errorlib.Error(packageName, modQuery,
"Cursor", fmt.Sprintf("No Query Parts"))
}
*/
dbname := q.Connection().Info().Database
tablename := ""
if parm == nil {
parm = toolkit.M{}
}
data := parm.Get("data", nil)
/*
parts will return E - map{interface{}}interface{}
where each interface{} returned is slice of interfaces --> []interface{}
*/
parts := crowd.From(q.Parts()).Group(func(x interface{}) interface{} {
qp := x.(*dbox.QueryPart)
return qp.PartType
}, nil).Data
fromParts, hasFrom := parts[dbox.QueryPartFrom]
if !hasFrom {
return errorlib.Error(packageName, modQuery, "Exec", "Invalid table name")
}
tablename = fromParts.([]interface{})[0].(*dbox.QueryPart).Value.(string)
var where interface{}
commandType := ""
multi := false
_, hasDelete := parts[dbox.QueryPartDelete]
_, hasInsert := parts[dbox.QueryPartInsert]
_, hasUpdate := parts[dbox.QueryPartUpdate]
_, hasSave := parts[dbox.QueryPartSave]
if hasDelete {
commandType = dbox.QueryPartDelete
} else if hasInsert {
commandType = dbox.QueryPartInsert
} else if hasUpdate {
commandType = dbox.QueryPartUpdate
} else if hasSave {
commandType = dbox.QueryPartSave
}
whereParts, hasWhere := parts[dbox.QueryPartWhere]
if hasWhere {
fb := q.Connection().Fb()
for _, p := range whereParts.([]interface{}) {
fs := p.(*dbox.QueryPart).Value.([]*dbox.Filter)
for _, f := range fs {
fb.AddFilter(f)
}
}
where, e = fb.Build()
if e != nil {
return errorlib.Error(packageName, modQuery, "Exec",
e.Error())
} else {
//fmt.Printf("Where: %s\n", toolkit.JsonString(where))
}
}
if data == nil {
multi = true
} else {
if where == nil {
id := toolkit.Id(data)
if id != nil {
where = (toolkit.M{}).Set("_id", id)
}
} else {
multi = true
}
}
session := q.Session()
multiExec := q.Config("multiexec", false).(bool)
if !multiExec && !q.usePooling && session != nil {
defer session.Close()
}
mgoColl := session.DB(dbname).C(tablename)
if commandType == dbox.QueryPartInsert {
e = mgoColl.Insert(data)
} else if commandType == dbox.QueryPartUpdate {
if multi {
dataM, e := toolkit.ToM(data)
if e != nil {
return errorlib.Error(packageName, modQuery+".Exec", commandType, e.Error())
}
//.........這裏部分代碼省略.........
示例7: Filters
func (q *Query) Filters(parm toolkit.M) (toolkit.M, error) {
filters := toolkit.M{}
quyerParts := q.Parts()
c := crowd.From(&quyerParts)
groupParts := c.Group(func(x interface{}) interface{} {
return x.(*dbox.QueryPart).PartType
}, nil).Exec()
parts := map[interface{}]interface{}{}
if len(groupParts.Result.Data().([]crowd.KV)) > 0 {
for _, kv := range groupParts.Result.Data().([]crowd.KV) {
parts[kv.Key] = kv.Value
}
}
skip := 0
if skipPart, hasSkip := parts[dbox.QueryPartSkip]; hasSkip {
skip = skipPart.([]*dbox.QueryPart)[0].Value.(int)
}
filters.Set("skip", skip)
take := 0
if takeParts, hasTake := parts[dbox.QueryPartTake]; hasTake {
take = takeParts.([]*dbox.QueryPart)[0].Value.(int)
}
filters.Set("take", take)
var aggregate bool
if _, hasAggr := parts[dbox.QueryPartAggr]; hasAggr {
aggregate = true
}
filters.Set("aggregate", aggregate)
var sort []string
if sortParts, hasSort := parts[dbox.QueryPartOrder]; hasSort {
sort = []string{}
for _, sl := range sortParts.([]*dbox.QueryPart) {
// qp := sl.(*dbox.QueryPart)
for _, fid := range sl.Value.([]string) {
sort = append(sort, fid)
}
}
}
filters.Set("sort", sort)
var fields []string
selectParts, hasSelect := parts[dbox.QueryPartSelect]
if hasSelect {
// fields = toolkit.M{}
for _, sl := range selectParts.([]*dbox.QueryPart) {
// qp := sl.(*dbox.QueryPart)
for _, fid := range sl.Value.([]string) {
fields = append(fields, fid)
// fields.Set(fid, fid)
}
}
filters.Set("cmdType", dbox.QueryPartSelect)
} else {
_, hasDelete := parts[dbox.QueryPartDelete]
_, hasInsert := parts[dbox.QueryPartInsert]
_, hasUpdate := parts[dbox.QueryPartUpdate]
_, hasSave := parts[dbox.QueryPartSave]
if hasDelete {
filters.Set("cmdType", dbox.QueryPartDelete)
} else if hasInsert {
filters.Set("cmdType", dbox.QueryPartInsert)
} else if hasUpdate {
filters.Set("cmdType", dbox.QueryPartUpdate)
} else if hasSave {
filters.Set("cmdType", dbox.QueryPartSave)
} else {
filters.Set("cmdType", dbox.QueryPartSelect)
}
}
filters.Set("select", fields)
whereParts, hasWhere := parts[dbox.QueryPartWhere]
var where []*dbox.Filter
if hasWhere {
fb := new(FilterBuilder)
for _, p := range whereParts.([]*dbox.QueryPart) {
fs := p.Value.([]*dbox.Filter)
for _, f := range fs {
f := fb.CheckFilter(f, parm)
where = append(where, f)
}
}
filters.Set("where", where)
}
// toolkit.Printf("where>%v\n", toolkit.JsonString(filters.Get("where")))
return filters, nil
}
示例8: Cursor
func (q *Query) Cursor(in toolkit.M) (dbox.ICursor, error) {
var e error
aggregate := false
if q.Connection().(*Connection).setNewHeader {
q.Connection().(*Connection).Close()
filename := q.Connection().(*Connection).Info().Host
os.Remove(filename)
return nil, errorlib.Error(packageName, "Cursor", modQuery, "Only Insert Query Permited")
}
quyerParts := q.Parts()
c := crowd.From(&quyerParts)
groupParts := c.Group(func(x interface{}) interface{} {
return x.(*dbox.QueryPart).PartType
}, nil).Exec()
parts := map[interface{}]interface{}{}
if len(groupParts.Result.Data().([]crowd.KV)) > 0 {
for _, kv := range groupParts.Result.Data().([]crowd.KV) {
parts[kv.Key] = kv.Value
}
}
skip := 0
if skipParts, hasSkip := parts[dbox.QueryPartSkip]; hasSkip {
skip = skipParts.([]*dbox.QueryPart)[0].
Value.(int)
}
take := 0
if takeParts, has := parts[dbox.QueryPartTake]; has {
take = takeParts.([]*dbox.QueryPart)[0].
Value.(int)
}
var fields toolkit.M
selectParts, hasSelect := parts[dbox.QueryPartSelect]
if hasSelect {
fields = toolkit.M{}
for _, sl := range selectParts.([]*dbox.QueryPart) {
// qp := sl.(*dbox.QueryPart)
for _, fid := range sl.Value.([]string) {
fields.Set(strings.ToLower(fid), 1)
}
}
} else {
_, hasUpdate := parts[dbox.QueryPartUpdate]
_, hasInsert := parts[dbox.QueryPartInsert]
_, hasDelete := parts[dbox.QueryPartDelete]
_, hasSave := parts[dbox.QueryPartSave]
if hasUpdate || hasInsert || hasDelete || hasSave {
return nil, errorlib.Error(packageName, modQuery, "Cursor",
"Valid operation for a cursor is select only")
}
}
var sort []string
sortParts, hasSort := parts[dbox.QueryPartSelect]
if hasSort {
sort = []string{}
for _, sl := range sortParts.([]*dbox.QueryPart) {
// qp := sl.(*dbox.QueryPart)
for _, fid := range sl.Value.([]string) {
sort = append(sort, fid)
}
}
}
var where []*dbox.Filter
whereParts, hasWhere := parts[dbox.QueryPartWhere]
if hasWhere {
for _, p := range whereParts.([]*dbox.QueryPart) {
fs := p.Value.([]*dbox.Filter)
for _, f := range fs {
// if len(in) > 0 {
f = ReadVariable(f, in)
// }
where = append(where, f)
}
}
}
cursor := dbox.NewCursor(new(Cursor))
cursor = cursor.SetConnection(q.Connection())
cursor.(*Cursor).file = q.File()
cursor.(*Cursor).reader = q.Reader()
cursor.(*Cursor).headerColumn = q.Connection().(*Connection).headerColumn
cursor.(*Cursor).count = 0
if e != nil {
return nil, errorlib.Error(packageName, modQuery, "Cursor", e.Error())
}
if !aggregate {
cursor.(*Cursor).ConditionVal.where = where
if fields != nil {
//.........這裏部分代碼省略.........
示例9: prepare
func (q *Query) prepare(in toolkit.M) (output toolkit.M, e error) {
output = toolkit.M{}
quyerParts := q.Parts()
c := crowd.From(&quyerParts)
groupParts := c.Group(func(x interface{}) interface{} {
return x.(*dbox.QueryPart).PartType
}, nil).Exec()
parts := map[interface{}]interface{}{}
if len(groupParts.Result.Data().([]crowd.KV)) > 0 {
for _, kv := range groupParts.Result.Data().([]crowd.KV) {
parts[kv.Key] = kv.Value
}
}
fromParts, hasFrom := parts[dbox.QueryPartFrom]
if hasFrom == false {
return nil, err.Error(packageName, "Query", "prepare", "Invalid table name")
}
tablename := fromParts.([]*dbox.QueryPart)[0].Value.(string)
output.Set("tablename", tablename)
q.filePath = filepath.Join(q.Connection().(*Connection).folder, tablename+".csv")
skip := 0
if skipParts, hasSkip := parts[dbox.QueryPartSkip]; hasSkip {
skip = skipParts.([]*dbox.QueryPart)[0].Value.(int)
}
output.Set("skip", skip)
take := 0
if takeParts, has := parts[dbox.QueryPartTake]; has {
take = takeParts.([]*dbox.QueryPart)[0].Value.(int)
}
output.Set("take", take)
var aggregate bool
aggrParts, hasAggr := parts[dbox.QueryPartAggr]
aggrExpression := toolkit.M{}
if hasAggr {
aggregate = true
aggrElements := func() []*dbox.QueryPart {
var qps []*dbox.QueryPart
for _, v := range aggrParts.([]*dbox.QueryPart) {
qps = append(qps, v)
}
return qps
}()
for _, el := range aggrElements {
aggr := el.Value.(dbox.AggrInfo)
aggrExpression.Set(aggr.Alias, toolkit.M{}.Set(aggr.Op, aggr.Field))
}
}
partGroup, hasGroup := parts[dbox.QueryPartGroup]
if hasGroup {
aggregate = true
groups := func() toolkit.M {
s := toolkit.M{}
for _, v := range partGroup.([]*dbox.QueryPart) {
gs := v.Value.([]string)
for _, g := range gs {
if strings.TrimSpace(g) != "" {
s.Set(g, "$"+g)
}
}
}
return s
}()
if len(groups) == 0 {
aggrExpression.Set("_id", "")
} else {
aggrExpression.Set("_id", groups)
}
}
output.Set("aggregate", aggregate)
output.Set("aggrExpression", aggrExpression)
var fields toolkit.M
selectParts, hasSelect := parts[dbox.QueryPartSelect]
if hasSelect {
fields = toolkit.M{}
for _, sl := range selectParts.([]*dbox.QueryPart) {
for _, fid := range sl.Value.([]string) {
fields.Set(fid, 1)
}
}
output.Set("commandtype", dbox.QueryPartSelect)
} else {
_, hasUpdate := parts[dbox.QueryPartUpdate]
_, hasInsert := parts[dbox.QueryPartInsert]
_, hasDelete := parts[dbox.QueryPartDelete]
_, hasSave := parts[dbox.QueryPartSave]
if hasInsert {
output.Set("commandtype", dbox.QueryPartInsert)
} else if hasUpdate {
output.Set("commandtype", dbox.QueryPartUpdate)
} else if hasDelete {
output.Set("commandtype", dbox.QueryPartDelete)
} else if hasSave {
//.........這裏部分代碼省略.........
示例10: insertBulk
func (q *Query) insertBulk(parm toolkit.M) error {
var e error
if parm == nil {
parm = toolkit.M{}
}
driverName := q.GetDriverDB()
// driverName = "oracle"
tablename := ""
data := parm.Get("data")
var attributes string
var dataM toolkit.M
var dataMs []toolkit.M
if toolkit.IsSlice(data) {
e = toolkit.Unjson(toolkit.Jsonify(data), &dataMs)
if e != nil {
return errorlib.Error(packageName, modQuery, "Exec: data extraction", "Data encoding error: "+e.Error())
}
} else {
dataM, e = toolkit.ToM(data)
dataMs = append(dataMs, dataM)
if e != nil {
return errorlib.Error(packageName, modQuery, "Exec: data extraction", "Data encoding error: "+e.Error())
}
}
temp := ""
quyerParts := q.Parts()
c := crowd.From(&quyerParts)
groupParts := c.Group(func(x interface{}) interface{} {
qp := x.(*dbox.QueryPart)
temp = toolkit.JsonString(qp)
return qp.PartType
}, nil).Exec()
parts := map[interface{}]interface{}{}
if len(groupParts.Result.Data().([]crowd.KV)) > 0 {
for _, kv := range groupParts.Result.Data().([]crowd.KV) {
parts[kv.Key] = kv.Value
}
}
commandType := ""
_, hasInsert := parts[dbox.QueryPartInsert]
if hasInsert {
commandType = dbox.QueryPartInsert
} else {
_, e = q.ExecOut(parm)
return e
// return errorlib.Error(packageName, "Query", modQuery+".InsertBulk", "Invalid Operation")
}
fromParts, hasFrom := parts[dbox.QueryPartFrom]
if !hasFrom {
return errorlib.Error(packageName, "Query", modQuery, "Invalid table name")
}
tablename = fromParts.([]*dbox.QueryPart)[0].Value.(string)
session := q.Session()
attributeList := extractFields(dataMs[0])
var datas []string
for _, dataVal := range dataMs {
var values string
tmp := toolkit.M{}
for _, attr := range attributeList {
tmp.Set(attr, dataVal.Get(attr))
}
values = extractDataBulk(attributeList, tmp, driverName)
// toolkit.Printf("test: \n %v \n------\n %v \n------\n %v \n------\n %v \n", attributeList, dataVal, tmp, values)
datas = append(datas, values)
}
attributes = "(" + strings.Join(attributeList, ",") + ")"
if attributes != "" && nil != datas {
var statement string
if driverName == "hive" {
/*statement = "INSERT INTO " + tablename + " VALUES " + values
e = sessionHive.Exec(statement, nil)*/
return errorlib.Error(packageName, modQuery+".Exec", commandType,
"Not Implemented Yet for HIVE")
} else {
statement = fmt.Sprintf("INSERT INTO "+tablename+" "+attributes+" VALUES %s", strings.Join(datas, ","))
_, e = session.Exec(statement)
}
if e != nil {
return errorlib.Error(packageName, modQuery+".Exec", commandType,
cast.ToString(e.Error()))
//.........這裏部分代碼省略.........
示例11: generatePlantMaster
// GeneratePlantMaster To Generate Master Plant
func (d *GenPlantMaster) generatePlantMaster() error {
tk.Println("Generating..")
ctx := d.BaseController.Ctx
c := ctx.Connection
query := []*dbox.Filter{}
FunctionalLocationList := []FunctionalLocation{}
query = append(query, dbox.Eq("LEN(FunctionalLocationCode)", 4))
csr, e := c.NewQuery().From(new(FunctionalLocation).TableName()).Where(query...).Cursor(nil)
defer csr.Close()
if e != nil {
return e
}
e = csr.Fetch(&FunctionalLocationList, 0, false)
if e != nil {
return e
}
PowerPlantInfoList := []PowerPlantInfo{}
csr, e = c.NewQuery().From(new(PowerPlantInfo).TableName()).Cursor(nil)
if e != nil {
return e
}
e = csr.Fetch(&PowerPlantInfoList, 0, false)
if e != nil {
return e
}
RegenMP := new(RegenMasterPlant)
temp := []PowerPlantInfo{}
for _, plant := range FunctionalLocationList {
RegenMP = new(RegenMasterPlant)
temp = []PowerPlantInfo{}
var tempValue float64
plantDes := PlantNormalization(plant.Description)
datas := crowd.From(&PowerPlantInfoList).Where(func(x interface{}) interface{} {
return strings.Contains(strings.ToLower(x.(PowerPlantInfo).Name), strings.ToLower(plantDes))
}).Exec().Result.Data().([]PowerPlantInfo)
RegenMP.PlantCode = plant.FunctionalLocationCode
RegenMP.PlantName = plantDes
RegenMP.City = datas[0].City
RegenMP.Province = datas[0].Province
RegenMP.Region = datas[0].Region
temp = crowd.From(&datas).Where(func(x interface{}) interface{} {
return x.(PowerPlantInfo).FuelTypes_Crude
}).Exec().Result.Data().([]PowerPlantInfo)
if len(temp) > 0 {
RegenMP.FuelTypes_Crude = true
} else {
RegenMP.FuelTypes_Crude = false
}
temp = crowd.From(&datas).Where(func(x interface{}) interface{} {
return x.(PowerPlantInfo).FuelTypes_Diesel
}).Exec().Result.Data().([]PowerPlantInfo)
if len(temp) > 0 {
RegenMP.FuelTypes_Diesel = true
} else {
RegenMP.FuelTypes_Diesel = false
}
temp = crowd.From(&datas).Where(func(x interface{}) interface{} {
return x.(PowerPlantInfo).FuelTypes_Gas
}).Exec().Result.Data().([]PowerPlantInfo)
if len(temp) > 0 {
RegenMP.FuelTypes_Gas = true
} else {
RegenMP.FuelTypes_Gas = false
}
temp = crowd.From(&datas).Where(func(x interface{}) interface{} {
return x.(PowerPlantInfo).FuelTypes_Heavy
}).Exec().Result.Data().([]PowerPlantInfo)
if len(temp) > 0 {
RegenMP.FuelTypes_Heavy = true
} else {
RegenMP.FuelTypes_Heavy = false
}
tempValue = crowd.From(&datas).Sum(func(x interface{}) interface{} {
return x.(PowerPlantInfo).GasTurbineUnit
}).Exec().Result.Sum
RegenMP.GasTurbineUnit = int(tempValue)
//.........這裏部分代碼省略.........
示例12: Cursor
func (q *Query) Cursor(in toolkit.M) (dbox.ICursor, error) {
var e error
/*
if q.Parts == nil {
return nil, errorlib.Error(packageName, modQuery,
"Cursor", fmt.Sprintf("No Query Parts"))
}
*/
aggregate := false
dbname := q.Connection().Info().Database
session := q.Session()
cursor := dbox.NewCursor(new(Cursor))
cursor.(*Cursor).session = session
driverName := q.GetDriverDB()
//driverName := "mssql"
/*
parts will return E - map{interface{}}interface{}
where each interface{} returned is slice of interfaces --> []interface{}
*/
parts := crowd.From(q.Parts()).Group(func(x interface{}) interface{} {
qp := x.(*dbox.QueryPart)
return qp.PartType
}, nil).Data
fromParts, hasFrom := parts[dbox.QueryPartFrom]
procedureParts, hasProcedure := parts["procedure"]
if hasFrom {
tablename := ""
tablename = fromParts.([]interface{})[0].(*dbox.QueryPart).Value.(string)
skip := 0
if skipParts, hasSkip := parts[dbox.QueryPartSkip]; hasSkip {
skip = skipParts.([]interface{})[0].(*dbox.QueryPart).
Value.(int)
}
take := 0
if takeParts, has := parts[dbox.QueryPartTake]; has {
take = takeParts.([]interface{})[0].(*dbox.QueryPart).
Value.(int)
}
var fields toolkit.M
selectParts, hasSelect := parts[dbox.QueryPartSelect]
var attribute string
incAtt := 0
if hasSelect {
fields = toolkit.M{}
for _, sl := range selectParts.([]interface{}) {
qp := sl.(*dbox.QueryPart)
for _, fid := range qp.Value.([]string) {
if incAtt == 0 {
attribute = fid
} else {
attribute = attribute + "," + fid
}
incAtt++
fields.Set(fid, 1)
}
}
} else {
_, hasUpdate := parts[dbox.QueryPartUpdate]
_, hasInsert := parts[dbox.QueryPartInsert]
_, hasDelete := parts[dbox.QueryPartDelete]
_, hasSave := parts[dbox.QueryPartSave]
if hasUpdate || hasInsert || hasDelete || hasSave {
return nil, errorlib.Error(packageName, modQuery, "Cursor",
"Valid operation for a cursor is select only")
}
}
//fmt.Printf("Result: %s \n", toolkit.JsonString(fields))
//fmt.Printf("Database:%s table:%s \n", dbname, tablename)
var sort []string
sortParts, hasSort := parts[dbox.QueryPartSelect]
if hasSort {
sort = []string{}
for _, sl := range sortParts.([]interface{}) {
qp := sl.(*dbox.QueryPart)
for _, fid := range qp.Value.([]string) {
sort = append(sort, fid)
}
}
}
//where := toolkit.M{}
var where interface{}
whereParts, hasWhere := parts[dbox.QueryPartWhere]
if hasWhere {
fb := q.Connection().Fb()
for _, p := range whereParts.([]interface{}) {
fs := p.(*dbox.QueryPart).Value.([]*dbox.Filter)
for _, f := range fs {
fb.AddFilter(f)
}
}
where, e = fb.Build()
//.........這裏部分代碼省略.........
示例13: Exec
func (q *Query) Exec(parm toolkit.M) error {
var e error
if parm == nil {
parm = toolkit.M{}
}
// fmt.Println("Parameter Exec : ", parm)
dbname := q.Connection().Info().Database
tablename := ""
if parm == nil {
parm = toolkit.M{}
}
data := parm.Get("data", nil)
// fmt.Println("Hasil ekstraksi Param : ", data)
//========================EXTRACT FIELD, DATA AND FORMAT DATE=============================
var attributes string
var values string
var setUpdate string
if data != nil {
var reflectValue = reflect.ValueOf(data)
if reflectValue.Kind() == reflect.Ptr {
reflectValue = reflectValue.Elem()
}
var reflectType = reflectValue.Type()
for i := 0; i < reflectValue.NumField(); i++ {
namaField := reflectType.Field(i).Name
dataValues := reflectValue.Field(i).Interface()
stringValues := StringValue(dataValues, q.GetDriverDB())
if i == 0 {
attributes = "(" + namaField
values = "(" + stringValues
setUpdate = namaField + " = " + stringValues
} else {
attributes += " , " + namaField
values += " , " + stringValues
setUpdate += " , " + namaField + " = " + stringValues
}
}
attributes += ")"
values += ")"
}
//=================================END OF EXTRACTION=======================================
temp := ""
parts := crowd.From(q.Parts()).Group(func(x interface{}) interface{} {
qp := x.(*dbox.QueryPart)
temp = toolkit.JsonString(qp)
return qp.PartType
}, nil).Data
fromParts, hasFrom := parts[dbox.QueryPartFrom]
if !hasFrom {
return errorlib.Error(packageName, "Query", modQuery, "Invalid table name")
}
tablename = fromParts.([]interface{})[0].(*dbox.QueryPart).Value.(string)
var where interface{}
whereParts, hasWhere := parts[dbox.QueryPartWhere]
if hasWhere {
fb := q.Connection().Fb()
for _, p := range whereParts.([]interface{}) {
fs := p.(*dbox.QueryPart).Value.([]*dbox.Filter)
for _, f := range fs {
fb.AddFilter(f)
}
}
where, e = fb.Build()
if e != nil {
} else {
}
}
commandType := ""
multi := false
_, hasDelete := parts[dbox.QueryPartDelete]
_, hasInsert := parts[dbox.QueryPartInsert]
_, hasUpdate := parts[dbox.QueryPartUpdate]
_, hasSave := parts[dbox.QueryPartSave]
if hasDelete {
commandType = dbox.QueryPartDelete
} else if hasInsert {
commandType = dbox.QueryPartInsert
} else if hasUpdate {
commandType = dbox.QueryPartUpdate
} else if hasSave {
commandType = dbox.QueryPartSave
}
//.........這裏部分代碼省略.........
示例14: generatePreventiveCorrectiveSummary
// generatePreventiveCorrectiveSummary
func (s *GenPreventiveCorrectiveSummary) generatePreventiveCorrectiveSummary() error {
var e error
ctx := s.BaseController.Ctx
c := ctx.Connection
years := [3]int{2013, 2014, 2015}
sintax := "select Distinct(Element) from MORSummary"
csr, e := c.NewQuery().Command("freequery", tk.M{}.Set("syntax", sintax)).Cursor(nil)
defer csr.Close()
if e != nil {
return e
}
MROElements := []tk.M{}
e = csr.Fetch(&MROElements, 0, false)
csr1, e := c.NewQuery().From(new(MasterEquipmentType).TableName()).Cursor(nil)
defer csr1.Close()
if e != nil {
return e
}
query := []*dbox.Filter{}
for _, year := range years {
yearFirst := strconv.Itoa(year)
yearFirst = yearFirst + "-01-01 00:00:00.000"
yearLast := strconv.Itoa(year + 1)
yearLast = yearLast + "-01-01 00:00:00.000"
query = append(query, dbox.And(dbox.Gte("Period", yearFirst), dbox.Lte("Period", yearLast)))
csr2, e := c.NewQuery().From(new(MaintenanceCost).TableName()).Where(query...).Cursor(nil)
defer csr2.Close()
if e != nil {
return e
}
datas := []tk.M{}
e = csr2.Fetch(&datas, 0, false)
Plants := crowd.From(&datas).Group(func(x interface{}) interface{} {
return x.(tk.M).GetString("plant")
}, nil).Exec().Result.Data().([]crowd.KV)
if len(Plants) > 0 {
for _, p := range Plants {
plant := p.Key.(string)
EqType := crowd.From(&datas).Where(func(x interface{}) interface{} {
period := x.(tk.M).GetString("period")
return strings.Contains(period, strconv.Itoa(year)) && x.(tk.M).GetString("plant") == plant
}).Exec().Result.Data().([]tk.M)
if len(EqType) > 0 {
EquipmentTypes := crowd.From(&EqType).Group(func(x interface{}) interface{} {
return x.(tk.M).GetString("equipmenttype")
}, nil).Exec().Result.Data().([]crowd.KV)
for _, eq := range EquipmentTypes {
EquipmentType := eq.Key.(string)
ActType := crowd.From(&EqType).Where(func(x interface{}) interface{} {
return x.(tk.M).GetString("equipmenttype") == EquipmentType
}).Exec().Result.Data().([]tk.M)
if len(ActType) > 0 {
MaintActivityTypes := crowd.From(&ActType).Group(func(x interface{}) interface{} {
return x.(tk.M).GetString("maintenanceactivitytype")
}, nil).Exec().Result.Data().([]crowd.KV)
for _, act := range MaintActivityTypes {
MaintActivityType := act.Key.(string)
OrderType := crowd.From(&ActType).Where(func(x interface{}) interface{} {
return x.(tk.M).GetString("maintenanceactivitytype") == MaintActivityType
}).Exec().Result.Data().([]tk.M)
if len(OrderType) > 0 {
OrderTypes := crowd.From(&OrderType).Group(func(x interface{}) interface{} {
return x.(tk.M).GetString("ordertype")
}, nil).Exec().Result.Data().([]crowd.KV)
for _, order := range OrderTypes {
OrderTypeString := order.Key.(string)
OrderNo := crowd.From(&OrderType).Where(func(x interface{}) interface{} {
return x.(tk.M).GetString("ordertype") == OrderTypeString
}).Exec().Result.Data().([]tk.M)
if len(OrderNo) > 0 {
Equipment := crowd.From(&OrderNo).Group(func(x interface{}) interface{} {
return x.(tk.M).GetString("equipment")
}, nil).Exec().Result.Data().([]crowd.KV)
for _, eqNo := range Equipment {
eqNoString := eqNo.Key.(string)
for _, element := range MROElements {
_ = element
//.........這裏部分代碼省略.........
示例15: Cursor
func (q *Query) Cursor(in toolkit.M) (dbox.ICursor, error) {
var e error
/*
if q.Parts == nil {
return nil, errorlib.Error(packageName, modQuery,
"Cursor", fmt.Sprintf("No Query Parts"))
}
*/
aggregate := false
dbname := q.Connection().Info().Database
tablename := ""
/*
parts will return E - map{interface{}}interface{}
where each interface{} returned is slice of interfaces --> []interface{}
*/
parts := crowd.From(q.Parts()).Group(func(x interface{}) interface{} {
qp := x.(*dbox.QueryPart)
return qp.PartType
}, nil).Data
fromParts, hasFrom := parts[dbox.QueryPartFrom]
if hasFrom == false {
return nil, errorlib.Error(packageName, "Query", "Cursor", "Invalid table name")
}
tablename = fromParts.([]interface{})[0].(*dbox.QueryPart).Value.(string)
skip := 0
if skipParts, hasSkip := parts[dbox.QueryPartSkip]; hasSkip {
skip = skipParts.([]interface{})[0].(*dbox.QueryPart).
Value.(int)
}
take := 0
if takeParts, has := parts[dbox.QueryPartTake]; has {
take = takeParts.([]interface{})[0].(*dbox.QueryPart).
Value.(int)
}
var fields toolkit.M
selectParts, hasSelect := parts[dbox.QueryPartSelect]
var attribute string
incAtt := 0
if hasSelect {
fields = toolkit.M{}
for _, sl := range selectParts.([]interface{}) {
qp := sl.(*dbox.QueryPart)
for _, fid := range qp.Value.([]string) {
if incAtt == 0 {
attribute = fid
} else {
attribute = attribute + "," + fid
}
incAtt++
fields.Set(fid, 1)
}
}
} else {
_, hasUpdate := parts[dbox.QueryPartUpdate]
_, hasInsert := parts[dbox.QueryPartInsert]
_, hasDelete := parts[dbox.QueryPartDelete]
_, hasSave := parts[dbox.QueryPartSave]
if hasUpdate || hasInsert || hasDelete || hasSave {
return nil, errorlib.Error(packageName, modQuery, "Cursor",
"Valid operation for a cursor is select only")
}
}
//fmt.Printf("Result: %s \n", toolkit.JsonString(fields))
//fmt.Printf("Database:%s table:%s \n", dbname, tablename)
var sort []string
sortParts, hasSort := parts[dbox.QueryPartSelect]
if hasSort {
sort = []string{}
for _, sl := range sortParts.([]interface{}) {
qp := sl.(*dbox.QueryPart)
for _, fid := range qp.Value.([]string) {
sort = append(sort, fid)
}
}
}
//where := toolkit.M{}
var where interface{}
whereParts, hasWhere := parts[dbox.QueryPartWhere]
if hasWhere {
fb := q.Connection().Fb()
for _, p := range whereParts.([]interface{}) {
fs := p.(*dbox.QueryPart).Value.([]*dbox.Filter)
for _, f := range fs {
fb.AddFilter(f)
}
}
where, e = fb.Build()
if e != nil {
return nil, errorlib.Error(packageName, modQuery, "Cursor",
e.Error())
} else {
//fmt.Printf("Where: %s", toolkit.JsonString(where))
//.........這裏部分代碼省略.........