本文整理汇总了Golang中github.com/astaxie/beego/orm.RegisterModel函数的典型用法代码示例。如果您正苦于以下问题:Golang RegisterModel函数的具体用法?Golang RegisterModel怎么用?Golang RegisterModel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RegisterModel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: initDb
func initDb() *gorp.DbMap {
//orm
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterDataBase("default", "mysql", "root:[email protected]/beego?charset=utf8&loc=Asia%2FSeoul")
// Set to UTC time
//orm.DefaultTimeLoc, _ = time.LoadLocation("Asia/Seoul")
orm.RegisterModel(new(models.User))
orm.RegisterModel(new(models.Log))
orm.RegisterModel(new(models.Board))
//gorp
db, err := sql.Open("mysql", "root:[email protected](127.0.0.1:3306)/beego")
checkErr(err, "SQL 연결 성공", "SQL 연결 실패")
dbmap := &gorp.DbMap{Db: db, Dialect: gorp.MySQLDialect{"InnoDB", "UTF8"}}
//테이블 생성
//속성선언.이름과 함께 테이블 생성(호출.구조체{}, "생성될 테이블 이름").값 증가설정(예,"구조체의 Idx")
dbmap.AddTableWithName(models.User{}, "user").SetKeys(true, "Idx")
dbmap.AddTableWithName(models.Log{}, "log")
dbmap.AddTableWithName(models.Board{}, "board").SetKeys(true, "Idx")
err = dbmap.CreateTablesIfNotExists()
checkErr(err, "테이블 생성 성공", "테이블 생성 실패")
return dbmap
}
示例2: init
func init() {
orm.RegisterModel(new(models.Idea))
orm.RegisterModel(new(models.User))
orm.RegisterModel(new(models.File))
orm.RegisterModel(new(models.Comment))
orm.RegisterDataBase("default", "postgres", "user=goidea password=goidea host=localhost port=5432 dbname=goidea sslmode=disable", 30)
}
示例3: init
func init() {
//dbhost := beego.AppConfig.String("dbhost")
dbport := beego.AppConfig.String("dbport")
dbuser := beego.AppConfig.String("dbuser")
dbpassword := beego.AppConfig.String("dbpassword")
dbname := beego.AppConfig.String("dbname")
if dbport == "" {
dbport = "3306"
}
dsn := dbuser + ":" + dbpassword + "@tcp(localhost:3306)/" + dbname + "?charset=utf8&loc=Asia%2FShanghai"
if os.Getenv("DB_USER") != "" {
fmt.Println("DB_USER: " + os.Getenv("DB_USER"))
dsn = os.Getenv("DB_USER") + ":" + os.Getenv("DB_PASS") + "@tcp(" + os.Getenv("DB_HOST") + ")/docker-weekly?charset=utf8&loc=Asia%2FShanghai"
}
fmt.Println("dsn: " + dsn)
//orm.RegisterDriver("mysql", orm.DR_MySQL)
dbmaxIdle, _ := beego.AppConfig.Int("dbmaxIdle")
dbmaxConn, _ := beego.AppConfig.Int("dbmaxConn")
orm.RegisterDataBase("default", "mysql", dsn, dbmaxIdle, dbmaxConn)
orm.RegisterModel(new(Article))
orm.RegisterModel(new(Apps))
if beego.AppConfig.String("mode") != "pro" {
orm.Debug = true
}
}
示例4: 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)
}
}
示例5: init
func init() {
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterDataBase("default", "mysql", "root:[email protected]/pets-clinic?charset=utf8")
orm.RegisterModel(new(Pet))
orm.RegisterModel(new(Visit))
orm.RunCommand()
orm.Debug = true
}
示例6: init
func init() {
orm.Debug, _ = beego.AppConfig.Bool("orm_debug")
orm.RegisterModel(new(Invest_Contract))
orm.RegisterModel(new(Lov))
orm.RegisterModel(new(Master))
orm.RegisterModel(new(Topic))
}
示例7: init
func init() {
orm.Debug = true
orm.RegisterModel(new(models.Location))
orm.RegisterModel(new(models.Photo))
orm.RegisterModel(new(models.Agent))
orm.RegisterModel(new(models.House))
orm.RegisterDriver("mysql", orm.DR_MySQL)
orm.RegisterDataBase("default", "mysql", "[email protected]/go_api_db?charset=utf8", 30)
}
示例8: init
func init() {
orm.RegisterModel(new(models.Idea))
orm.RegisterModel(new(models.User))
orm.RegisterDataBase("default", "postgres", "user=goidea password=goidea host=localhost port=5432 dbname=test sslmode=disable", 30)
err := orm.RunSyncdb("default", true, false)
if err != nil {
fmt.Println(err)
}
//orm.Debug = true
}
示例9: RegisterDB
func RegisterDB() {
if !com.IsExist(_DB_NAME) {
os.MkdirAll(path.Dir(_DB_NAME), os.ModePerm)
os.Create(_DB_NAME)
}
orm.RegisterModel(new(Todo))
orm.RegisterModel(new(Task))
orm.RegisterDriver(_SQLITE3_DRIVER, orm.DR_Sqlite)
orm.RegisterDataBase("default", _SQLITE3_DRIVER, _DB_NAME, 10)
}
示例10: init
func init() {
orm.Debug = true
orm.RegisterDataBase("default", "mysql", beego.AppConfig.String("mysql_conf"))
orm.RegisterModel(new(Posts))
orm.RegisterModel(new(Users))
orm.RegisterModel(new(Options))
orm.RegisterModel(new(Cates))
orm.RegisterModel(new(Links))
o = orm.NewOrm()
}
示例11: init
func init() {
orm.RegisterModel(new(Executionlog))
orm.RegisterModel(new(User))
orm.RegisterModel(new(Projectinfo))
orm.RegisterModel(new(Environmentinfo))
orm.RegisterModel(new(Projectbranch))
orm.RegisterModel(new(Projectenvironment))
orm.RegisterModel(new(Projectbuild))
orm.RegisterModel(new(Moduleinfo))
orm.RegisterModel(new(Rundeckserver))
orm.RegisterModel(new(Rundeckjob))
}
示例12: init
func init() {
orm.RegisterModel(new(models.Jt_user))
orm.RegisterModel(new(models.Jt_content))
orm.RegisterModel(new(models.Jt_comment))
orm.RegisterDriver("mysql", orm.DR_MySQL)
// 参数1 自定义的数据库名称,用来在orm中切换数据库使用
// 参数2 driverName
// 参数3 对应的链接字符串
// 参数4 设置最大的空闲连接数,使用 golang 自己的连接池
orm.RegisterDataBase("default", "mysql", "root:[email protected](112.124.17.181:3306)/joneto?charset=utf8", 30)
orm.BootStrap() // 强制在 main 函数里调用,检查 Model 关系,检测数据库参数,调用 orm 提供的 Command
}
示例13: registerDB
func registerDB() {
orm.Debug = true
sqlEnv := os.Getenv("SQL_SOURCE")
if sqlEnv == "" {
sqlEnv = DATA_SOURCE
}
orm.RegisterDataBase("default", DRIVER_NAME, sqlEnv, MAX_IDLE_CONN, MAX_OPEN_CONN)
// orm.RegisterModel(new(ServiceCount))
orm.RegisterModel(new(PurchaseOrder))
orm.RegisterModel(new(PurchaseOrderDetail))
orm.RunSyncdb("default", false, true)
}
示例14: 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)
}
}
示例15: InitEntity
func InitEntity() {
orm.RegisterModel(new(entities.Article))
orm.RegisterModel(new(entities.Category))
orm.RegisterModel(new(entities.Parameter))
orm.RegisterModel(new(entities.User))
orm.RegisterModel(new(entities.ArticleLike))
orm.RegisterModel(new(entities.ArticleView))
orm.RegisterModel(new(entities.Tag))
orm.RegisterModel(new(entities.OpenUser))
orm.RegisterModel(new(entities.SystemMail))
}