Exemplo n.º 1
0
func (s *sphinxPools) newConn() (*SphinxDB, error) {
	var (
		err error
		db  *sql.DB
		o   orm.Ormer
	)

	if db, err = sql.Open("sphinx", "root:root@tcp("+setting.SphinxHost+")/?loc=UTC"); err != nil {
		return nil, err
	}

	if err = db.Ping(); err != nil {
		db.Close()
		return nil, err
	}

	db.SetMaxIdleConns(1)
	db.SetMaxOpenConns(2)

	o, err = orm.NewOrmWithDB("sphinx", "sphinx", db)
	if err != nil {
		return nil, err
	}

	sdb := &SphinxDB{
		alive: true,
		pools: s,
		db:    db,
		orm:   o,
	}
	return sdb, nil
}
Exemplo n.º 2
0
func init() {
	runtime.GOMAXPROCS(Workers)
	beego.AppConfigPath = "../conf/app.conf"
	beego.ParseConfig()
	setting.ReadConfig()
	DiscuzDb = beego.AppConfig.String("importer::discuzdb")
	AvatarPath = beego.AppConfig.String("importer::avatarpath")
	if err := orm.RegisterDataBase("discuz", "mysql", fmt.Sprintf("%s:%s@tcp(%s:3306)/%s?charset=utf8", setting.MySQLUser, setting.MySQLPassword, setting.MySQLHost, DiscuzDb)+"&loc=Asia%2FShanghai", 30); err != nil {
		fmt.Println("MySQL error:", err.Error())
		return
	}
	OrmGotalk = orm.NewOrm()
	if db, err := orm.GetDB("discuz"); err == nil {
		Orm, err = orm.NewOrmWithDB("mysql", "discuz", db)
		if err != nil {
			fmt.Println("MySQL error:", err.Error())
			return
		}
	} else {
		fmt.Println("MySQL error:", err.Error())
		return
	}
	orm.RunSyncdb("default", true, false)
}