func RegisterDb() { switch { case dbtypeset == "sqlite": qbs.Register("sqlite3", "./data/sqlite.db", "", qbs.NewSqlite3()) case dbtypeset == "mysql": qbs.Register("mysql", "qbs_test@/qbs_test?charset=utf8&parseTime=true&loc=Local", "dbname", qbs.NewMysql()) case dbtypeset == "pgsql": qbs.Register("postgres", "user=postgres password=jn!@#$%^&* dbname=pgsql sslmode=disable", "pgsql", qbs.NewPostgres()) } }
func RegisterDb() { switch { case dbtypeset == "sqlite": qbs.Register("sqlite3", "./data/sqlite.db", "", qbs.NewSqlite3()) case dbtypeset == "mysql": qbs.Register("mysql", "qbs_test@/qbs_test?charset=utf8&parseTime=true&loc=Local", "dbname", qbs.NewMysql()) case dbtypeset == "pgsql": qbs.Register("postgres", "qbs_test@/qbs_test?charset=utf8&parseTime=true&loc=Local", "dbname", qbs.NewPostgres()) } }
func RegisterDb(driver, dbname, user, password, host string) { qbs.Register(driver, fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true", user, password, host, dbname), dbname, qbs.NewMysql()) err := CreateTabel() if err != nil { fmt.Println(err) } }
func main2() { qbs.Register("sqlite3", "gowalker.db", "", qbs.NewSqlite3()) q, _ := qbs.GetQbs() defer q.Close() pinfo := new(PkgInfo) q.Iterate(pinfo, func() error { if pinfo.Id > 198 { c := &http.Client{} req, err := http.NewRequest("GET", "http://gowalker.org/add?path="+pinfo.Path+"&views="+fmt.Sprintf("%d", pinfo.Views), nil) if err != nil { return err } req.Header.Add("User-Agent", "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:12.0) Gecko/20100101 Firefox/12.0") resp, err := c.Do(req) defer resp.Body.Close() fmt.Println(pinfo.Id, pinfo.Path) if pinfo.Id >= 10000 { return errors.New("FINISH") } } return nil }) }
// InitDb initializes the database. func InitDb() { dbName := utils.Cfg.MustValue("db", "name") dbPwd := utils.Cfg.MustValue("db", "pwd_"+runtime.GOOS) // Register database. qbs.Register("mysql", fmt.Sprintf("%v:%v@%v/%v?charset=utf8&parseTime=true", utils.Cfg.MustValue("db", "user"), dbPwd, utils.Cfg.MustValue("db", "host"), dbName), dbName, qbs.NewMysql()) // Connect to database. q := connDb() defer q.Close() mg, err := setMg() if err != nil { panic("models.init -> " + err.Error()) } defer mg.Close() // Create data tables. mg.CreateTableIfNotExists(new(hv.PkgInfo)) mg.CreateTableIfNotExists(new(PkgTag)) mg.CreateTableIfNotExists(new(PkgRock)) mg.CreateTableIfNotExists(new(PkgExam)) mg.CreateTableIfNotExists(new(PkgDecl)) mg.CreateTableIfNotExists(new(PkgDoc)) mg.CreateTableIfNotExists(new(PkgFunc)) mg.CreateTableIfNotExists(new(PkgImport)) beego.Trace("Initialized database ->", dbName) }
//连接数据库 func connectDb(driver, dbname, user, password, host string) { params := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true", user, password, host, dbname) qbs.Register(driver, params, dbname, qbs.NewMysql()) err := initTable() if err != nil { fmt.Println(err) } }
func RegisterDb() { err := os.MkdirAll("./data", 777) if err != nil { fmt.Println(err) } qbs.Register("sqlite3", "./data/ubuntu_log.sqlite", "./data/ubuntu_log.sqlite", qbs.NewSqlite3()) }
func createTables() { qbs.Register("postgres", "user=holla dbname=hollaholla password=gimmiechocolate sslmode=disable", "hollaholla", qbs.NewPostgres()) err := createTable(new(User)) if err != nil { panic(err) } err = createTable(new(Store)) if err != nil { panic(err) } err = createTable(new(Deal)) if err != nil { panic(err) } }
// 初始化数据库 func RegisterDb() { qbs.Register("mysql", DBSPEC, DBNAME, qbs.NewMysql()) // 创建数据库 m, err := qbs.GetMigration() if err != nil { panic(err) } defer m.Close() m.CreateTableIfNotExists(new(models.User)) m.CreateTableIfNotExists(new(models.Project)) m.CreateTableIfNotExists(new(models.UserCode)) m.CreateTableIfNotExists(new(models.UserStatus)) m.CreateTableIfNotExists(new(models.OAuth)) }
func init() { st := NewSuite("qbs") st.InitF = func() { st.AddBenchmark("Insert", 2000*ORM_MULTI, QbsInsert) st.AddBenchmark("MultiInsert 100 row", 500*ORM_MULTI, QbsInsertMulti) st.AddBenchmark("Update", 2000*ORM_MULTI, QbsUpdate) st.AddBenchmark("Read", 4000*ORM_MULTI, QbsRead) st.AddBenchmark("MultiRead limit 100", 2000*ORM_MULTI, QbsReadSlice) qbs.Register("mysql", ORM_SOURCE, "model", qbs.NewMysql()) qbs.ChangePoolSize(ORM_MAX_IDLE) qbs.SetConnectionLimit(ORM_MAX_CONN, true) qo, _ = qbs.GetQbs() } }
func main() { qbs.Register("postgres", "user=postgres password=jn!@#$%^&* dbname=pgsql sslmode=disable", "pgsql", qbs.NewPostgres()) m, _ := qbs.GetMigration() //m.Log = true //m.DropTable(new(Topic)) m.CreateTableIfNotExists(new(Topic)) q, _ := qbs.GetQbs() //q.Log = true i := new(Topic) i.Content = "i am test!!!!!!" q.Save(i) nana, _ := FindNaById(q, 1) fmt.Println(nana) }
func init() { revel.OnAppStart(func() { var ( found bool spec []string dialect qbs.Dialect ) if Driver, found = revel.Config.String("db.driver"); !found { revel.ERROR.Fatal("No db.driver found.") } switch strings.ToLower(Driver) { case "mysql": dialect = qbs.NewMysql() case "postgres": dialect = qbs.NewPostgres() case "sqlite3": dialect = qbs.NewSqlite3() } // Start building the spec from available config options if User, found = revel.Config.String("db.user"); found { spec = append(spec, User) if Password, found = revel.Config.String("db.password"); found { spec = append(spec, fmt.Sprintf(":%v", Password)) } spec = append(spec, "@") } if Protocol, found = revel.Config.String("db.protocol"); found { spec = append(spec, Protocol) if Address, found = revel.Config.String("db.address"); found { spec = append(spec, fmt.Sprintf("(%v)", Address)) } } if DbName, found = revel.Config.String("db.dbname"); !found { revel.ERROR.Fatal("No db.dbname found.") } spec = append(spec, fmt.Sprintf("/%v", DbName)) if Params, found = revel.Config.String("db.params"); found { spec = append(spec, fmt.Sprintf("?%v", Params)) } qbs.Register(Driver, strings.Join(spec, ""), DbName, dialect) Db, err = qbs.GetQbs() defer Db.Close() }) }
func Init() { var found bool if Driver, found = revel.Config.String("db.driver"); !found { revel.ERROR.Fatal("No db.driver found.") } if Spec, found = revel.Config.String("db.spec"); !found { revel.ERROR.Fatal("No db.spec found.") } // QBS uses snake case by default; override the name convention. qbs.ColumnNameToFieldName = noConvert qbs.FieldNameToColumnName = noConvert qbs.TableNameToStructName = noConvert qbs.StructNameToTableName = noConvert qbs.Register(Driver, Spec, "", qbs.NewMysql()) }
func InitQbs(maxConn int) { var ( found bool driver, spec string ) if driver, found = revel.Config.String("db.driver"); !found { revel.ERROR.Fatal("No db.driver found.") } if spec, found = revel.Config.String("db.spec"); !found { revel.ERROR.Fatal("No db.spec found.") } // QBS uses snake case by default; override the name convention. qbs.ColumnNameToFieldName = noConvert qbs.FieldNameToColumnName = noConvert qbs.TableNameToStructName = noConvert qbs.StructNameToTableName = noConvert qbs.Register(driver, spec, "", qbs.NewMysql()) qbs.ChangePoolSize(maxConn) }
func init() { // Initialize database. os.Mkdir("./data", os.ModePerm) qbs.Register(_SQLITE3_DRIVER, DB_NAME, "", qbs.NewSqlite3()) // Connect to database. q := connDb() defer q.Close() mg, err := setMg() if err != nil { beego.Error("models.init():", err) } defer mg.Close() // Create data tables. mg.CreateTableIfNotExists(new(PkgInfo)) mg.CreateTableIfNotExists(new(PkgDecl)) mg.CreateTableIfNotExists(new(PkgDoc)) beego.Trace("Initialized database ->", DB_NAME) }
func RegisterDb() { qbs.Register("mysql", "qbs_test@/qbs_test?charset=utf8&parseTime=true&loc=Local", "qbs_test", qbs.NewMysql()) }
func init() { os.Remove("/tmp/tmp.db") qbs.Register("sqlite3", "/tmp/tmp.db", "", qbs.NewSqlite3()) }