Skip to content

初始化方法Oracle

Tuuz edited this page Oct 27, 2023 · 4 revisions

同时你可以参考TuuzGoWeb中database的方法,编写自己的初始化方式

import (
	_ "github.com/sijms/go-ora/v2"
	"github.com/tobycroft/gorose-pro"
)

var Database *gorose.Engin


func DbConfig() *gorose.Config {
	var conf gorose.Config
	conf.Driver = "oracle"
	conf.SetMaxIdleConns = 20
	conf.SetMaxOpenConns = 300
	conf.Prefix = ""
	conf.Dsn = go_ora.BuildUrl("10.0.0.172", 1572, "XE", "ADMIN", "123456", map[string]string{})
	return &conf
}

func init() {
    var err error
    Database, err = gorose.Open(DbConfig())
    if err != nil {
        log.Panic(err)
    }
}

//注意这个db就是后续文档中调用的初始化db方法
func DB() gorose.IOrm {
    return database.Database.NewOrm()
}