Exemplo n.º 1
0
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, "")
}
Exemplo n.º 2
0
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
}
Exemplo n.º 3
0
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())
	}

}
Exemplo n.º 4
0
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
}
Exemplo n.º 5
0
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
}
Exemplo n.º 6
0
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, "")
}
Exemplo n.º 7
0
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
}
Exemplo n.º 8
0
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
}
Exemplo n.º 9
0
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
	}
}
Exemplo n.º 10
0
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
}
Exemplo n.º 11
0
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"
	}
}
Exemplo n.º 12
0
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
}
Exemplo n.º 13
0
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
}
Exemplo n.º 14
0
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
}
Exemplo n.º 15
0
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
}
Exemplo n.º 16
0
func InitCall() {
	conn, _ := dbox.NewConnection("mongo", &dbox.ConnectionInfo{"localhost:27017", "ormdb", "", "", nil})
	err := conn.Connect()
	if err != nil {
		log.Printf("CONN ERR %+v \n", err)
	}
	log.Printf("CONN %+v \n", conn)
	SetDb(conn)
}
Exemplo n.º 17
0
func (l *LoginController) prepareconnection() (conn dbox.IConnection, err error) {
	driver, ci := new(colonycore.Login).GetACLConnectionInfo()
	conn, err = dbox.NewConnection(driver, ci)
	if err != nil {
		return
	}
	err = conn.Connect()
	return
}
Exemplo n.º 18
0
func (a *SessionController) prepareconnection() (conn dbox.IConnection, err error) {
	conn, err = dbox.NewConnection("mongo",
		&dbox.ConnectionInfo{"localhost:27017", "valegrab", "", "", toolkit.M{}.Set("timeout", 3)})
	if err != nil {
		return
	}
	err = conn.Connect()
	return
}
Exemplo n.º 19
0
func prepareOrm() (*orm.DataContext, error) {
	conn, e := dbox.NewConnection("mongo",
		&dbox.ConnectionInfo{"localhost:27123", "ectest", "", "", nil})
	e = conn.Connect()
	if e != nil {
		return nil, e
	}

	ctx := orm.New(conn)
	return ctx, nil
}
Exemplo n.º 20
0
func connect() error {
	var e error
	if ctx == nil {
		ctx, e = dbox.NewConnection("mongo",
			&dbox.ConnectionInfo{"localhost:27123", "ectest", "", "", nil})
		if e != nil {
			return e
		}
	}
	e = ctx.Connect()
	return e
}
Exemplo n.º 21
0
func connect() error {
	var e error
	if ctx == nil {
		ctx, e = dbox.NewConnection("hive",
			&dbox.ConnectionInfo{"192.168.0.223:10000", "default", "hdfs", "", nil})
		if e != nil {
			return e
		}
	}
	e = ctx.Connect()
	return e
}
Exemplo n.º 22
0
func connect() error {
	var e error
	if ctx == nil {
		ctx, e = dbox.NewConnection("mysql",
			&dbox.ConnectionInfo{"localhost:3306", "test", "root", "", nil})
		if e != nil {
			return e
		}
	}
	e = ctx.Connect()
	return e
}
Exemplo n.º 23
0
func (w *Grabber) OpenHistory() ([]interface{}, error) {
	var history = []interface{}{} //toolkit.M{}
	var config = map[string]interface{}{"useheader": true, "delimiter": ",", "dateformat": "MM-dd-YYYY"}

	ci := &dbox.ConnectionInfo{tLocation, "", "", "", config}
	c, err := dbox.NewConnection("csv", ci)
	if err != nil {
		return history, err
	}

	err = c.Connect()
	if err != nil {
		return history, err
	}
	defer c.Close()

	csr, err := c.NewQuery().Select("*").Cursor(nil)
	if err != nil {
		return history, err
	}
	if csr == nil {
		return history, errors.New("Cursor not initialized")
	}
	defer csr.Close()
	ds := []toolkit.M{}
	err = csr.Fetch(&ds, 0, false)
	if err != nil {
		return history, err
	}

	for i, v := range ds {
		castDate, _ := time.Parse(time.RFC3339, v.Get("grabdate").(string))

		w.humanDate = cast.Date2String(castDate, "YYYY/MM/dd HH:mm:ss")
		w.rowgrabbed, _ = strconv.ParseFloat(fmt.Sprintf("%v", v.Get("rowgrabbed")), 64)
		w.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", w.humanDate)
		addToMap.Set("grabstatus", v.Get("grabstatus"))
		addToMap.Set("rowgrabbed", w.rowgrabbed)
		addToMap.Set("rowsaved", w.rowsaved)
		addToMap.Set("notehistory", v.Get("note"))
		addToMap.Set("recfile", v.Get("recfile"))
		addToMap.Set("nameid", w.nameid)

		history = append(history, addToMap)
	}
	return history, nil
}
Exemplo n.º 24
0
func prepareConnection() (dbox.IConnection, error) {
	ci := &dbox.ConnectionInfo{"localhost", "", "oracle", "oracle", nil}
	c, e := dbox.NewConnection("oracle", ci)
	if e != nil {
		return nil, e
	}

	e = c.Connect()
	if e != nil {
		return nil, e
	}
	return c, nil
}
Exemplo n.º 25
0
func prepareConnection() (dbox.IConnection, error) {
	ci := &dbox.ConnectionInfo{"localhost:5432", "eccolony", "postgres", "12345", nil}
	c, e := dbox.NewConnection("postgres", ci)
	if e != nil {
		return nil, e
	}

	e = c.Connect()
	if e != nil {
		return nil, e
	}
	return c, nil
}
Exemplo n.º 26
0
func connect() error {
	var e error
	if ctx == nil {
		var config = toolkit.M{}.Set("timeout", 3)
		ctx, e = dbox.NewConnection("mongo",
			&dbox.ConnectionInfo{"localhost:27017", "belajar", "", "", config})
		if e != nil {
			return e
		}
	}
	e = ctx.Connect()
	return e
}
Exemplo n.º 27
0
func connect() error {
	var e error
	if ctx == nil {
		wd, _ := os.Getwd()
		ctx, e = dbox.NewConnection("jsons",
			&dbox.ConnectionInfo{wd, "", "", "", nil})
		if e != nil {
			return e
		}
	}
	e = ctx.Connect()
	return e
}
Exemplo n.º 28
0
func prepareConnection() (dbox.IConnection, error) {
	ci := &dbox.ConnectionInfo{"localhost:3306", "eccolony", "root", "", nil}
	c, e := dbox.NewConnection("mysql", ci)
	if e != nil {
		return nil, e
	}

	e = c.Connect()
	if e != nil {
		return nil, e
	}
	return c, nil
}
Exemplo n.º 29
0
func Connect() (dbox.IConnection, error) {
	connectionInfo := &dbox.ConnectionInfo{"localhost", "eccolonymanager", "", "", nil}
	connection, e := dbox.NewConnection("mongo", connectionInfo)
	if !HandleError(e) {
		return nil, e
	}

	e = connection.Connect()
	if !HandleError(e) {
		return nil, e
	}

	return connection, nil
}
Exemplo n.º 30
0
func LoadConfig(pathJson string) (dbox.IConnection, error) {
	connectionInfo := &dbox.ConnectionInfo{pathJson, "", "", "", nil}
	connection, e := dbox.NewConnection("json", connectionInfo)
	if !HandleError(e) {
		return nil, e
	}

	e = connection.Connect()
	if !HandleError(e) {
		return nil, e
	}

	return connection, nil
}