engine.go 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. package engine
  2. import (
  3. "net/url"
  4. "github.com/vladimirok5959/golang-sql/gosql/common"
  5. )
  6. // ----------------------------------------------------------------------------
  7. type mysql struct {
  8. *common.DBMethods
  9. }
  10. func NewMySQL(dbURL *url.URL, migrationsDir string) (common.Engine, error) {
  11. db, err := common.OpenDB(dbURL, migrationsDir)
  12. if err != nil {
  13. return nil, err
  14. }
  15. return &mysql{
  16. DBMethods: &common.DBMethods{
  17. DB: db, Driver: dbURL.Scheme,
  18. },
  19. }, nil
  20. }
  21. // ----------------------------------------------------------------------------
  22. type postgresql struct {
  23. *common.DBMethods
  24. }
  25. func NewPostgreSQL(dbURL *url.URL, migrationsDir string) (common.Engine, error) {
  26. db, err := common.OpenDB(dbURL, migrationsDir)
  27. if err != nil {
  28. return nil, err
  29. }
  30. return &postgresql{
  31. DBMethods: &common.DBMethods{
  32. DB: db, Driver: dbURL.Scheme,
  33. },
  34. }, nil
  35. }
  36. // ----------------------------------------------------------------------------
  37. type sqlite struct {
  38. *common.DBMethods
  39. }
  40. func NewSQLite(dbURL *url.URL, migrationsDir string) (common.Engine, error) {
  41. db, err := common.OpenDB(dbURL, migrationsDir)
  42. if err != nil {
  43. return nil, err
  44. }
  45. return &sqlite{
  46. DBMethods: &common.DBMethods{
  47. DB: db, Driver: dbURL.Scheme,
  48. },
  49. }, nil
  50. }