Ejemplo n.º 1
0
func xmain() {
	db, err := sql.Open("sqlite3", "./httpserver.s3db")
	if err != nil {
		panic(err)
	}
	orm = beedb.New(db)
	insert()
	insertsql()
	a := selectone()
	fmt.Println(a)

	b := selectall()
	fmt.Println(b)

	update()

	updatesql()

	findmap()

	groupby()

	jointable()

	deleteone()

	deletesql()

	deleteall()
}
Ejemplo n.º 2
0
func main() {
	db, err := sql.Open("mymysql", "go_test/root/root")
	if err != nil {
		panic(err)
	}

	beedb.OnDebug = true
	orm := beedb.New(db)

	var saveone Userinfo
	saveone.Username = "******"
	saveone.Departname = "Test Add Departname"
	saveone.Created = time.Now()
	orm.Save(&saveone)

	add := make(map[string]interface{})
	add["username"] = "******"
	add["departname"] = "cloud develop"
	add["created"] = "2012-12-12"
	orm.SetTable("userinfo").Insert(add)

	addslice := make([]map[string]interface{})
	add := make(map[string]interface{})
	add2 := make(map[string]interface{})
	add["username"] = "******"
	add["departname"] = "cloud develop"
	add["created"] = "2020-12-22"
	add2["username"] = "******"
	add2["departname"] = "cloud develop2"
	add2["created"] = "2012-02-02"
	addslice = append(addslice, add, add2)
	orm.SetTable("userinfo").Insert(addslice)
}
Ejemplo n.º 3
0
func main() {
	db, err := sql.Open("sqlite3", "./asta.db")
	if err != nil {
		panic(err)
	}
	orm = beedb.New(db)
	//insert()
	//insertsql()
	// a := selectone()
	// fmt.Println(a)

	// b := selectall()
	// fmt.Println(b)

	// update()

	// updatesql()

	// findmap()

	// groupby()

	// jointable()

	// delete()

	//deletesql()

	//deleteall()
}
func main() {
	db, err := sql.Open("sqlite3", DB_PATH)
	checkError(err)
	orm = beedb.New(db)
	var lastIdInserted int64

	fmt.Println("Inserting")
	lastIdInserted = insertUsingStruct()
	insertUsingMap()

	a := getOneUserInfo(lastIdInserted)
	fmt.Println(a)

	b := getAllUserInfo(lastIdInserted)
	fmt.Println(b)

	fmt.Println("Updating")
	updateUserinfo(lastIdInserted)
	updateUsingMap(lastIdInserted)

	fmt.Println("Querying")
	getMapsFromSelect(lastIdInserted)
	groupby()
	joinTables(lastIdInserted)

	fmt.Println("Deleting")
	deleteWithUserinfo(lastIdInserted)
	deleteRows()
	deleteAllUserinfo(lastIdInserted)
}
Ejemplo n.º 5
0
func GetLink() beedb.Model {
	db, err := sql.Open("sqlite3", "./beepkg.db")
	if err != nil {
		panic(err)
	}
	orm := beedb.New(db)
	return orm
}
Ejemplo n.º 6
0
func loadDB() {
	db, err := sql.Open("sqlite3", "./httpserver.s3db")
	if err != nil {
		panic(err)
	}
	orm = beedb.New(db)

}
Ejemplo n.º 7
0
/*
	Get orm Model
*/
func get_DBFront() beedb.Model {
	db, err := sql.Open("sqlite3", db_front)
	if !check_err(err) {
		panic(err)
	}
	orm := beedb.New(db)
	return orm
}
Ejemplo n.º 8
0
// Retrieve an instance of the DB.
// REMEMBER TO CLOSE THE DB AFTER USING IT.
func RetrieveDB() (*beedb.Model, error) {
	db, err := sql.Open(DBTYPE, DBLOCATION)
	if err != nil {
		return nil, err
	}
	orm := beedb.New(db)
	return &orm, nil
}
Ejemplo n.º 9
0
func (q *MysqlQuery) FindAll(result interface{}) error {
	db := q.SlaveDb
	orm := beedb.New(db)
	if q.Fields == "" {
		q.Fields = "*"
	}
	return orm.SetTable(q.Table).Where(q.Where).OrderBy(q.OrderBy).Limit(q.Size, q.Offset).Select(q.Fields).FindAll(result)
}
Ejemplo n.º 10
0
func GetDB() beedb.Model {
	db, e := sql.Open("mysql", "root:123@/golang?charset=utf8")
	if e != nil {
		println(e.Error())
	}
	orm := beedb.New(db)
	orm.SetTable("weixin")
	return orm
}
Ejemplo n.º 11
0
func (q *MysqlQuery) Exec(newOrm bool, query string, args ...interface{}) (sql.Result, error) {
	db := SlaveDb
	if newOrm {
		db = ConnectMysql(false)
		defer db.Close()
	}
	orm := beedb.New(db)
	return orm.Exec(query, args...)
}
Ejemplo n.º 12
0
func InitDb() (orm beedb.Model) {
	database := beego.AppConfig.String("mysqldb")
	username := beego.AppConfig.String("mysqluser")
	password := beego.AppConfig.String("mysqlpass")
	db, err := sql.Open("mymysql", database+"/"+username+"/"+password)
	Check(err)
	orm = beedb.New(db)
	return
}
Ejemplo n.º 13
0
func openDbConnection(engine string, arg_string string) {
	db, err := sql.Open(engine, arg_string)

	if err != nil {
		panic(err)
	}

	song_db = beedb.New(db, "pg")
}
Ejemplo n.º 14
0
func (q *MysqlQuery) Delete(newOrm bool) (int64, error) {
	db := MasterDB
	if newOrm {
		db = ConnectMysql(true)
		defer db.Close()
	}
	orm := beedb.New(db)
	return orm.SetTable(q.Table).Where(q.Where).DeleteRow()
}
Ejemplo n.º 15
0
func InitDb() (orm beedb.Model) {
	database := "seocms"
	username := "******"
	password := "******"
	db, err := sql.Open("mymysql", database+"/"+username+"/"+password)
	Check(err)
	orm = beedb.New(db)
	return
}
Ejemplo n.º 16
0
//数据库连接
func GetLink() beedb.Model {
	//beedb.OnDebug = true
	db, err := sql.Open("mysql", mysql_user+":"+mysql_pass+"@tcp("+mysql_host+":"+mysql_port+")/"+database_name)
	if err != nil {
		panic(err)
	}

	orm := beedb.New(db)
	return orm
}
Ejemplo n.º 17
0
func (q *MysqlQuery) Upsert(data interface{}, newOrm bool) error {
	db := MasterDB
	if newOrm {
		db = ConnectMysql(true)
		defer db.Close()
	}

	orm := beedb.New(db)
	return orm.SetTable(q.Table).Save(data)
}
Ejemplo n.º 18
0
func GetLink() beedb.Model {
	beedb.OnDebug = true
	db, err := sql.Open("mymysql", "test/root/123456")
	if err != nil {
		panic(err)
	}

	orm := beedb.New(db)

	return orm
}
Ejemplo n.º 19
0
func handleOffer(offer bondoffer.BondOffer, bond bondoffer.Bond, method string) {
	offer.Version = bond.Version
	offer.LastVersion = bond.LastVersion
	offer.Method = method

	offerMap := offer.ToMap()

	orm := beedb.New(db)
	_, err := orm.SetTable("bond_offer_log").Insert(offerMap)
	stomputils.CheckErr(err)
	fmt.Println(time.Now(), method, offer.CompanyName, offer.GoodsCode)
}
Ejemplo n.º 20
0
func (q *MysqlQuery) FindAll(result interface{}, newOrm bool) error {
	db := SlaveDb
	if newOrm {
		db = ConnectMysql(false)
		defer db.Close()
	}

	orm := beedb.New(db)
	if q.Fields == "" {
		q.Fields = "*"
	}
	return orm.SetTable(q.Table).Where(q.Where).OrderBy(q.OrderBy).Limit(q.Size, q.Offset).Select(q.Fields).FindAll(result)
}
Ejemplo n.º 21
0
func main() {
	db, err := sql.Open("mymysql", "golog/root/rabbit")
	if err != nil {
		panic(err)
	}
	orm := beedb.New(db)
	var cat Category
	err = orm.Where("id=?", 1).Find(&cat)
	if err != nil {
		fmt.Printf("%v", err)
	}
	fmt.Printf("%v", cat)
}
Ejemplo n.º 22
0
func (db *Database) Connect() {
	db_db, err := sql.Open("postgres", "user=adsms dbname=novigeroi password=adsms sslmode=disable")
	db.db = db_db
	if err != nil {
		panic(err.Error())
	}

	// Beedb ORM

	beedb.OnDebug = true

	orm := beedb.New(db.db, "pg")
	db.orm = &orm
}
Ejemplo n.º 23
0
func insertData(db *sql.DB, mkType string) {
	//	beedb.OnDebug=true
	orm := beedb.New(db)
	tableName := "market_stream" + mkType
	fmt.Printf("start type%v:\n", mkType)
	orm.SetTable(tableName).DeleteRow()

	rows, _ := orm.SetTable("market_stream").Where("type=?", mkType).Select(fields).FindMap()

	i := 0
	for _, row := range rows {
		bstr := string(row["body"])
		bodys := strings.Split(bstr, ",")

		add := make(map[string]interface{})

		for k, v := range row {
			add[k] = v
		}

		for _, v := range bodys {
			vs := strings.Split(v, ":")
			if len(vs) == 0 || vs[0] == "" {
				continue
			}

			if vs[0] == "id" {
				vs[0] = "bodyId"
			}
			if len(vs) == 1 || vs[1] == "" {
				add[vs[0]] = []byte("")
			} else if len(vs) == 2 {
				add[vs[0]] = []byte(vs[1])
			}
		}

		add["body"] = ""
		//		orm.SetTable(tableName).Insert(add)

		i++
		if i%100 == 0 {
			fmt.Printf("%v rows\n", i)
		}
	}

	fmt.Printf("%v rows end\n", i)
}
Ejemplo n.º 24
0
func readData(host, port, username, password, database, table, versionfield, valuefield, startversion, endversion string) {
	messageLabel.SetText("")
	url := fmt.Sprintf("%s:%s@tcp(%s:%s)/%s?charset=utf8", username, password, host, port, database)

	db, err := sql.Open("mysql", url)
	if checkErr(err, "连接数据库出错") {
		return
	}
	defer db.Close()

	version, err := strconv.Atoi(startversion)
	if checkErr(err, "StartVersion 必须数字,不能为空") {
		return
	}
	maxVersion, err := strconv.Atoi(endversion)
	if checkErr(err, "EndVersion 必须数字,不能为空") {
		return
	}

	orm := beedb.New(db)

	for version <= maxVersion {
		rows, err := orm.SetTable(table).Where(versionfield+"=?", version).FindMap()
		if checkErr(err, "Sql执行错误") {
			return
		}

		for _, row := range rows {
			inBuffer := bytes.NewBuffer(row[valuefield])
			greader, err := gzip.NewReader(inBuffer)
			if checkErr(err, "数据解压错误") {
				return
			}
			defer greader.Close()

			data, err := ioutil.ReadAll(greader)
			if checkErr(err, "数据读取错误") {
				return
			}

			logTextEdit.SetText(logTextEdit.Text() + string(data))
		}
		version++
	}

}
Ejemplo n.º 25
0
func initDatabase() bool {
	// Fetch database info from conf file
	username, _ := g_config.GetString("database", "user")
	password, _ := g_config.GetString("database", "pass")
	scheme, _ := g_config.GetString("database", "db")

	// Connect
	db, err := sql.Open("mymysql", fmt.Sprintf("%v/%v/%v", scheme, username, password))
	if err != nil {
		log.Error("main", "setupDatabase", "Error when opening sql connection: %v", err.Error())
	} else {
		g_orm = beedb.New(db)
		beedb.OnDebug, _ = g_config.GetBool("database", "debug_mode")
	}

	return (err == nil)
}
Ejemplo n.º 26
0
func main() {
	db, err := sql.Open("sqlite3", "./mysqlite")
	if err != nil {
		panic(err)
	}
	orm = beedb.New(db)

	var saveone Userinfo
	saveone.Username = "******"
	saveone.Departname = "Test Depart"
	saveone.Created = time.Now().Format("2006-01-01 00:00:00")
	orm.Save(&saveone)
	fmt.Println(saveone)

	var query Userinfo
	orm.Where("uid=?", saveone.Uid).Find(&query)
	fmt.Println(query)
}
Ejemplo n.º 27
0
func main() {
	// load settings
	settings = loadSettings()
	// func routers
	for rule, funcname := range Urls {
		http.HandleFunc(rule, funcname)
	}
	// static files
	http.Handle("/static/", http.StripPrefix("/static", http.FileServer(http.Dir(settings["root"]+settings["static"]))))
	link := fmt.Sprintf("%s/%s/%s", settings["db_name"], settings["db_user"], settings["db_pass"])
	db, err := sql.Open("mymysql", link)
	if err != nil {
		panic(err)
	}
	orm = beedb.New(db)
	err = http.ListenAndServe(":8888", nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}
Ejemplo n.º 28
0
Archivo: test.go Proyecto: roca/GO
func QueryRows2(db *sql.DB) {

	var orm beedb.Model

	var allCommands []Command

	beedb.PluralizeTableNames = true

	orm = beedb.New(db, "pg")
	beedb.OnDebug = true

	err := orm.FindAll(&allCommands)
	if err != nil {
		panic(err)
	}

	for i, command := range allCommands {
		fmt.Printf("row %d : %s %s\n", i, command.Path, command.Dir)
	}
}
Ejemplo n.º 29
0
Archivo: test.go Proyecto: roca/GO
func QueryRows2(db *sql.DB) {

	var orm beedb.Model

	var allclones []Clone

	beedb.PluralizeTableNames = true

	orm = beedb.New(db, "pg")
	beedb.OnDebug = true

	err := orm.FindAll(&allclones)
	if err != nil {
		panic(err)
	}

	for i, clone := range allclones {
		fmt.Printf("row %d : %s %s\n", i, clone.Name, clone.Seq)
	}
}
Ejemplo n.º 30
0
Archivo: pg.go Proyecto: huaguzi/beedb
func main() {
	db, err := sql.Open("postgres", "user=asta password=123456 dbname=test sslmode=disable")
	if err != nil {
		panic(err)
	}
	orm = beedb.New(db, "pg")
	insert()
	//insertsql()
	// a := selectone()
	// fmt.Println(a)
	// b := selectall()
	// fmt.Println(b)
	//update()
	//updatesql()
	//findmap()
	//groupby()
	//jointable()
	//delete()
	//deleteall()
	//deletesql()
}