本文整理汇总了Golang中github.com/astaxie/beego/orm.RegisterDataBase函数的典型用法代码示例。如果您正苦于以下问题:Golang RegisterDataBase函数的具体用法?Golang RegisterDataBase怎么用?Golang RegisterDataBase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegisterDataBase函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: dbInit
func dbInit() {
orm.RegisterModel(new(UserInfo), new(UserStatus), new(UserRecord))
//register mysql driver
err := orm.RegisterDriver("mysql", orm.DR_MySQL)
if err != nil {
beego.Critical(err)
}
//register default database
if !localSwitch {
orm.RegisterDataBase("default", "mysql", "autelan:[email protected](rdsrenv7vrenv7v.mysql.rds.aliyuncs.com:3306)/umsdb?charset=utf8&&loc=Asia%2FShanghai")
} else {
dbIp := beego.AppConfig.String("DbIp")
dbPort := beego.AppConfig.String("DbPort")
dbName := beego.AppConfig.String("DbName")
dbUser := beego.AppConfig.String("DbUser")
dbPassword := beego.AppConfig.String("DbPassword")
dbUrl := dbUser + ":" + dbPassword +
"@tcp(" + dbIp + ":" + dbPort + ")/" +
dbName + "?charset=utf8&loc=Asia%2FShanghai"
beego.Debug("dbUrl=", dbUrl)
err = orm.RegisterDataBase("default", "mysql", dbUrl)
if err != nil {
beego.Critical(err)
}
}
orm.SetMaxIdleConns("default", 30)
orm.SetMaxOpenConns("default", 30)
ormer = orm.NewOrm()
}
示例2: init
func init() {
dbname := "default"
runmode := beego.AppConfig.String("runmode")
datasource := beego.AppConfig.String("datasource")
switch runmode {
case "prod":
//orm.RegisterDriver("postgres", orm.DR_Postgres)
//orm.RegisterDataBase(dbname, "postgres", datasource, 30)
//orm.SetMaxIdleConns(dbname, 100)
//orm.SetMaxOpenConns(dbname, 100)
orm.RegisterDriver("mysql", orm.DRMySQL)
orm.RegisterDataBase(dbname, "mysql", datasource)
case "dev":
orm.RegisterDriver("mysql", orm.DRMySQL)
orm.RegisterDataBase(dbname, "mysql", datasource)
default:
//orm.RegisterDataBase(dbname, "sqlite3", datasource)
orm.RegisterDriver("mysql", orm.DRMySQL)
orm.RegisterDataBase(dbname, "mysql", datasource)
}
orm.DefaultTimeLoc = time.FixedZone("Asia/Tokyo", 9*60*60)
force, verbose := false, true
err := orm.RunSyncdb(dbname, force, verbose)
if err != nil {
panic(err)
}
// orm.RunCommand()
}
示例3: InitDatabase
func InitDatabase() {
// set default database
config := g.Config()
orm.RegisterDataBase("default", "mysql", config.Uic.Addr, config.Uic.Idle, config.Uic.Max)
orm.RegisterDataBase("falcon_portal", "mysql", config.FalconPortal.Addr, config.FalconPortal.Idle, config.FalconPortal.Max)
// register model
orm.RegisterModel(new(uic.User), new(uic.Session), new(event.Events), new(event.EventCases))
if config.Debug {
orm.Debug = true
}
}
示例4: init
func init() {
dbname := "default" // 数据库别名
dbtype := beego.AppConfig.String("dbtype")
dbcfg, err := beego.AppConfig.GetSection(dbtype)
if err != nil {
panic(err)
}
// 统一采用 UTC 时间
orm.DefaultTimeLoc = time.UTC
orm.Debug = true
switch dbtype {
case "mysql":
var username string = dbcfg["username"]
if username, err = utils.AesDecrypt(username); err != nil {
panic(err)
}
var password string = dbcfg["password"]
if password, err = utils.AesDecrypt(password); err != nil {
panic(err)
}
url := dbcfg["url"]
maxidle, _ := strconv.Atoi(dbcfg["maxidle"])
maxconn, _ := strconv.Atoi(dbcfg["maxconn"])
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterDataBase(dbname, "mysql",
username+":"+password+"@"+url,
maxidle, maxconn)
case "sqlite":
url := dbcfg["url"]
orm.RegisterDriver("sqlite3", orm.DR_Sqlite)
orm.RegisterDataBase(dbname, "sqlite3", url)
}
orm.RegisterModel(new(User), new(UserBind), new(UserStats))
orm.RegisterModel(new(Question), new(Reply), new(QuestionMark), new(AnswerMark))
orm.RegisterModel(new(Category))
orm.RegisterModel(new(Blog))
orm.RegisterModel(new(Comment))
force := false // drop table 后再建表
verbose, _ := beego.AppConfig.Bool("SqlLogOn") // 打印执行过程
// 遇到错误立即返回
err = orm.RunSyncdb(dbname, force, verbose)
if err != nil {
fmt.Println(err)
}
}
示例5: InitDatabase
func InitDatabase() {
// set default database
config := g.Config()
orm.RegisterDataBase("default", "mysql", config.Db.Addr, config.Db.Idle, config.Db.Max)
// register model
orm.RegisterModel(new(Host), new(Grp), new(Grp_host), new(Grp_tpl), new(Tpl))
strConn := strings.Replace(config.Db.Addr, "graph", "grafana", 1)
orm.RegisterDataBase("grafana", "mysql", strConn, config.Db.Idle, config.Db.Max)
orm.RegisterModel(new(Province), new(City), new(Idc))
if config.Debug == true {
orm.Debug = true
}
}
示例6: regDatabase
func (this *StellarAddressManager) regDatabase() {
orm.RegisterModel(new(databasefunction.StellarAddrT))
orm.Debug = true
orm.RegisterDriver("mysql", orm.DR_MySQL)
dataSrcName := "root:[email protected](localhost:3306)/default?charset=utf8&loc=Asia%2FShanghai"
orm.RegisterDataBase("default", "mysql", dataSrcName, 30)
dataSrcName = "root:[email protected](localhost:3306)/stellaraddr_info?charset=utf8&loc=Asia%2FShanghai"
orm.RegisterDataBase("stellaraddr_info", "mysql", dataSrcName, 30)
this.dbPointer = orm.NewOrm()
this.dbPointer.Using("stellaraddr_info")
orm.RunSyncdb("stellaraddr_info", false, true)
}
示例7: initDb
func initDb() {
iniconf, err := config.NewConfig("ini", "conf/app.conf")
if err != nil {
beego.Error(err)
}
driverName := iniconf.String("orm::driver_name")
dataSource := iniconf.String("orm::data_source")
maxIdle, _ := iniconf.Int("orm::max_idle_conn")
maxOpen, _ := iniconf.Int("orm::max_open_conn")
// set default database
err = orm.RegisterDataBase("default", driverName, dataSource, maxIdle, maxOpen)
if err != nil {
beego.Error(err)
}
// orm.Debug = true
//orm.RunCommand() //执行命令行的
err = orm.RunSyncdb("default", false, false) //建表的
////数据库别名,不强制建数据库,打印建表过程
if err != nil {
beego.Error(err)
}
}
示例8: init
func init() {
orm.RegisterDataBase("default", "sqlite3", DATABASEPATH)
orm.RegisterModel(new(DB_message), new(DB_transaction), new(DB_blocks), new(DB_send))
orm.RunSyncdb("default", false, true)
myorm = orm.NewOrm()
myorm.Using("default")
}
示例9: init
func init() {
orm.RegisterDriver("mymysql", orm.DR_MySQL)
orm.RegisterDataBase("default", "mymysql", "tcp:127.0.0.1:3306*test/root/mysql")
orm.Debug = true
orm.RegisterModel(new(Entity))
orm.BootStrap()
}
示例10: init
func init() {
// register model
orm.RegisterModel(new(User))
// set default database
orm.RegisterDataBase("go_blog", "postgres", "root:[email protected]/my_db?charset=utf8", 30)
}
示例11: RegistDB
func RegistDB() {
orm.RegisterModel(new(User), new(Article), new(Stream))
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterDataBase("default", "mysql", "root:[email protected]/newblog?charset=utf8")
orm.RunSyncdb("default", false, true)
}
示例12: init
func init() {
orm.RegisterDriver("mysql", orm.DRMySQL)
orm.RegisterDataBase("go", "mysql", "cmsuser:[email protected](10.255.223.241:3306)/bookbar_fuzuokui?charset=utf8")
orm.SetMaxIdleConns("go", 30) //设置数据库最大空闲连接
orm.SetMaxOpenConns("go", 30) //设置数据库最大连接数
orm.RegisterModel(new(GoBar))
}
示例13: initDb
func initDb(dbType string) {
orm.DefaultRowsLimit = -1
switch dbType {
case "mysql":
orm.RegisterDriver("mysql", orm.DRMySQL)
case "postgres":
orm.RegisterDriver("postgres", orm.DRPostgres)
default:
panic("not specific db Type")
}
var initOk bool
configerMap, _ := config.GlobalConfiger.Map(dbType)
for key, value := range configerMap {
if key == "default" {
initOk = true
}
if err := orm.RegisterDataBase(key, dbType, value.(string)); err != nil {
panic(err)
}
}
if !initOk {
panic("a database instance called default must be inited")
}
if config.GlobalConfiger.String("runmode") == "dev" {
orm.Debug = true
}
}
示例14: init
func init() {
if cfg, err := goconfig.LoadConfigFile("config.ini"); err == nil {
dbUser, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbuser")
dbPassword, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbpass")
dbHost, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbhost")
dbPort, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbport")
dbName, _ = cfg.GetValue(goconfig.DEFAULT_SECTION, "dbname")
} else {
log.Println("读取配置文件conf.ini失败")
}
orm.DefaultTimeLoc = time.Local
maxIdle := 50 //(可选) 设置最大空闲连接
maxConn := 100 //(可选) 设置最大数据库连接 (go >= 1.2)
connStr := fmt.Sprintf("%s:%[email protected](%s:%s)/%s?charset=utf8",
dbUser,
dbPassword,
dbHost,
dbPort,
dbName,
) + "&loc=" + url.QueryEscape("Local")
if err := orm.RegisterDataBase("default", "mysql",
connStr,
maxIdle,
maxConn,
); err != nil {
log.Println(err.Error())
}
}
示例15: init
func init() {
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterDataBase("default", "mysql", "user:[email protected]/ayp?charset=utf8")
orm.RegisterModel(new(models.Articulos), new(models.Categoria),
new(models.Proveedor), new(models.Usuarios), new(models.Empresa))
}