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


Golang xorm.NewEngine函数代码示例

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


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

示例1: SetEngine

func SetEngine() (err error) {
	switch DbCfg.Type {
	case "mysql":
		orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%[email protected](%s)/%s?charset=utf8",
			DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name))
	case "postgres":
		orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s",
			DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode))
	case "sqlite3":
		os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm)
		orm, err = xorm.NewEngine("sqlite3", DbCfg.Path)
	default:
		return fmt.Errorf("Unknown database type: %s", DbCfg.Type)
	}
	if err != nil {
		return fmt.Errorf("models.init(fail to conntect database): %v", err)
	}

	// WARNNING: for serv command, MUST remove the output to os.stdout,
	// so use log file to instead print to stdout.
	execDir, _ := base.ExecDir()
	logPath := execDir + "/log/xorm.log"
	os.MkdirAll(path.Dir(logPath), os.ModePerm)

	f, err := os.Create(logPath)
	if err != nil {
		return fmt.Errorf("models.init(fail to create xorm.log): %v", err)
	}
	orm.Logger = f

	orm.ShowSQL = true
	orm.ShowDebug = true
	orm.ShowErr = true
	return nil
}
开发者ID:popospectre,项目名称:gogs,代码行数:35,代码来源:models.go

示例2: setEngine

func setEngine() {
	var err error
	switch DbCfg.Type {
	case "mysql":
		orm, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%[email protected]%s/%s?charset=utf8",
			DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name))
	case "postgres":
		orm, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s",
			DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode))
	case "sqlite3":
		os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm)
		orm, err = xorm.NewEngine("sqlite3", DbCfg.Path)
	default:
		fmt.Printf("Unknown database type: %s\n", DbCfg.Type)
		os.Exit(2)
	}
	if err != nil {
		fmt.Printf("models.init(fail to conntect database): %v\n", err)
		os.Exit(2)
	}

	// WARNNING: for serv command, MUST remove the output to os.stdout,
	// so use log file to instead print to stdout.

	//x.ShowDebug = true
	//orm.ShowErr = true
	f, err := os.Create("xorm.log")
	if err != nil {
		fmt.Printf("models.init(fail to create xorm.log): %v\n", err)
		os.Exit(2)
	}
	orm.Logger = f
	orm.ShowSQL = true
}
开发者ID:josephyzhou,项目名称:gogs,代码行数:34,代码来源:models.go

示例3: XConDb

func XConDb() (*xorm.Engine, error) {
	switch {
	case dbtype == "sqlite":
		return xorm.NewEngine("sqlite3", DbName)

	case dbtype == "mysql":
		return xorm.NewEngine("mysql", "user=mysql [email protected]#9^&* dbname=mysql")

	case dbtype == "pgsql":
		return xorm.NewEngine("postgres", "user=postgres [email protected]#$%^&* dbname=pgsql sslmode=disable")
	}
	return nil, errors.New("尚未设定数据库连接")
}
开发者ID:JessonChan,项目名称:toropress,代码行数:13,代码来源:models.go

示例4: ConDb

func ConDb() (*xorm.Engine, error) {
	switch {
	case dbtype == "sqlite":
		return xorm.NewEngine("sqlite3", "./data/sqlite.db")

	case dbtype == "mysql":
		return xorm.NewEngine("mysql", "user=mysql [email protected]#9^&* dbname=mysql")

	case dbtype == "pgsql":
		// "user=postgres [email protected]#$%^&* dbname=pgsql sslmode=disable maxcons=10 persist=true"
		//return xorm.NewEngine("postgres", "host=110.76.39.205 user=postgres password=LhS88root dbname=pgsql sslmode=disable")
		return xorm.NewEngine("postgres", "user=postgres password=LhS88root dbname=mzr sslmode=disable")
	}
	return nil, errors.New("尚未设定数据库连接")
}
开发者ID:rose312,项目名称:mzr,代码行数:15,代码来源:mzs.go

示例5: SetDB

