当前位置: 首页>>代码示例>>Golang>>正文


Golang orm.RunSyncdb函数代码示例

本文整理汇总了Golang中github.com/astaxie/beego/orm.RunSyncdb函数的典型用法代码示例。如果您正苦于以下问题:Golang RunSyncdb函数的具体用法?Golang RunSyncdb怎么用?Golang RunSyncdb使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了RunSyncdb函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: 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"
	// }

	//注册mysql Driver
	orm.RegisterDriver("mysql", orm.DRMySQL)
	//构造conn连接
	conn := dbuser + ":" + dbpassword + "@/" + dbname + "?charset=utf8"
	//数据库别名
	alice := "default"
	//不强制建数据库
	force := false
	//打印建表过程
	verbose := true

	orm.RegisterDataBase(alice, "mysql", conn)
	orm.RegisterModel(new(Admin), new(Article), new(ArticleCate), new(AutoUser), new(Baoliao), new(Item), new(ItemCate), new(ItemComment), new(ItemTag), new(Mall), new(Tag))
	//建表
	err := orm.RunSyncdb(alice, force, verbose)
	if err != nil {
		beego.Error(err)
	}

	if beego.AppConfig.String("runmode") == "dev" {
		orm.Debug = true
	}

}
开发者ID:ludivicio,项目名称:numa,代码行数:35,代码来源:base.go

示例2: 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

示例3: init

// Init will initialize database to create tables automatically.
func init() {
	// Registry archci database models.
	models.RegisterModels()

	// Initialize database with environment variables.
	server := ""
	username := "root"
	password := "root"
	database := "mysql"

	if os.Getenv(ENV_MYSQL_SERVER) != "" {
		server = os.Getenv(ENV_MYSQL_SERVER)
	}
	if os.Getenv(ENV_MYSQL_USERNAME) != "" {
		username = os.Getenv(ENV_MYSQL_USERNAME)
	}
	if os.Getenv(ENV_MYSQL_PASSWORD) != "" {
		password = os.Getenv(ENV_MYSQL_PASSWORD)
	}
	if os.Getenv(ENV_MYSQL_DATABASE) != "" {
		database = os.Getenv(ENV_MYSQL_DATABASE)
	}

	// The datasource looks like "root:[email protected]/archci?charset=utf8".
	DATASOURCE := username + ":" + password + "@" + server + "/" + database + "?charset=utf8"
	fmt.Println("Connect to database with " + DATASOURCE)

	orm.RegisterDriver(MYSQL_DRIVER, orm.DR_MySQL)
	orm.RegisterDataBase("default", MYSQL_DRIVER, DATASOURCE, 30)
	orm.RunSyncdb("default", false, true)
}
开发者ID:hanjinze,项目名称:archci,代码行数:32,代码来源:main.go

示例4: 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

示例5: main

func main() {
	orm.Debug = true
	orm.RunSyncdb("default", false, true)
	/* 设置Session配置*/
	beego.SessionOn = false
	beego.Run()
}
开发者ID:jaguarWang,项目名称:webpage,代码行数:7,代码来源:main.go

示例6: 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

示例7: main

func main() {
	orm.Debug = true
	orm.RunSyncdb("default", true, true)
	beego.Router("/", &controllers.MainController{})

	beego.Run()
}
开发者ID:zykzhang,项目名称:practice,代码行数:7,代码来源:main.go

示例8: LoadConfig

func LoadConfig() {
	redisServer := beego.AppConfig.String("redis_resource")
	redisServer = "{\"conn\":\"" + redisServer + "\"}"
	store, err := cache.NewCache("redis", redisServer)
	if err != nil {
		log.Panic("缓存出错" + err.Error())
	}
	Captcha = captcha.NewWithFilter("/captcha/", store)

	driverName := beego.AppConfig.String("driverName")
	dataSource := beego.AppConfig.String("dataSource")
	maxIdle, _ := beego.AppConfig.Int("maxIdle")
	maxOpen, _ := beego.AppConfig.Int("maxOpen")

	orm.RegisterDriver("mysql", orm.DR_MySQL)

	// set default database
	err = orm.RegisterDataBase("default", driverName, dataSource, maxIdle, maxOpen)
	if err != nil {
		beego.Error(err)
	}
	orm.RunCommand()

	err = orm.RunSyncdb("default", false, false)
	if err != nil {
		beego.Error(err)
	}
	SocialAuthInit()

	config.InitConfig()
}
开发者ID:ming-hai,项目名称:account,代码行数:31,代码来源:setting.go

示例9: main

func main() {
	// Database alias.
	name := "default"

	// Drop table and re-create.
	force := true

	// Print log.
	verbose := true

	// Error.
	err := orm.RunSyncdb(name, force, verbose)
	if err != nil {
		fmt.Println(err)
	}
	o := orm.NewOrm()
	o.Using("default")
	seed(o)

	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowAllOrigins: true,
	}))

	beego.Run()
}
开发者ID:quannguyen89,项目名称:beego_api_demo,代码行数:25,代码来源:main.go

示例10: main

