engine.go 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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, skipMigration bool, debug bool) (common.Engine, error) {
  11. db, err := common.OpenDB(dbURL, migrationsDir, skipMigration, debug)
  12. if err != nil {
  13. return nil, err
  14. }
  15. return &mysql{
  16. DBMethods: &common.DBMethods{
  17. DB: db,
  18. Debug: debug,
  19. Driver: dbURL.Scheme,
  20. },
  21. }, nil
  22. }
  23. // ----------------------------------------------------------------------------
  24. type postgresql struct {
  25. *common.DBMethods
  26. }
  27. func NewPostgreSQL(dbURL *url.URL, migrationsDir string, skipMigration bool, debug bool) (common.Engine, error) {
  28. db, err := common.OpenDB(dbURL, migrationsDir, skipMigration, debug)
  29. if err != nil {
  30. return nil, err
  31. }
  32. return &postgresql{
  33. DBMethods: &common.DBMethods{
  34. DB: db,
  35. Debug: debug,
  36. Driver: dbURL.Scheme,
  37. },
  38. }, nil
  39. }
  40. // ----------------------------------------------------------------------------
  41. type sqlite struct {
  42. *common.DBMethods
  43. }
  44. func NewSQLite(dbURL *url.URL, migrationsDir string, skipMigration bool, debug bool) (common.Engine, error) {
  45. db, err := common.OpenDB(dbURL, migrationsDir, skipMigration, debug)
  46. if err != nil {
  47. return nil, err
  48. }
  49. return &sqlite{
  50. DBMethods: &common.DBMethods{
  51. DB: db,
  52. Debug: debug,
  53. Driver: dbURL.Scheme,
  54. },
  55. }, nil
  56. }