//设置数据库
func SetDB() {
	path, _ := filepath.Abs("")
	c, _ := config.ReadDefault(fmt.Sprintf("%s/admin/conf/databases.conf", path))

	driver, _ := c.String("database", "db.driver")
	dbname, _ := c.String("database", "db.dbname")
	user, _ := c.String("database", "db.user")
	password, _ := c.String("database", "db.password")
	host, _ := c.String("database", "db.host")
	//prefix, _ := c.String("database", "db.prefix")

	//数据库链接
	var err error
	Engine, err = xorm.NewEngine(driver, fmt.Sprintf("%s:%[email protected](%s)/%s?charset=utf8", user, password, host, dbname))
	if err != nil {
		revel.WARN.Printf("错误: %v", err)
	}

	//缓存方式是存放到内存中,缓存struct的记录数为1000条
	//cacher := xorm.NewLRUCacher(xorm.NewMemoryStore(), 1000)
	//Engine.SetDefaultCacher(cacher)

	//控制台打印SQL语句
	//Engine.ShowSQL = true

	//控制台打印调试信息
	//Engine.ShowDebug = true

	//控制台打印错误信息
	//Engine.ShowErr = true

	//控制台打印警告信息
	//Engine.ShowWarn = true
}
开发者ID:qmdx,项目名称:GoCMS,代码行数:35,代码来源:init.go

示例6: ConnectDb

func ConnectDb() (*xorm.Engine, error) {
	fmt.Println("database type: " + dbtype)
	switch {
	case dbtype == "sqlite":
		return xorm.NewEngine("sqlite3", dbname)

	case dbtype == "mysql":
		return xorm.NewEngine("mysql", fmt.Sprintf("%v:%[email protected](%v:%v)/%v?charset=%v",
			dbuser, dbpassword, dbhost, dbport, dbname, dbcharset))

	case dbtype == "pgsql":
		return xorm.NewEngine("postgres", fmt.Sprintf("%v:%[email protected](%v:%v)/%v?charset=%v",
			dbuser, dbpassword, dbhost, dbport, dbname, dbcharset))
	}
	return nil, errors.New("No database found!")
}
开发者ID:Raysmond,项目名称:RaysGo,代码行数:16,代码来源:models.go

示例7: setEngine

func setEngine() {
	dbName := utils.Cfg.MustValue("db", "name")
	dbPwd := utils.Cfg.MustValue("db", "pwd_"+runtime.GOOS)

	if runtime.GOOS == "darwin" {
		u, err := user.Current()
		if err != nil {
			beego.Critical("models.init -> fail to get user:", err.Error())
			os.Exit(2)
		}
		dbPwd = utils.Cfg.MustValue("db", "pwd_"+runtime.GOOS+"_"+u.Username)
	}

	var err error
	x, err = xorm.NewEngine("mysql", fmt.Sprintf("%v:%[email protected]%v/%v?charset=utf8",
		utils.Cfg.MustValue("db", "user"), dbPwd,
		utils.Cfg.MustValue("db", "host"), dbName))
	if err != nil {
		beego.Critical("models.init -> fail to conntect database:", err.Error())
		os.Exit(2)
	}

	if beego.RunMode != "pro" {
		x.ShowDebug = true
		x.ShowErr = true
		//x.ShowSQL = true
	}

	beego.Trace("Initialized database ->", dbName)
}
开发者ID:juju2013,项目名称:gowalker,代码行数:30,代码来源:models.go

示例8: ConDb

func ConDb() *xorm.Engine {

	/*
		engine, _ = xorm.NewEngine("sqlite3", "./test.db")
	*/
	engine, _ = xorm.NewEngine("postgres", "user=postgres [email protected]#$%^&* dbname=pgsql sslmode=disable")
	return engine
}
开发者ID:rose312,项目名称:mzr,代码行数:8,代码来源:xo.go

示例9: InitDB

// should be call before pacakge called
func InitDB(driver, dataSource string) (err error) {
	x, err = xorm.NewEngine(driver, dataSource)
	if err != nil {
		return
	}
	// create tables
	return x.Sync(new(Project), new(File))
}
开发者ID:kaisne,项目名称:gobuild,代码行数:9,代码来源:database.go

示例10: InitOrm

func InitOrm() *xorm.Engine {
	LoadDBConfig()
	orm, err := xorm.NewEngine("postgres", fmt.Sprintf("user=%s dbname=%s sslmode=%s",
		DBConfig.User, DBConfig.Name, DBConfig.SslMode))
	if err != nil {
		panic(err)
	}
	return orm
}
开发者ID:jartek,项目名称:goapi,代码行数:9,代码来源:models.go

示例11: NewTestEngine

