Golang Gorm lib执行sql文件的最佳解决方案

Mabye someone have more simple code for execution sql file by gorm lib?

// CARRIERS IMPORT
err := DB.Session.Model(model.Carriers{}).Count(&carriers).Error
if err != nil {
    panic(err)
} else if carriers == 0 {
    path, err := filepath.Abs("./dumps/carriers.sql")
    if err != nil {
        panic(err)
    }
    file, err := ioutil.ReadFile(path)
    if err != nil {
        panic(err)
    }
    DB.Session.Model(model.Carriers{}).Exec(string(file))
}

When executing a SQL file full of statements, the existing sql command-line clients do not just send the file contents over to the server. Instead, they parse the file and issue individual statements.

If you want to replicate this functionality, you will need to parse the file yourself into individual statements and execute them.

The easiest way is to invoke an external command-line client. For example for postgresql you should exec something like psql [connection args] -f <sql file>.