gosql.go 667 B

12345678910111213141516171819202122232425262728
  1. package gosql
  2. import (
  3. "fmt"
  4. "github.com/vladimirok5959/golang-sql/gosql/common"
  5. "github.com/vladimirok5959/golang-sql/gosql/engine"
  6. )
  7. type Tx = common.Tx
  8. func Open(dbURL, migrationsDir string, debug bool) (common.Engine, error) {
  9. databaseURL, err := common.ParseUrl(dbURL)
  10. if err != nil {
  11. return nil, err
  12. }
  13. switch databaseURL.Scheme {
  14. case "mysql":
  15. return engine.NewMySQL(databaseURL, migrationsDir, debug)
  16. case "postgres", "postgresql":
  17. return engine.NewPostgreSQL(databaseURL, migrationsDir, debug)
  18. case "sqlite", "sqlite3":
  19. return engine.NewSQLite(databaseURL, migrationsDir, debug)
  20. default:
  21. return nil, fmt.Errorf("DB open error")
  22. }
  23. }