Esempio n. 1
0
func (od *ormdrv) InitDB(driver, user, passwd, uri, name string, partition int64) error {
	switch driver {
	case "mysql":
		dsm := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", user, passwd, uri, "mysql")
		db, err := sql.Open("mysql", dsm)
		if err != nil {
			return err
		}

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

		cmd := "CREATE DATABASE IF NOT EXISTS " + name
		if _, err := db.Exec(cmd); err != nil {
			return err
		}
	default:
		//
	}

	ds := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", user, passwd, uri, name)
	if err := orm.RegisterDataBase("default", driver, ds, 0, 0); err != nil {
		return err
	}

	if err := orm.RunSyncdb("default", false, false); err != nil {
		return err
	}

	return nil
}
Esempio n. 2
0
func (od *ormdrv) InitDB(driver, user, passwd, uri, name string, partition int64) error {
	ds := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8", user, passwd, uri, name)
	if err := orm.RegisterDataBase("default", driver, ds, 0, 0); err != nil {
		return err
	}

	if err := orm.RunSyncdb("default", false, false); err != nil {
		return err
	}

	return nil
}
Esempio n. 3
0
//Init Database
func init() {
	orm.RegisterModel(new(Workspace), new(Project), new(Pipeline), new(Status), new(Param), new(Point), new(Stage))
	orm.RegisterDataBase("default", "tidb", "goleveldb:///tmp/tidb/vessel", 0, 0)
}