🔥A cross-language distributed transaction manager. Support xa, tcc, saga, transactional messages. 跨语言分布式事务管理器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

38 lines
842 B

package examples
import (
"io/ioutil"
"strings"
"github.com/sirupsen/logrus"
"github.com/yedf/dtm/common"
)
// RunSQLScript 1
func RunSQLScript(mysql map[string]string, script string) {
conf := map[string]string{}
common.MustRemarshal(mysql, &conf)
conf["database"] = ""
db, con := common.DbAlone(conf)
defer func() { con.Close() }()
content, err := ioutil.ReadFile(script)
if err != nil {
e2p(err)
}
sqls := strings.Split(string(content), ";")
for _, sql := range sqls {
s := strings.TrimSpace(sql)
if s == "" {
continue
}
logrus.Printf("executing: '%s'", s)
db.Must().Exec(s)
}
}
// PopulateMysql populate example mysql data
func PopulateMysql() {
common.InitApp(common.GetProjectDir(), &config)
config.Mysql["database"] = dbName
RunSQLScript(config.Mysql, common.GetCurrentCodeDir()+"/examples.sql")
}