func main() {

	// get config data
	db_driver := beego.AppConfig.String("db_driver")
	if db_driver != "" {
		log.Println("db_driver: ", db_driver)
	}
	db_source := beego.AppConfig.String("db_source")
	if db_source != "" {
		log.Println("db_source: ", db_source)
	}
	db_maxidle, err := beego.AppConfig.Int("db_maxidle")
	if err == nil && db_maxidle != 0 {
		log.Println("db_maxidle: ", db_maxidle)
	}
	db_maxconn, err := beego.AppConfig.Int("db_maxconn")
	if err == nil && db_maxconn != 0 {
		log.Println("db_maxconn: ", db_maxconn)
	}

	// set database
	err = orm.RegisterDataBase("default", db_driver, db_source, db_maxidle, db_maxconn)
	if err != nil {
		beego.Error(err)
	}
	err = orm.RunSyncdb("default", false, false)
	if err != nil {
		beego.Error(err)
	}

	beego.SetStaticPath("/upload", "upload")

	beego.SessionOn = true
	beego.Run()
}
开发者ID:codeshredder,项目名称:infoboard,代码行数:35,代码来源:main.go

示例11: DBInit

func DBInit() {
	orm.Debug = true

	orm.RegisterDataBase("default", "sqlite3", "data.db", 30)
	orm.RunSyncdb("default", true, true)

	o := orm.NewOrm()
	o.Using("default")

	user := &User{
		Account:  "[email protected]",
		Password: "admin",
		Showname: "管理员",
	}

	h := md5.New()
	h.Write([]byte(user.Password))
	user.Password = hex.EncodeToString(h.Sum(nil))

	id, err := o.Insert(user)
	if err != nil {
		log.Info("%s.", err.Error())
	} else {
		log.Info("User added,ID is:%d.", id)
	}
}
开发者ID:hugb,项目名称:beegeserver,代码行数:26,代码来源:migration.go

示例12: init

//////////////////////////////////////////////////
// init initializes the database and rebuilds the tables from file data
func init() {
	dbuser := beego.AppConfig.String("mysqluser")
	dbpass := beego.AppConfig.String("mysqlpass")
	database := beego.AppConfig.String("mysqldb")

	orm.RegisterDataBase("default", "mysql", dbuser+":"+dbpass+"@/"+database+"?charset=utf8")
	orm.SetMaxIdleConns("default", 30)
	orm.SetMaxOpenConns("default", 30)

	orm.RegisterModel(new(User), new(Project), new(ProjectUser), new(Message), new(Star), new(Groups), new(GroupUser), new(Rights), new(SessionToken))

	// Drop all runtime tables
	o := orm.NewOrm()
	o.Raw("SET FOREIGN_KEY_CHECKS=0;").Exec()
	_, err := o.Raw("TRUNCATE TABLE user;").Exec()
	if err != nil {
		// If table can't be truncated, rebuild all tables (CAUTION: Star and Message db are lost!)
		// This is only for absolute startup
		err := orm.RunSyncdb("default", true, true)
		if err != nil {
			beego.Error(err)
		}
	}
	o.Raw("TRUNCATE TABLE message;").Exec()
	o.Raw("TRUNCATE TABLE rights;").Exec()
	o.Raw("TRUNCATE TABLE project;").Exec()
	o.Raw("TRUNCATE TABLE project_user;").Exec()
	o.Raw("TRUNCATE TABLE groups;").Exec()
	o.Raw("TRUNCATE TABLE group_user;").Exec()
	o.Raw("SET FOREIGN_KEY_CHECKS=1;").Exec()

	createAllUserDatabaseEntries()
}
开发者ID:lafisrap,项目名称:Computer-Spielplatz,代码行数:35,代码来源:models.go

示例13: main

func main() {
	orm.Debug = true
	orm.RunSyncdb("default", false, true)

	beego.Router("/", &controllers.MainController{})
	beego.Router("/login", &controllers.LoginController{})
	beego.Router("/category", &controllers.CategoryController{})
	beego.Router("/reply", &controllers.ReplyController{})
	beego.AutoRouter(&controllers.ReplyController{})
	beego.Router("/topic", &controllers.TopicController{})
	beego.AutoRouter(&controllers.TopicController{})

	os.Mkdir("attachment", os.ModePerm)
	beego.SetStaticPath("/attachment", "attachment")

	err := i18n.SetMessage("en-US", "conf/locale_en-US.ini")
	if err != nil {
		beego.Error(err)
	}
	err = i18n.SetMessage("zh-CN", "conf/locale_zh-CN.ini")
	if err != nil {
		beego.Error(err)
	}
	err = i18n.SetMessage("zh-HK", "conf/locale_zh-HK.ini")
	if err != nil {
		beego.Error(err)
	}

	beego.AddFuncMap("i18n", i18n.Tr)

	beego.Run()
}
开发者ID:xuzhenglun,项目名称:Blog-Go,代码行数:32,代码来源:main.go

示例14: init

func init() {
	//orm.RegisterDataBase("default", "mysql", "[email protected]/gotalk?charset=utf8", 30)
	beego.AppConfigPath = "../conf/app.conf"
	beego.ParseConfig()
	setting.ReadConfig()
	orm.RunSyncdb("default", true, false)
}
开发者ID:naokij,项目名称:gotalk,代码行数:7,代码来源:category_test.go

示例15: Syncdb

/**
* 同步数据库
 */
func Syncdb() {

	createdb()
	Connect()
	o = orm.NewOrm()

	// 数据库别名
	name := "default"
	// drop table 后再建表
	force := true
	// 打印执行过程
	verbose := true
	// 遇到错误立即返回

	err := orm.RunSyncdb(name, force, verbose)
	if err != nil {
		fmt.Println(err)
	}
	insertUser()
	insertCategory()
	insertShop()
	insertFood()
	//insertNodes()
	fmt.Println("database init is complete.\nPlease restart the application")

}
开发者ID:lvzhongyi,项目名称:canku,代码行数:29,代码来源:syncdb.go


注:本文中的github.com/astaxie/beego/orm.RunSyncdb函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。