gosql.go 780 B

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