本文整理匯總了Golang中github.com/eaciit/dbox.NewConnection函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewConnection函數的具體用法?Golang NewConnection怎麽用?Golang NewConnection使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了NewConnection函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: GetData
func (w *TestController) GetData(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
connectionInfo := &dbox.ConnectionInfo{"/Users/novalagung/Documents/go/src/github.com/eaciit/colony-app/data-root/sample-data-json", "", "", "", nil}
connection, err := dbox.NewConnection("jsons", connectionInfo)
if err != nil {
return createResult(false, nil, err.Error())
}
err = connection.Connect()
if err != nil {
return createResult(false, nil, err.Error())
}
c, err := connection.NewQuery().Select().From("sample-json-3").Cursor(nil)
if err != nil {
return createResult(false, nil, err.Error())
}
data := []toolkit.M{}
err = c.Fetch(&data, 0, true)
if err != nil {
return createResult(false, nil, err.Error())
}
return createResult(true, data, "")
}
示例2: setConnectionFromConfigFile
func (d *DataContext) setConnectionFromConfigFile(name string) error {
d.ConnectionName = name
if d.ConnectionName == "" {
d.ConnectionName = fmt.Sprintf("Default")
}
connType := strings.ToLower(config.Get("Connection_" + d.ConnectionName + "_Type").(string))
host := config.Get("Connection_" + d.ConnectionName + "_Host").(string)
username := config.Get("Connection_" + d.ConnectionName + "_Username").(string)
password := config.Get("Connection_" + d.ConnectionName + "_Password").(string)
database := config.Get("Connection_" + d.ConnectionName + "_database").(string)
ci := new(dbox.ConnectionInfo)
ci.Host = host
ci.UserName = username
ci.Password = password
ci.Database = database
conn, eConnect := dbox.NewConnection(connType, ci)
if eConnect != nil {
return err.Error(packageName, modCtx, "SetConnectionFromConfigFile", eConnect.Error())
}
if eConnect = conn.Connect(); eConnect != nil {
return err.Error(packageName, modCtx, "SetConnectionFromConfigFile", eConnect.Error())
}
d.Connection = conn
return nil
}
示例3: main
func main() {
dataurl := toolkit.M{}
dataurl["Pu00231_Input.trade_date"] = "20151214"
dataurl["Pu00231_Input.variety"] = "i"
dataurl["Pu00231_Input.trade_type"] = "0"
dataurl["Submit"] = "Go"
dataurl["action"] = "Pu00231_result"
ci := &dbox.ConnectionInfo{"E:\\data\\temp\\tempjson.json", "", "", "", nil}
c, e := dbox.NewConnection("json", ci)
if e != nil {
fmt.Println(e)
}
e = c.Connect()
if e != nil {
fmt.Println(e)
}
e = c.NewQuery().Insert().Exec(toolkit.M{"data": dataurl})
if e != nil {
fmt.Println("Unable to insert: %s \n", e.Error())
}
}
示例4: Griddashboard
func (a *DashboardController) Griddashboard(k *knot.WebContext) interface{} {
k.Config.OutputType = knot.OutputJson
ci := &dbox.ConnectionInfo{filename, "", "", "", nil}
c, e := dbox.NewConnection("json", ci)
if e != nil {
return e
}
e = c.Connect()
if e != nil {
return e
}
defer c.Close()
csr, e := c.NewQuery().Select("nameid", "url", "grabinterval", "intervaltype", "datasettings").Cursor(nil)
defer csr.Close()
// result := make([]toolkit.M, 0)
result := []toolkit.M{}
e = csr.Fetch(&result, 0, false)
if e != nil {
return e
}
return result
}
示例5: AddRecHistory
func (g *GrabService) AddRecHistory(key string, docs []toolkit.M) string {
var config = map[string]interface{}{"useheader": true, "delimiter": ",", "newfile": true}
file := fmt.Sprintf("%s%s.%s-%s.csv", g.HistoryRecPath, g.Name, key, cast.Date2String(time.Now(), "YYYYMMddHHmmss"))
ci := &dbox.ConnectionInfo{file, "", "", "", config}
c, e := dbox.NewConnection("csv", ci)
if e != nil {
g.ErrorNotes = fmt.Sprintf("[%s] Setup connection to Record history failed [csv-%s]:%s", g.Name, file, e)
g.Log.AddLog(g.ErrorNotes, "ERROR")
return ""
}
e = c.Connect()
if e != nil {
g.ErrorNotes = fmt.Sprintf("[%s] Setup connection to history failed [csv-%s]:%s", g.Name, file, e)
g.Log.AddLog(g.ErrorNotes, "ERROR")
return ""
}
// q := c.NewQuery().SetConfig("multiexec", true).Save()
for _, doc := range docs {
e = c.NewQuery().Insert().Exec(toolkit.M{"data": doc})
if e != nil {
g.ErrorNotes = fmt.Sprintf("[%s] Insert to history failed [csv-%s]:%s", g.Name, file, e)
g.Log.AddLog(g.ErrorNotes, "ERROR")
return ""
}
}
c.Close()
return file
}
示例6: GetData
func (w *TestController) GetData(r *knot.WebContext) interface{} {
r.Config.OutputType = knot.OutputJson
connectionInfo := &dbox.ConnectionInfo{"192.168.0.200:27017", "ecshell", "", "", nil}
connection, err := dbox.NewConnection("mongo", connectionInfo)
if err != nil {
return createResult(false, nil, err.Error())
}
err = connection.Connect()
if err != nil {
return createResult(false, nil, err.Error())
}
c, err := connection.NewQuery().Select().From("WEISUserLog").Cursor(nil)
if err != nil {
return createResult(false, nil, err.Error())
}
data := []toolkit.M{}
err = c.Fetch(&data, 0, true)
if err != nil {
return createResult(false, nil, err.Error())
}
return createResult(true, data, "")
}
示例7: 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
}
示例8: Query
func Query(driver string, host string, other ...interface{}) *queryWrapper {
wrapper := queryWrapper{}
wrapper.ci = &dbox.ConnectionInfo{host, "", "", "", nil}
if len(other) > 0 {
wrapper.ci.Database = other[0].(string)
}
if len(other) > 1 {
wrapper.ci.UserName = other[1].(string)
}
if len(other) > 2 {
wrapper.ci.Password = other[2].(string)
}
if len(other) > 3 {
wrapper.ci.Settings = other[3].(toolkit.M)
}
wrapper.connection, wrapper.err = dbox.NewConnection(driver, wrapper.ci)
if wrapper.err != nil {
return &wrapper
}
wrapper.err = wrapper.connection.Connect()
return &wrapper
}
示例9: GetDataFromCsv
func (a *ResultController) GetDataFromCsv(k *knot.WebContext) interface{} {
k.Config.OutputType = knot.OutputJson
d := struct {
Host string
Delimiter string
Useheader bool
}{}
e := k.GetPayload(&d)
var config = map[string]interface{}{"useheader": d.Useheader, "delimiter": d.Delimiter, "dateformat": "MM-dd-YYYY"}
ci := &dbox.ConnectionInfo{d.Host, "", "", "", config}
c, e := dbox.NewConnection("csv", ci)
defer c.Close()
e = c.Connect()
csr, e := c.NewQuery().Select("*").Cursor(nil)
defer csr.Close()
data := []tk.M{}
e = csr.Fetch(&data, 0, false)
if e != nil {
return e.Error()
} else {
return data
}
}
示例10: ResultFromDatabase
func (g *GetDatabase) ResultFromDatabase(dataSettingId string, out interface{}) error {
c, e := dbox.NewConnection(g.desttype, &g.ConnectionInfo)
if e != nil {
return e
}
e = c.Connect()
if e != nil {
return e
}
defer c.Close()
iQ := c.NewQuery()
if g.CollectionSettings[dataSettingId].Collection != "" {
iQ.From(g.CollectionSettings[dataSettingId].Collection)
}
for _, val := range g.CollectionSettings[dataSettingId].MapsColumns {
iQ.Select(val.Source)
}
if len(g.CollectionSettings[dataSettingId].FilterCond) > 0 {
iQ.Where(g.CollectionSettings[dataSettingId].filterDbox)
}
csr, e := iQ.Cursor(nil)
if e != nil {
return e
}
if csr == nil {
return e
}
defer csr.Close()
results := make([]toolkit.M, 0)
e = csr.Fetch(&results, 0, false)
if e != nil {
return e
}
ms := []toolkit.M{}
for _, val := range results {
m := toolkit.M{}
for _, column := range g.CollectionSettings[dataSettingId].MapsColumns {
m.Set(column.Source, "")
if val.Has(column.Destination) {
m.Set(column.Source, val[column.Destination])
}
}
ms = append(ms, m)
}
if edecode := toolkit.Unjson(toolkit.Jsonify(ms), out); edecode != nil {
return edecode
}
return nil
}
示例11: 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"
}
}
示例12: prepareConnection
func prepareConnection() (dbox.IConnection, error) {
// mapHeader := make([]toolkit.M, 7)
// mapHeader[0] = toolkit.M{}.Set("A", "date")
// mapHeader[1] = toolkit.M{}.Set("B", "int")
// mapHeader[2] = toolkit.M{}.Set("C", "int")
// mapHeader[3] = toolkit.M{}.Set("D", "int")
// mapHeader[4] = toolkit.M{}.Set("E", "int")
// mapHeader[5] = toolkit.M{}.Set("F", "int")
// mapHeader[6] = toolkit.M{}.Set("G", "int")
// mapHeader := []toolkit.M{} //AddMap Header
var config = map[string]interface{}{}
// var config = map[string]interface{}{"mapheader": mapHeader}
ci := &dbox.ConnectionInfo{"E:\\data\\sample\\IO Price Indices.xlsm", "", "", "", config}
c, e := dbox.NewConnection("xlsx", ci)
if e != nil {
return nil, e
}
e = c.Connect()
if e != nil {
return nil, e
}
return c, nil
}
示例13: Query
func Query(driver string, host string, other ...interface{}) *queryWrapper {
if driver == "mysql" && !strings.Contains(host, ":") {
host = fmt.Sprintf("%s:3306", host)
}
wrapper := queryWrapper{}
wrapper.ci = &dbox.ConnectionInfo{host, "", "", "", nil}
if len(other) > 0 {
wrapper.ci.Database = other[0].(string)
}
if len(other) > 1 {
wrapper.ci.UserName = other[1].(string)
}
if len(other) > 2 {
wrapper.ci.Password = other[2].(string)
}
if len(other) > 3 {
wrapper.ci.Settings = other[3].(toolkit.M)
}
wrapper.connection, wrapper.err = dbox.NewConnection(driver, wrapper.ci)
if wrapper.err != nil {
return &wrapper
}
wrapper.err = wrapper.connection.Connect()
if wrapper.err != nil {
return &wrapper
}
return &wrapper
}
示例14: prepareContext
func prepareContext() (*DataContext, error) {
conn, _ := dbox.NewConnection("mongo", &dbox.ConnectionInfo{"localhost:27123", "ectest", "", "", nil})
if eConnect := conn.Connect(); eConnect != nil {
return nil, eConnect
}
ctx := New(conn)
return ctx, nil
}
示例15: OpenHistory
func (h *HistoryModule) OpenHistory() interface{} {
var config = map[string]interface{}{"useheader": true, "delimiter": ",", "dateformat": "MM-dd-YYYY"}
ci := &dbox.ConnectionInfo{h.filepathName, "", "", "", config}
c, e := dbox.NewConnection("csv", ci)
if e != nil {
return e.Error()
}
e = c.Connect()
if e != nil {
return e.Error()
}
defer c.Close()
csr, e := c.NewQuery().Select("*").Cursor(nil)
if e != nil {
return e.Error()
}
if csr == nil {
return "Cursor not initialized"
}
defer csr.Close()
ds := []toolkit.M{}
e = csr.Fetch(&ds, 0, false)
if e != nil {
return e.Error()
}
var history = []interface{}{} //toolkit.M{}
for i, v := range ds {
// layout := "2006/01/02 15:04:05"
castDate := time.Now()
if v.Has("grabdata") {
castDate, _ = time.Parse(time.RFC3339, v.Get("grabdate").(string))
}
h.humanDate = cast.Date2String(castDate, "YYYY/MM/dd HH:mm:ss")
h.rowgrabbed, _ = strconv.ParseFloat(fmt.Sprintf("%v", v.Get("rowgrabbed")), 64)
h.rowsaved, _ = strconv.ParseFloat(fmt.Sprintf("%v", v.Get("rowgrabbed")), 64)
var addToMap = toolkit.M{}
addToMap.Set("id", i+1)
addToMap.Set("datasettingname", v.Get("datasettingname"))
addToMap.Set("grabdate", h.humanDate)
addToMap.Set("grabstatus", v.Get("grabstatus"))
addToMap.Set("rowgrabbed", h.rowgrabbed)
addToMap.Set("rowsaved", h.rowsaved)
addToMap.Set("notehistory", v.Get("note"))
addToMap.Set("recfile", v.Get("recfile"))
addToMap.Set("nameid", h.nameid)
history = append(history, addToMap)
}
return history
}