Beispiel #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
}
Beispiel #2
0
//Sync Database
func Sync(force, verbose bool) error {
	log.Info("Sync database struct")

	if err := orm.RunSyncdb("default", force, verbose); err != nil {
		return fmt.Errorf("Sync Database Error, ", err.Error())
	}

	return nil
}
Beispiel #3
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
}