Exemple #1
0
func initDb() *gorp.DbMap {
	//orm
	orm.RegisterDriver("mysql", orm.DR_MySQL)
	orm.RegisterDataBase("default", "mysql", "root:Kim616294.@/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:Kim616294.@tcp(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
}
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)
}
Exemple #3
0
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: "******"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
	}
}
Exemple #4
0
func init() {
	/* 로그기록 */
	//NewLogger(10000)
	beego.SetLogger("file", `{"filename":"server.log"}`)

	/* 데이타베이스 드라이브 설정 */
	orm.RegisterDriver("mysql", orm.DR_MySQL)
	orm.RegisterDataBase("default", "mysql", "root:Kim616294.@/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)
	}

}
Exemple #5
0
func init() {
	orm.RegisterDriver("mysql", orm.DR_MySQL)
	orm.RegisterDataBase("default", "mysql", "root:pass@/pets-clinic?charset=utf8")
	orm.RegisterModel(new(Pet))
	orm.RegisterModel(new(Visit))
	orm.RunCommand()
	orm.Debug = true
}
Exemple #6
0
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))
}
Exemple #7
0
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", "root@/go_api_db?charset=utf8", 30)
}
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
}
Exemple #9
0
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)
}
Exemple #10
0
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()
}
Exemple #11
0
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))
}
Exemple #12
0
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:123456!a@tcp(112.124.17.181:3306)/joneto?charset=utf8", 30)
	orm.BootStrap() // 强制在 main 函数里调用,检查 Model 关系,检测数据库参数,调用 orm 提供的 Command
}
Exemple #13
0
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)
}
Exemple #14
0
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)
	}
}
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))
}
Exemple #16
0
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
	}
}
Exemple #17
0
func init() {
    // register model
    orm.RegisterModel(new(User))

    // set default database
    orm.RegisterDataBase("go_blog", "postgres", "root:root@/my_db?charset=utf8", 30)
}
Exemple #18
0
func RegistDB() {
	orm.RegisterModel(new(User), new(Article), new(Stream))
	orm.RegisterDriver("mysql", orm.DR_MySQL)
	orm.RegisterDataBase("default", "mysql", "root:mysql@/newblog?charset=utf8")
	orm.RunSyncdb("default", false, true)

}
Exemple #19
0
func init() {
	//获取服务器数据库相关信息
	dbhost := beego.AppConfig.String("db_host")
	dbport := beego.AppConfig.String("db_port")
	dbuser := beego.AppConfig.String("db_user")
	dbpassword := beego.AppConfig.String("db_pass")
	dbname := beego.AppConfig.String("db_name")
	dbIdle, _ := beego.AppConfig.Int("db_max_idle_conn")
	dbConn, _ := beego.AppConfig.Int("db_max_open_conn")

	dburl := dbuser + ":" + dbpassword + "@tcp(" + dbhost + ":" + dbport + ")/" + dbname + "?charset=utf8"
	orm.RegisterDataBase("default", "mysql", dburl, dbIdle, dbConn)

	//注册模型
	orm.RegisterModel(new(Category), new(Topic), new(Comment))
	if beego.AppConfig.String("runmode") == "dev" {
		orm.Debug = true
	}

	//新建数据库表
	orm.RunSyncdb("default", false, true)

	//附件上传文件夹处理
	os.Mkdir("attachment", os.ModePerm)
}
Exemple #20
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 #21
0
func init() {
	orm.RegisterDriver("mysql", orm.DR_MySQL)
	orm.RegisterDataBase("default", "mysql", "user:Passwd@/ayp?charset=utf8")
	orm.RegisterModel(new(models.Articulos), new(models.Categoria),
		new(models.Proveedor), new(models.Usuarios), new(models.Empresa))

}
Exemple #22
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 #23
0
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")
}
Exemple #24
0
func init() {
	orm.RegisterDriver("mysql", orm.DR_MySQL)
	orm.RegisterDataBase("default", "mysql", "root:1234@tcp(localhost:3306)/os?charset=utf8")
	orm.RegisterModel(new(Groups), new(User), new(Grel))
	ORM = orm.NewOrm()
	orm.Debug = true
}
Exemple #25
0
func Init() error {
	orm.RegisterDataBase("default", "postgres", os.Getenv("DB_URL"), 30)

	orm.RegisterModel(new(Owner))
	orm.RegisterModel(new(Site))
	orm.RegisterModel(new(User))
	orm.RegisterModel(new(Template))

	if os.Getenv("DB_AUTO") != "" {
		if err := orm.RunSyncdb("default", true, true); err != nil {
			return err
		}
	}

	return loadTemplates()
}
Exemple #26
0
func init() {
	fmt.Println("register PvInverterDayData table")
	orm.RegisterModel(new(PvInverterDayData))

	// fmt.Printf("current seconds is:%v\n", time.Now().Unix())
	// fmt.Printf("today seconds is:%v\n", GetCurrentDay())
}
Exemple #27
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()
}
Exemple #28
0
func init() {
	if prefix := beego.AppConfig.String("database::mysqlprefex"); prefix != "" {
		orm.RegisterModelWithPrefix(prefix, new(ClientJobs))
	} else {
		orm.RegisterModel(new(ClientJobs))
	}
}
Exemple #29
0
func RegistDB() {
	host := beego.AppConfig.String("DBhost")
	dataSource := "root:arvin@(" + host + ":3306)/test?charset=utf8"
	orm.RegisterModel(new(Category), new(Topic), new(Reply))
	orm.RegisterDriver("mysql", orm.DRMySQL)
	orm.RegisterDataBase("default", "mysql", dataSource)
}
Exemple #30
0
func init() {
	// orm.RegisterDataBase("default", "mysql", "root:1234@tcp(localhost:3306)/qq?charset=utf8")
	orm.RegisterDataBase("default", "mysql", "cdb_outerroot:root1234@tcp(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()
}