func NewTestEngine(x *xorm.Engine) (err error) {
	switch DbCfg.Type {
	case "mysql":
		x, err = xorm.NewEngine("mysql", fmt.Sprintf("%s:%[email protected](%s)/%s?charset=utf8",
			DbCfg.User, DbCfg.Pwd, DbCfg.Host, DbCfg.Name))
	case "postgres":
		x, err = xorm.NewEngine("postgres", fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s",
			DbCfg.User, DbCfg.Pwd, DbCfg.Name, DbCfg.SslMode))
	// case "sqlite3":
	// 	os.MkdirAll(path.Dir(DbCfg.Path), os.ModePerm)
	// 	x, err = xorm.NewEngine("sqlite3", DbCfg.Path)
	default:
		return fmt.Errorf("Unknown database type: %s", DbCfg.Type)
	}
	if err != nil {
		return fmt.Errorf("models.init(fail to conntect database): %v", err)
	}

	return x.Sync(new(User), new(PublicKey), new(Repository), new(Watch),
		new(Action), new(Access), new(Issue), new(Comment))
}
开发者ID:popospectre,项目名称:gogs,代码行数:21,代码来源:models.go

示例12: SetupDb

func SetupDb() (engine *xorm.Engine) {
	var (
		err error
	)

	if engine, err = xorm.NewEngine("sqlite3", "/tmp/tmp.db"); err != nil {
		panic(err)
	}

	if err = engine.Sync(new(User)); err != nil {
		panic(err)
	}

	return engine
}
开发者ID:GoSteelProgrammers,项目名称:talk-review-orms,代码行数:15,代码来源:query.go

示例13: init

func (s *ServerType) init() {

	s.DB, err = xorm.NewEngine("mysql", s.MYSQL_DSN)
	if err != nil {
		panic(err)
	}
	s.DB.ShowSQL = s.MYSQL_DEBUG

	if s.PHP_CLI == "" {
		s.PHP_CLI = DEFAULT_PHP_CLI
	}

	if s.LogFile != "" {
		logFile, err := os.OpenFile(s.LogFile, os.O_RDWR|os.O_CREATE, 0666)
		if err != nil {
			panic(err)
		}
		log.SetOutput(logFile)
	}

	//worker_num为0表示不启用PHP引擎
	if s.PHP_WORKER_NUM != 0 {

		if s.PHP_TPL_DIR == "" {
			s.PHP_TPL_DIR = s.Root + "/static/template/"
		}

		//php模板引擎
		s.PHP = php.NewEngine(s.PHP_WORKER_NUM, s.PHP_CLI, s.PHP_TPL_DIR)
		//设置PHP的运行路径
		s.PHP.RunDir = s.Root
		//初始化
		s.PHP.Init()

		go s.PHP.EngineLoop()
	}

	go Session_CheckExpire()

	//默认
	if s.DefaultAction == "" {
		s.DefaultAction = "index"
	}
	if s.DefaultController == "" {
		s.DefaultController = "Base"
	}
	s.Charset = "utf-8"
}
开发者ID:WaylandGod,项目名称:easygo,代码行数:48,代码来源:server.go

示例14: init

func init() {
	st := NewSuite("xorm")
	st.InitF = func() {
		st.AddBenchmark("Insert", 2000*ORM_MULTI, XormInsert)
		st.AddBenchmark("MultiInsert 100 row", 500*ORM_MULTI, XormInsertMulti)
		st.AddBenchmark("Update", 2000*ORM_MULTI, XormUpdate)
		st.AddBenchmark("Read", 4000*ORM_MULTI, XormRead)
		st.AddBenchmark("MultiRead limit 100", 2000*ORM_MULTI, XormReadSlice)

		engine, _ := xorm.NewEngine("mysql", ORM_SOURCE)

		engine.SetMaxIdleConns(ORM_MAX_IDLE)
		engine.SetMaxConns(ORM_MAX_CONN)

		xo = engine.NewSession()
	}
}
开发者ID:KiraPro,项目名称:orm-benchmark,代码行数:17,代码来源:xorm.go

示例15: init

func init() {
	var err error
	orm, err = xorm.NewEngine("sqlite3", "./test.db")
	if err != nil {
		fmt.Println(err)
	}

	orm.ShowSQL = true
	orm.ShowDebug = true

	err = orm.Sync(&User{}, &Repository{})
	if err != nil {
		fmt.Println(err)
	}

	base.RepoRootPath = "test"
}
开发者ID:Julianzz,项目名称:gogs,代码行数:17,代码来源:models_test.go


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