Skip to content

Commit

Permalink
chore: [#585] change driver Name and handle MariaDB versioning (#4)
Browse files Browse the repository at this point in the history
  • Loading branch information
almas1992 authored Feb 7, 2025
1 parent 2ac5aa9 commit df4e513
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
6 changes: 3 additions & 3 deletions config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ func (s *ConfigTestSuite) TestWrites() {
s.Equal([]contracts.FullConfig{
{
Connection: s.connection,
Driver: "mysql",
Driver: Name,
Prefix: "goravel_",
Singular: false,
Charset: "utf8mb4",
Expand Down Expand Up @@ -196,7 +196,7 @@ func (s *ConfigTestSuite) TestFillDefault() {
expectConfigs: []contracts.FullConfig{
{
Connection: s.connection,
Driver: "mysql",
Driver: Name,
Prefix: prefix,
Singular: singular,
Charset: charset,
Expand Down Expand Up @@ -237,7 +237,7 @@ func (s *ConfigTestSuite) TestFillDefault() {
expectConfigs: []contracts.FullConfig{
{
Connection: s.connection,
Driver: "mysql",
Driver: Name,
Prefix: prefix,
Singular: singular,
Charset: charset,
Expand Down
15 changes: 13 additions & 2 deletions mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/goravel/framework/contracts/log"
"github.com/goravel/framework/contracts/testing"
"github.com/goravel/framework/errors"
"github.com/goravel/framework/support/str"
"gorm.io/gorm"

"github.com/goravel/mysql/contracts"
Expand All @@ -36,16 +37,18 @@ func (r *Mysql) Config() database.Config {
return database.Config{}
}

version, name := r.versionAndName()

return database.Config{
Connection: writers[0].Connection,
Database: writers[0].Database,
Driver: Name,
Driver: name,
Host: writers[0].Host,
Password: writers[0].Password,
Port: writers[0].Port,
Prefix: writers[0].Prefix,
Username: writers[0].Username,
Version: r.version(),
Version: version,
}
}

Expand Down Expand Up @@ -81,6 +84,14 @@ func (r *Mysql) Processor() contractsschema.Processor {
return NewProcessor()
}

func (r *Mysql) versionAndName() (string, string) {
version := str.Of(r.version())
if version.Contains("MariaDB") {
return version.Between("5.5.5-", "-MariaDB").String(), "MariaDB"
}
return version.String(), Name
}

func (r *Mysql) version() string {
instance, _, err := r.Gorm()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

const (
Binding = "goravel.mysql"
Name = "mysql"
Name = "MySQL"
)

var App foundation.Application
Expand Down

0 comments on commit df4e513

Please sign in to comment.