gosql.go 646 B

1234567891011121314151617181920212223242526
  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. func Open(dbURL, migrationsDir string, debug bool) (common.Engine, error) {
  8. databaseURL, err := common.ParseUrl(dbURL)
  9. if err != nil {
  10. return nil, err
  11. }
  12. switch databaseURL.Scheme {
  13. case "mysql":
  14. return engine.NewMySQL(databaseURL, migrationsDir, debug)
  15. case "postgres", "postgresql":
  16. return engine.NewPostgreSQL(databaseURL, migrationsDir, debug)
  17. case "sqlite", "sqlite3":
  18. return engine.NewSQLite(databaseURL, migrationsDir, debug)
  19. default:
  20. return nil, fmt.Errorf("DB open error")
  21. }
  22. }