本文整理汇总了Golang中github.com/astaxie/beego/orm.RegisterDriver函数的典型用法代码示例。如果您正苦于以下问题:Golang RegisterDriver函数的具体用法?Golang RegisterDriver怎么用?Golang RegisterDriver使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegisterDriver函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: Connect
//数据库连接
func Connect() {
var dns string
db_type := beego.AppConfig.String("db_type")
db_host := beego.AppConfig.String("db_host")
db_port := beego.AppConfig.String("db_port")
db_user := beego.AppConfig.String("db_user")
db_pass := beego.AppConfig.String("db_pass")
db_name := beego.AppConfig.String("db_name")
db_path := beego.AppConfig.String("db_path")
db_sslmode := beego.AppConfig.String("db_sslmode")
switch db_type {
case "mysql":
orm.RegisterDriver("mysql", orm.DR_MySQL)
dns = fmt.Sprintf("%s:%[email protected](%s:%s)/%s?charset=utf8", db_user, db_pass, db_host, db_port, db_name)
break
case "postgres":
orm.RegisterDriver("postgres", orm.DR_Postgres)
dns = fmt.Sprintf("dbname=%s host=%s user=%s password=%s port=%s sslmode=%s", db_name, db_host, db_user, db_pass, db_port, db_sslmode)
case "sqlite3":
orm.RegisterDriver("sqlite3", orm.DR_Sqlite)
if db_path == "" {
db_path = "./"
}
dns = fmt.Sprintf("%s%s.db", db_path, db_name)
break
default:
beego.Critical("Database driver is not allowed:", db_type)
}
orm.RegisterDataBase("default", db_type, dns)
}
开发者ID:kerneltravel,项目名称:admin,代码行数:31,代码来源:AdminInit.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: InitDB
//初始化mysql或postgresql数据库,配置参数如下
//
// db_type 数据库类型,mysql或postgres(mysql)
//
// db_host 数据库主机地址(127.0.0.1)
//
// db_port 数据库端口(3306)
//
// db_user 数据库用户(root)
//
// db_pass 数据库密码
//
// db_name 数据库名
//
// db_sslmode 是否SSL模式连接,仅用于postgresql(disable)
func InitDB() {
if beego.BConfig.RunMode == "dev" {
beego.Info("initiating db")
}
var dsn string
db_type := beego.AppConfig.DefaultString("db_type", "mysql")
db_host := beego.AppConfig.DefaultString("db_host", "127.0.0.1")
db_port := beego.AppConfig.DefaultString("db_port", "3306")
db_user := beego.AppConfig.DefaultString("db_user", "root")
db_pass := beego.AppConfig.DefaultString("db_pass", "")
db_name := beego.AppConfig.String("db_name")
//db_path := beego.AppConfig.String("db_path")
db_sslmode := beego.AppConfig.DefaultString("db_sslmode", "disable")
switch db_type {
case "mysql":
orm.RegisterDriver("mysql", orm.DRMySQL)
dsn = fmt.Sprintf("%s:%[email protected](%s:%s)/%s?charset=utf8", db_user, db_pass, db_host, db_port, db_name)
break
case "postgres":
orm.RegisterDriver("postgres", orm.DRPostgres)
dsn = fmt.Sprintf("dbname=%s host=%s user=%s password=%s port=%s sslmode=%s", db_name, db_host, db_user, db_pass, db_port, db_sslmode)
// case "sqlite3":
// orm.RegisterDriver("sqlite3", orm.DR_Sqlite)
// if db_path == "" {
// db_path = "./"
// }
// dns = fmt.Sprintf("%s%s.db", db_path, db_name)
// break
default:
panic("Database driver is not allowed:" + db_type)
}
orm.RegisterDataBase("default", db_type, dsn)
}
开发者ID:sillydong,项目名称:goczd,代码行数:49,代码来源:init.go
示例4: 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
示例5: InitDB
// initialize the db driver and config
func InitDB(c *gokits.Crypto) {
if dbinited {
return
}
// 设置为 UTC 时间
orm.DefaultTimeLoc = time.UTC
orm.Debug = false
web, err := macaron.Config().GetSection("web")
if err != nil {
panic(err)
}
webcfg = web
sqllog := webcfg.Key("sqllog").String() // log the sql string
if "on" == sqllog {
orm.Debug = true
}
dbtype = web.Key("dbtype").String()
log.Debugf("DB type is %s", dbtype)
dbcfg, err := macaron.Config().GetSection(dbtype)
if err != nil {
panic(err)
}
switch dbtype {
case "mysql":
var username string = dbcfg.Key("username").String()
if username, err = c.DecryptStr(username); err != nil {
panic(err)
}
var password string = dbcfg.Key("password").String()
if password, err = c.DecryptStr(password); err != nil {
panic(err)
}
url := dbcfg.Key("url").String()
maxidle = dbcfg.Key("maxidle").MustInt(2)
maxconn = dbcfg.Key("maxconn").MustInt(2)
dburl = username + ":" + password + "@" + url
orm.RegisterDriver(dbtype, orm.DR_MySQL)
case "sqlite":
dburl = dbcfg.Key("url").String()
dbtype = "sqlite3"
orm.RegisterDriver(dbtype, orm.DR_Sqlite)
}
dbinited = true
}
开发者ID:xtfly,项目名称:goman,代码行数:53,代码来源:driver.go
示例6: 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
示例7: ConnectDB
//连接数据库
func ConnectDB() {
db_type := beego.AppConfig.String("db::type")
db_host := beego.AppConfig.String("db::host")
db_port := beego.AppConfig.String("db::port")
db_user := beego.AppConfig.String("db::user")
db_pass := beego.AppConfig.String("db::pass")
db_name := beego.AppConfig.String("db::name")
db_path := beego.AppConfig.String("db::path")
db_sslmode := beego.AppConfig.String("db::sslmode")
var dsn string
switch db_type {
case "mysql":
orm.RegisterDriver("mysql", orm.DR_MySQL)
dsn = fmt.Sprintf("%s:%[email protected](%s:%s)/%s?charset=utf8", db_user, db_pass, db_host, db_port, db_name)
dsn += "&loc=Asia%2FShanghai"
break
case "postgres":
orm.RegisterDriver("postgres", orm.DR_Postgres)
dsn = fmt.Sprintf("dbname=%s host=%s user=%s password=%s port=%s sslmode=%s", db_name, db_host, db_user, db_pass, db_port, db_sslmode)
case "sqlite3":
orm.RegisterDriver("sqlite3", orm.DR_Sqlite)
if db_path == "" {
db_path = "./"
}
dsn = fmt.Sprintf("%s%s.db", db_path, db_name)
break
default:
beego.Critical("Database driver not support: ", db_type)
}
orm.RegisterDataBase("default", db_type, dsn)
//打印查询日志
orm.Debug, _ = beego.AppConfig.Bool("db::orm_debug")
o = orm.NewOrm()
// 数据库别名
name := "default"
// 不强制重新建数据库
force := false
// 打印执行过程
verbose := true
// 遇到错误立即返回
err := orm.RunSyncdb(name, force, verbose)
if err != nil {
beego.Error(err)
}
}
开发者ID:kevinxu001,项目名称:survey,代码行数:51,代码来源:db.go
示例8: RegistDB
func RegistDB() {
host := beego.AppConfig.String("DBhost")
dataSource := "root:[email protected](" + host + ":3306)/test?charset=utf8"
orm.RegisterModel(new(Category), new(Topic), new(Reply))
orm.RegisterDriver("mysql", orm.DRMySQL)
orm.RegisterDataBase("default", "mysql", dataSource)
}
开发者ID:arvinkai,项目名称:Mytestbolg,代码行数:7,代码来源:models.go
示例9: init
func init() {
orm.Debug = true
orm.RegisterDriver("sqlite", orm.DR_Sqlite)
orm.RegisterDataBase("default", "sqlite3", "./gowebssh.db")
}
开发者ID:wuwenbao,项目名称:GoWebSSH,代码行数:7,代码来源:base.go
示例10: 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
示例11: connectDB
func connectDB() {
orm.RegisterDriver("mysql", orm.DR_MySQL)
name := utils.GetConf().String("db::name")
user := utils.GetConf().String("db::user")
pass := utils.GetConf().String("db::pass")
host := utils.GetConf().String("db::host")
port := utils.GetConf().String("db::port")
//data source name
// dsn := fmt.Sprintf("%s:%[email protected](%s:%s)/%s?charset=utf8", user, pass, host, port, name)
dsn := fmt.Sprintf("%s:%[email protected](%s:%s)/%s?charset=utf8&loc=Local", user, pass, host, port, name)
orm.RegisterDataBase("default", "mysql", dsn)
orm.RegisterModel(new(User), new(Project), new(ProjectLog))
orm.RegisterModel(new(Company), new(Job), new(Progress))
orm.RegisterModel(new(File), new(JobComplaint), new(JobProgress))
orm.RegisterModel(new(JobValid), new(JobClaim), new(JobSubmit))
orm.RegisterModel(new(UserLogin), new(JobAssign))
orm.RegisterModel(new(JobHistory), new(JobComplaintReply))
orm.RegisterModel(new(Require))
db = orm.NewOrm()
setMaxIdleConns()
}
开发者ID:zbzzbd,项目名称:beego,代码行数:25,代码来源:init.go
示例12: 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
示例13: init
func init() {
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterDataBase("default", "mysql", "root:[email protected](localhost:8889)/MtimeCI?charset=utf8&loc=Asia%2FShanghai")
orm.Debug = true
}
开发者ID:beerbubble,项目名称:MtimeCI,代码行数:7,代码来源:main.go
示例14: main
func main() {
setting.Initialize()
beego.SetLogFuncCall(true)
beego.SetViewsPath("views")
if setting.IsProMode {
beego.Info(setting.PostgresMigrateConnection)
//auto migrate db
//todo: we may want to disable this later
//dbMigrate()
} else {
beego.Info("Develment mode enabled")
}
dbMigrate()
beego.Info(beego.BConfig.AppName, setting.APP_VER, setting.AppUrl)
testOnly() //todo:remove this
//dev directory listing
if !setting.IsProMode {
beego.SetStaticPath("/assets", "static/dist/assets")
beego.BConfig.WebConfig.DirectoryIndex = true
}
orm.RegisterDriver("postgres", orm.DRPostgres)
orm.RegisterDataBase("default", "postgres", setting.PostgresConnection)
services.Register()
orm.RunCommand()
orm.Debug = true
controllers.RegisterControllers()
if beego.BConfig.RunMode == "dev" {
// beego.Router("/test/:tmpl(mail/.*)", new(base.TestRouter))
}
beego.Run()
}
开发者ID:thanzen,项目名称:identity,代码行数:35,代码来源:main.go
示例15: init
func init() {
//For version 1.6
//orm.DRMySQL
//orm.DRSqlite
//orm.DRPostgres
// < 1.6
//orm.DR_MySQL
//orm.DR_Sqlite
//orm.DR_Postgres
// 参数1 driverName
// 参数2 数据库类型
// 这个用来设置 driverName 对应的数据库类型
// mysql / sqlite3 / postgres 这三种是默认已经注册过的,所以可以无需设置
orm.RegisterDriver("mysql", orm.DRMySQL)
// 参数1 数据库的别名,用来在ORM中切换数据库使用
// 参数2 driverName
// 参数3 对应的链接字符串
orm.RegisterDataBase("default", "mysql", "root:[email protected]/sport_collage?charset=utf8")
// 参数4(可选) 设置最大空闲连接
// 参数5(可选) 设置最大数据库连接 (go >= 1.2)
//maxIdle := 30
//maxConn := 30
//orm.RegisterDataBase("default", "mysql", "root:[email protected]/orm_test?charset=utf8", maxIdle, maxConn)
orm.RunSyncdb("default", false, false)
}
开发者ID:renxuetao,项目名称:SportCollage,代码行数:29,代码来源:main.go
示例16: init
func init() {
// orm.RegisterDataBase("default", "mysql", "root:[email protected](localhost:3306)/qq?charset=utf8")
orm.RegisterDataBase("default", "mysql", "cdb_outerroot:[email protected](55c354e17de4e.sh.cdb.myqcloud.com:7276)/qq?charset=utf8")
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterModel(new(User), new(Profile), new(Userz), new(Friends))
ORM = orm.NewOrm()
}
开发者ID:shaalx,项目名称:orm_test,代码行数:7,代码来源:main.go
示例17: initORM
func initORM() {
if ormInitiated {
return
}
appConf, err := config.NewConfig("ini", "conf/app.conf")
if err != nil {
panic(err)
}
dbAddr := appConf.String("admin::dbAddr")
dbUser := appConf.String("admin::dbUser")
dbPass := appConf.String("admin::dbPass")
controllers.ALI_YUN_AK_ID = appConf.String("admin::akId")
controllers.ALI_YUN_AK_KEY = appConf.String("admin::akKey")
controllers.QQ_OAUTH_CONSUMER_KEY = appConf.String("admin::qqOAuthConsumerKey")
clientId := appConf.String("admin::clientId")
clientSecret := appConf.String("admin::clientSecret")
controllers.BASIC_AUTH_AUTHORIZATION = utils.Base64(clientId + ":" + clientSecret)
controllers.VISITOR_TOKEN = appConf.String("admin::visitorToken")
orm.RegisterDriver("mymysql", orm.DRMySQL)
conn := fmt.Sprintf("%s:%[email protected](%s)/beego_unit_test?charset=utf8mb4", dbUser, dbPass, dbAddr)
orm.RegisterDataBase("default", "mysql", conn)
ormInitiated = true
}
开发者ID:Piasy,项目名称:BeegoTDDBootStrap,代码行数:25,代码来源:common_ops.go
示例18: init
func init() {
duangcfg, err := config.NewConfig("ini", "conf/duang.conf")
if err != nil {
fmt.Println(err)
return
}
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterDataBase("default", "mysql", fmt.Sprintf("%s:%[email protected]%s/%s?charset=utf8", duangcfg.String("db_user"), duangcfg.String("db_pass"), duangcfg.String("db_addr"), duangcfg.String("db_name")))
orm.RegisterModel(
new(Unit),
new(UnitParameter),
new(Dockerd),
new(Ip),
new(Container),
//new(Frontend),
//new(Backend),
)
force, err := duangcfg.Bool("db_dropifexist")
if err != nil {
force = false
}
verbose := true
err = orm.RunSyncdb("default", force, verbose)
if err != nil {
beego.Error(err)
}
}
开发者ID:lilwulin,项目名称:duang,代码行数:31,代码来源:init.go
示例19: 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
示例20: init
func init() {
//读取配置文件信息
settings := func(path string) map[string]string {
return goutils.NewConfig().Load(path).GlobalContent()
}("conf/app.conf")
//获取settings中的信息
dbinfo, ok := settings["DBINFO"]
if !ok {
log.Fatal("not found DBINFO in config file")
}
orm.RegisterDriver("mysql", orm.DRMySQL)
orm.RegisterDataBase("default", "mysql", dbinfo)
orm.RegisterModel(
new(First),
new(Second),
new(System),
new(Userinfo),
new(Userlog),
new(Novel),
new(Content),
new(Collectrank),
new(Clickrank),
new(Recommend),
)
}
开发者ID:aosen,项目名称:novel,代码行数:25,代码来源:basemodel.go
注:本文中的github.com/astaxie/beego/orm.RegisterDriver函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论