本文整理汇总了Golang中github.com/astaxie/beego/orm.RegisterDataBase函数的典型用法代码示例。如果您正苦于以下问题:Golang RegisterDataBase函数的具体用法?Golang RegisterDataBase怎么用?Golang RegisterDataBase使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegisterDataBase函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()
}
开发者ID:tcdog001,项目名称:ums,代码行数:35,代码来源:db.go
示例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()
}
开发者ID:gusa1120,项目名称:beego_sample,代码行数:35,代码来源:db.go
示例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
}
}
开发者ID:donh,项目名称:alarm,代码行数:11,代码来源:database.go
示例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)
}
}
开发者ID:wcreate,项目名称:lawoto,代码行数:52,代码来源:driver.go
示例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
}
}
开发者ID:myhung,项目名称:query,代码行数:15,代码来源:http.go
示例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)
}
开发者ID:jojopoper,项目名称:UpdateStellarAddrDB,代码行数:15,代码来源:stellaraddress.go
示例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)
}
}
开发者ID:oyoy8629,项目名称:hellodb,代码行数:26,代码来源:init.go
示例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")
}
开发者ID:Wishing-Wall,项目名称:wishingwall,代码行数:7,代码来源:dbutil.go
示例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()
}
开发者ID:nivance,项目名称:go-example,代码行数:7,代码来源:model.go
示例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)
}
开发者ID:paradox41,项目名称:go-blog,代码行数:7,代码来源:main.go
示例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)
}
开发者ID:uguangtian,项目名称:go-newblog,代码行数:7,代码来源:models.go
示例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))
}
开发者ID:fuzuokui,项目名称:timerapp,代码行数:7,代码来源:goBarModel.go
示例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
}
}
开发者ID:DrWrong,项目名称:monica,代码行数:31,代码来源:database.go
示例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())
}
}
开发者ID:endville,项目名称:gpsgate,代码行数:31,代码来源:db.go
示例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))
}
开发者ID:carlosjml4,项目名称:artyprovee,代码行数:7,代码来源:main.go
示例16: init
func init() {
orm.RegisterDriver("mysql", orm.DR_MySQL)
err := orm.RegisterDataBase("default", "mysql", global.C.MySqlUrl)
if err != nil {
fmt.Println(err)
}
}
开发者ID:playnb,项目名称:mustang,代码行数:7,代码来源:sqldb.go
示例17: init
func init() {
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterDataBase("default", "mysql", "root:[email protected](localhost:3306)/os?charset=utf8")
orm.RegisterModel(new(Groups), new(User), new(Grel))
ORM = orm.NewOrm()
orm.Debug = true
}
开发者ID:shaalx,项目名称:orm_test,代码行数:7,代码来源:main.go
示例18: InitDB
//InitDB initializes the database
func InitDB() {
orm.RegisterDriver("mysql", orm.DRMySQL)
addr := os.Getenv("MYSQL_HOST")
port := os.Getenv("MYSQL_PORT")
username := os.Getenv("MYSQL_USR")
password := os.Getenv("MYSQL_PWD")
log.Debugf("db url: %s:%s, db user: %s", addr, port, username)
dbStr := username + ":" + password + "@tcp(" + addr + ":" + port + ")/registry"
ch := make(chan int, 1)
go func() {
var err error
var c net.Conn
for {
c, err = net.DialTimeout("tcp", addr+":"+port, 20*time.Second)
if err == nil {
c.Close()
ch <- 1
} else {
log.Errorf("failed to connect to db, retry after 2 seconds :%v", err)
time.Sleep(2 * time.Second)
}
}
}()
select {
case <-ch:
case <-time.After(60 * time.Second):
panic("Failed to connect to DB after 60 seconds")
}
err := orm.RegisterDataBase("default", "mysql", dbStr)
if err != nil {
panic(err)
}
}
开发者ID:CodingDance,项目名称:harbor,代码行数:35,代码来源:base.go
示例19: init
func init() {
//register all tables
orm.RegisterModel(new(Userinfo), new(Admininfo), new(Deviceinfo), new(Historyinfo), new(Command), new(OperationRecord), new(Alarm), new(Script))
//register mysql driver
err := orm.RegisterDriver("mysql", orm.DR_MySQL)
if err != nil {
beego.Critical(err)
}
//register default database
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.RegisterDataBase("default", "mysql", "root:[email protected]/lte_test?charset=utf8&&loc=Asia%2FShanghai")
orm.SetMaxIdleConns("default", 30)
orm.SetMaxOpenConns("default", 30)
}
开发者ID:tcdog001,项目名称:szm_lms,代码行数:27,代码来源:init.go
示例20: init
func init() {
/* 로그기록 */
//NewLogger(10000)
beego.SetLogger("file", `{"filename":"server.log"}`)
/* 데이타베이스 드라이브 설정 */
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterDataBase("default", "mysql", "root:[email protected]/cluber?charset=utf8&loc=Asia%2FSeoul")
/* 데이타베이스 테이블 등록 */
orm.RegisterModel(new(models.User))
orm.RegisterModel(new(models.Log))
orm.RegisterModel(new(models.Contents))
// 사용 데이타베이스
name := "default"
// 서버 시작시 테이블 재생성
force := false
// SQL 로그 확인
verbose := true
// 데이타베이스를 동기화 하고 에러 발생시 err 에 에러내용 입력
err := orm.RunSyncdb(name, force, verbose)
if err != nil {
fmt.Println(err)
}
}
开发者ID:GeoLyu,项目名称:test,代码行数:27,代码来源:main.go
注:本文中的github.com/astaxie/beego/orm.RegisterDataBase函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论