本文整理匯總了Golang中github.com/eaciit/toolkit.JsonString函數的典型用法代碼示例。如果您正苦於以下問題:Golang JsonString函數的具體用法?Golang JsonString怎麽用?Golang JsonString使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了JsonString函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestHiveExecMulti
func TestHiveExecMulti(t *testing.T) {
e := h.Conn.Open()
fatalCheck(t, "Populate", e)
var ms1, ms2 []HiveResult
q := "select * from sample_07 limit 5"
e = h.Exec(q, func(x HiveResult) error {
ms1 = append(ms1, x)
return nil
})
fatalCheck(t, "HS1 exec", e)
e = h.Exec(q, func(x HiveResult) error {
ms2 = append(ms2, x)
return nil
})
fatalCheck(t, "HS2 Exec", e)
t.Logf("Value of HS1\n%s\n\nValue of HS2\n%s", toolkit.JsonString(ms1), toolkit.JsonString(ms2))
h.Conn.Close()
}
示例2: TestScan
func TestScan(t *testing.T) {
var e error
fmt.Println("Test Scan")
if econnect := connect(); econnect != nil {
t.Error("Unable to connect to database")
return
}
defer close()
ormConn := orm.New(ctx)
defer ormConn.Close()
cats := make([]OutageCategory, 0)
e = ormConn.Find(new(OutageCategory), nil).FetchAll(&cats, true)
if e != nil {
t.Error(e.Error())
}
os := make([]*Outage, 0)
e = ormConn.Find(new(Outage), nil).FetchAll(&os, true)
if e != nil {
t.Error(e.Error())
}
for _, o := range os {
fmt.Printf("Before: %s \n\n", tk.JsonString(o))
for k, sum := range o.Summaries {
for k, i := range sum.Outages {
i.Valid = false
i.SuggestedCategoryId = ""
for _, c := range cats {
fmt.Printf("Evaluating keyword: %s ...", strings.Join(c.Keywords, ","))
cok := c.Scan(i.Reason)
fmt.Printf("%+v \n", cok)
if cok {
if i.Valid == false && sum.CategoryId == c.Id {
fmt.Printf("Tag: %s as valid \n", c.Id)
i.Valid = true
i.SuggestedCategoryId = ""
} else if i.Valid == false {
fmt.Printf("Suggesting: %s \n", c.Id)
i.SuggestedCategoryId = c.Id
}
}
}
sum.Outages[k] = i
}
o.Summaries[k] = sum
}
o.Sync()
e = ormConn.Save(o)
fmt.Printf("After: %s \n\n", tk.JsonString(o))
}
}
示例3: TestAggr
func TestAggr(t *testing.T) {
skipIfNil(t)
c2 := c.Min(fn).Max(fn).Sum(fn).Avg(fn).Exec()
check(t, c2.Error, "Aggr")
if toolkit.ToInt(c2.Result.Min, toolkit.RoundingAuto) != min ||
toolkit.ToInt(c2.Result.Max, toolkit.RoundingAuto) != max ||
c2.Result.Sum != toolkit.ToFloat64(sum, 4, toolkit.RoundingAuto) ||
c2.Result.Avg != avg {
t.Fatalf("Error aggr. Got %v\n", toolkit.JsonString(c2.Result))
}
toolkit.Println("Value: ", toolkit.JsonString(c2.Result))
}
示例4: TestSaveQuery
func TestSaveQuery(t *testing.T) {
var e error
for i := 1; i <= 5; i++ {
ds := new(colonycore.DataSource)
ds.ID = toolkit.Sprintf("ds%d", i)
ds.ConnectionID = "conn1"
ds.QueryInfo = toolkit.M{}
ds.MetaData = nil
e = colonycore.Save(ds)
if e != nil {
t.Fatalf("Save datasource fail. " + e.Error())
}
}
var dss []colonycore.DataSource
c, e := colonycore.Find(new(colonycore.DataSource), nil)
if e != nil {
t.Fatalf("Load ds fail: " + e.Error())
}
e = c.Fetch(&dss, 0, true)
if e != nil {
t.Fatalf("Ftech ds fail: " + e.Error())
}
if len(dss) != 5 {
t.Fatal("Fetch ds fail. Got %d records only", len(dss))
}
toolkit.Println("Data:", toolkit.JsonString(dss))
}
示例5: 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, ",")
}())
}
示例6: TestSelect
func TestSelect(t *testing.T) {
t.Skip()
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
}
defer c.Close()
// csr, e := c.NewQuery().Select().From("tes").Where(dbox.Eq("id", "3")).Cursor(nil)
csr, e := c.NewQuery().
// Select("empno", "ename", "hiredate").
From(tableCustomers).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{}
e = csr.Fetch(&rets, 0, false)
if e != nil {
t.Errorf("Unable to fetch N: %s \n", e.Error())
} else {
toolkit.Printf("Fetch N OK. Result: %v \n", toolkit.JsonString(rets))
toolkit.Printf("Total Fetch OK : %v \n", toolkit.SliceLen(rets))
}
}
示例7: TestTakeSkip
func TestTakeSkip(t *testing.T) {
t.Skip()
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
}
defer c.Close()
csr, e := c.NewQuery().
Select("id", "productname").
From(tableProducts).
Take(5).
Skip(10).
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{}
e = csr.Fetch(&rets, 0, false)
if e != nil {
t.Errorf("Unable to fetch: %s \n", e.Error())
} else {
toolkit.Printf("Fetch OK. Result: %v \n", toolkit.JsonString(rets))
toolkit.Printf("Total Record OK. Result: %v \n", toolkit.SliceLen(rets))
}
}
示例8: TestSelectAggregate
func TestSelectAggregate(t *testing.T) {
t.Skip()
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
}
defer c.Close()
csr, e := c.NewQuery().
Select("productname").
Aggr(dbox.AggrSum, "price", "Total Price").
Aggr(dbox.AggrAvr, "price", "Avg").
From(tableProducts).
Group("productname").
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{}
e = csr.Fetch(&rets, 0, false)
if e != nil {
t.Errorf("Unable to fetch: %s \n", e.Error())
} else {
toolkit.Printf("Fetch OK. Result: %v \n", toolkit.JsonString(rets))
}
}
示例9: 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))
}
}
示例10: TestSelectAggregate
func TestSelectAggregate(t *testing.T) {
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
return
}
defer c.Close()
//fb := c.Fb()
csr, e := c.NewQuery().
Aggr(dbox.AggrSum, 1, "Sum").
Aggr(dbox.AggrMax, "$fullname", "Name").
From("ORMUsers").
Group("enable").
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()
ds, e := csr.Fetch(nil, 0, false)
if e != nil {
t.Errorf("Unable to fetch: %s \n", e.Error())
} else {
fmt.Printf("Fetch OK. Result: %v \n",
toolkit.JsonString(ds.Data))
}
}
示例11: 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", "email").
Where(dbox.Eq("email", "[email protected]")).
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 OK. Result: %v \n",
toolkit.JsonString(ds.Data[0]))
}
}
示例12: TestSelect
func TestSelect(t *testing.T) {
// t.Skip()
skipIfConnectionIsNil(t)
cursor, e := ctx.NewQuery().
Select("id", "nama", "amount").
From(tableName).
Cursor(nil)
if e != nil {
t.Fatalf("Cursor error: " + e.Error())
}
defer cursor.Close()
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("Number of rows", cursor.Count())
toolkit.Println("Fetch OK. Result:")
for _, val := range results {
toolkit.Printf("%v \n",
toolkit.JsonString(val))
}
}
}
示例13: TestSelectAggregateUsingCommand
func TestSelectAggregateUsingCommand(t *testing.T) {
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
return
}
defer c.Close()
//fb := c.Fb()
pipe := []toolkit.M{toolkit.M{}.Set("$group", toolkit.M{}.Set("_id", "$enable").Set("count", toolkit.M{}.Set("$sum", 1)))}
csr, e := c.NewQuery().
Command("pipe", pipe).
From("ORMUsers").
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()
ds, e := csr.Fetch(nil, 0, false)
if e != nil {
t.Errorf("Unable to fetch: %s \n", e.Error())
} else {
fmt.Printf("Fetch OK. Result: %v \n",
toolkit.JsonString(ds.Data))
}
}
示例14: TestFreeQuery
func TestFreeQuery(t *testing.T) {
t.Skip()
c, e := prepareConnection()
if e != nil {
t.Errorf("Unable to connect %s \n", e.Error())
}
defer c.Close()
csr, e := c.NewQuery().
Command("freequery", toolkit.M{}.
Set("syntax", "select name from tes where name like 'r%'")).
Cursor(nil)
if csr == nil {
t.Errorf("Cursor not initialized", e.Error())
return
}
defer csr.Close()
results := make([]map[string]interface{}, 0)
err := csr.Fetch(&results, 0, false)
if err != nil {
t.Errorf("Unable to fetch: %s \n", err.Error())
} else {
toolkit.Println("======================")
toolkit.Println("TEST FREE QUERY")
toolkit.Println("======================")
toolkit.Println("Fetch N OK. Result: ")
for _, val := range results {
toolkit.Printf("%v \n",
toolkit.JsonString(val))
}
}
}
示例15: main
func main() {
//emp := new(Employee)
//var emps interface{}
emps := tk.MakeSlice(&Employee{}).([]*Employee)
fillArray(&emps)
fmt.Printf("Value of empls:\n%s\n", tk.JsonString(emps))
}