Exemple #1
0
func init() {
	orm.RegisterDriver("mysql", orm.DRMySQL)
	orm.RegisterDataBase("go", "mysql", "cmsuser:cms@tcp(10.255.223.241:3306)/bookbar_fuzuokui?charset=utf8")
	orm.SetMaxIdleConns("go", 30) //设置数据库最大空闲连接
	orm.SetMaxOpenConns("go", 30) //设置数据库最大连接数
	orm.RegisterModel(new(GoBar))
}
Exemple #2
0
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:autelan@/lte_test?charset=utf8&&loc=Asia%2FShanghai")

	orm.SetMaxIdleConns("default", 30)
	orm.SetMaxOpenConns("default", 30)
}
Exemple #3
0
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:Autelan1202@tcp(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()
}
//////////////////////////////////////////////////
// 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()
}
Exemple #5
0
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)
	case "dev":
		orm.Debug = true
		fallthrough
	default:
		orm.RegisterDriver("sqlite3", orm.DR_Sqlite)
		orm.RegisterDataBase(dbname, "sqlite3", 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()
}
Exemple #6
0
func init() {
	orm.RegisterDriver("mysql", orm.DRMySQL)
	orm.RegisterDataBase("default", "mysql", "cmsuser:cms@tcp(10.255.223.241:3306)/bookbar?charset=utf8")
	orm.SetMaxIdleConns("default", 30) //设置数据库最大空闲连接
	orm.SetMaxOpenConns("default", 30) //设置数据库最大连接数
	orm.RegisterModel(new(Bar))
	orm.Debug = true
}
Exemple #7
0
func init() {
	orm.RegisterDriver("mysql", orm.DRMySQL)
	// orm.RegisterDataBase("default", "mysql", "root:123456@/tcp(localhost:3306)bookbar?charset=utf8")
	orm.RegisterDataBase("default", "mysql", "cmsuser:cms@tcp(10.255.223.241:3306)/bookbar_fuzuokui?charset=utf8")
	orm.SetMaxIdleConns("default", 30)           //设置数据库最大空闲连接
	orm.SetMaxOpenConns("default", 30)           //设置数据库最大连接数
	orm.RegisterModelWithPrefix("go_", new(Bar)) //注册模型并使用表前缀
	orm.RegisterModelWithPrefix("go_", new(Article))
}
func init() {
	orm.RegisterDriver("mysql", orm.DR_MySQL)          //注册数据库驱动
	orm.RegisterDataBase("default", "mysql", mysqlUrl) //注册一个别名为default的数据库
	orm.SetMaxIdleConns("default", 30)                 //设置数据库最大空闲连接
	orm.SetMaxOpenConns("default", 30)                 //设置数据库最大连接数
	orm.RegisterModelWithPrefix("go_", new(Archives))  //注册模型并使用表前缀
	orm.RegisterModelWithPrefix("go_", new(Arctype))   //注册模型并使用表前缀
	orm.RegisterModelWithPrefix("go_", new(User))      //注册模型并使用表前缀
	orm.RunSyncdb("default", false, true)
	fmt.Println("init at models")
}