-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
3,436 additions
and
1 deletion.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
* @goravel/core-developers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
blank_issues_enabled: false | ||
contact_links: | ||
- name: Please submit to goravel/goravel (请提交至 goravel/goravel) | ||
url: https://github.com/goravel/goravel/issues/new/choose | ||
about: Thanks in advance for your feedback (提前感谢您的反馈) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name: Codecov | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
jobs: | ||
codecov: | ||
uses: goravel/.github/.github/workflows/codecov.yml@master | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Lint | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
permissions: | ||
contents: read | ||
jobs: | ||
lint: | ||
uses: goravel/.github/.github/workflows/lint.yml@master | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
name: PR Check Title | ||
on: | ||
pull_request: | ||
jobs: | ||
check: | ||
uses: goravel/.github/.github/workflows/check_pr_title.yml@master | ||
secrets: inherit |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
name: Test | ||
on: | ||
push: | ||
branches: | ||
- master | ||
pull_request: | ||
jobs: | ||
test: | ||
uses: goravel/.github/.github/workflows/test_linux.yml@master | ||
secrets: inherit | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
with-expecter: True | ||
disable-version-string: True | ||
all: True | ||
recursive: true | ||
packages: | ||
github.com/goravel/sqlserver/contracts: | ||
config: | ||
dir: mocks/{{replaceAll .InterfaceDirRelative "contracts" ""}} | ||
filename: "{{.InterfaceName}}.go" | ||
mockname: "{{.InterfaceName}}" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,65 @@ | ||
# sqlserver | ||
# Sqlserver | ||
|
||
The Sqlserver driver for facades.Orm() of Goravel. | ||
|
||
## Version | ||
|
||
| goravel/sqlserver | goravel/framework | | ||
|------------------|-------------------| | ||
| v1.0.* | v1.16.* | | ||
|
||
## Install | ||
|
||
1. Add package | ||
|
||
``` | ||
go get -u github.com/goravel/sqlserver | ||
``` | ||
|
||
2. Register service provider | ||
|
||
``` | ||
// config/app.go | ||
import "github.com/goravel/sqlserver" | ||
"providers": []foundation.ServiceProvider{ | ||
... | ||
&sqlserver.ServiceProvider{}, | ||
} | ||
``` | ||
|
||
3. Add Sqlserver driver to `config/database.go` file | ||
|
||
``` | ||
// config/database.go | ||
import ( | ||
"github.com/goravel/framework/contracts/database" | ||
"github.com/goravel/framework/contracts/database/orm" | ||
sqlserverfacades "github.com/goravel/sqlserver/facades" | ||
) | ||
"connections": map[string]any{ | ||
... | ||
"sqlserver": map[string]any{ | ||
"host": config.Env("DB_HOST", "127.0.0.1"), | ||
"port": config.Env("DB_PORT", 3306), | ||
"database": config.Env("DB_DATABASE", "forge"), | ||
"username": config.Env("DB_USERNAME", ""), | ||
"password": config.Env("DB_PASSWORD", ""), | ||
"charset": "utf8mb4", | ||
"prefix": "", | ||
"singular": false, | ||
"via": func() (orm.Driver, error) { | ||
return sqlserverfacades.Sqlserver("sqlserver"), nil | ||
}, | ||
// Optional | ||
"read": []database.Config{ | ||
{Host: "192.168.1.1", Port: 3306, Database: "forge", Username: "root", Password: "123123"}, | ||
}, | ||
// Optional | ||
"write": []database.Config{ | ||
{Host: "192.168.1.2", Port: 3306, Database: "forge", Username: "root", Password: "123123"}, | ||
}, | ||
}, | ||
} | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package sqlserver | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/goravel/framework/contracts/config" | ||
|
||
"github.com/goravel/sqlserver/contracts" | ||
) | ||
|
||
type Config struct { | ||
config config.Config | ||
connection string | ||
} | ||
|
||
func NewConfig(config config.Config, connection string) *Config { | ||
return &Config{ | ||
config: config, | ||
connection: connection, | ||
} | ||
} | ||
|
||
func (r *Config) Config() config.Config { | ||
return r.config | ||
} | ||
|
||
func (r *Config) Connection() string { | ||
return r.connection | ||
} | ||
|
||
func (r *Config) Reads() []contracts.FullConfig { | ||
configs := r.config.Get(fmt.Sprintf("database.connections.%s.read", r.connection)) | ||
if readConfigs, ok := configs.([]contracts.Config); ok { | ||
return r.fillDefault(readConfigs) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (r *Config) Writes() []contracts.FullConfig { | ||
configs := r.config.Get(fmt.Sprintf("database.connections.%s.write", r.connection)) | ||
if writeConfigs, ok := configs.([]contracts.Config); ok { | ||
return r.fillDefault(writeConfigs) | ||
} | ||
|
||
// Use default db configuration when write is empty | ||
return r.fillDefault([]contracts.Config{{}}) | ||
} | ||
|
||
func (r *Config) fillDefault(configs []contracts.Config) []contracts.FullConfig { | ||
if len(configs) == 0 { | ||
return nil | ||
} | ||
|
||
var fullConfigs []contracts.FullConfig | ||
for _, config := range configs { | ||
fullConfig := contracts.FullConfig{ | ||
Config: config, | ||
Connection: r.connection, | ||
Driver: Name, | ||
NoLowerCase: r.config.GetBool(fmt.Sprintf("database.connections.%s.no_lower_case", r.connection)), | ||
Prefix: r.config.GetString(fmt.Sprintf("database.connections.%s.prefix", r.connection)), | ||
Singular: r.config.GetBool(fmt.Sprintf("database.connections.%s.singular", r.connection)), | ||
} | ||
if nameReplacer := r.config.Get(fmt.Sprintf("database.connections.%s.name_replacer", r.connection)); nameReplacer != nil { | ||
if replacer, ok := nameReplacer.(contracts.Replacer); ok { | ||
fullConfig.NameReplacer = replacer | ||
} | ||
} | ||
|
||
// If read or write is empty, use the default config | ||
if fullConfig.Dsn == "" { | ||
fullConfig.Dsn = r.config.GetString(fmt.Sprintf("database.connections.%s.dsn", r.connection)) | ||
} | ||
if fullConfig.Host == "" { | ||
fullConfig.Host = r.config.GetString(fmt.Sprintf("database.connections.%s.host", r.connection)) | ||
} | ||
if fullConfig.Port == 0 { | ||
fullConfig.Port = r.config.GetInt(fmt.Sprintf("database.connections.%s.port", r.connection)) | ||
} | ||
if fullConfig.Username == "" { | ||
fullConfig.Username = r.config.GetString(fmt.Sprintf("database.connections.%s.username", r.connection)) | ||
} | ||
if fullConfig.Password == "" { | ||
fullConfig.Password = r.config.GetString(fmt.Sprintf("database.connections.%s.password", r.connection)) | ||
} | ||
if fullConfig.Database == "" { | ||
fullConfig.Database = r.config.GetString(fmt.Sprintf("database.connections.%s.database", r.connection)) | ||
} | ||
if fullConfig.Charset == "" { | ||
fullConfig.Charset = r.config.GetString(fmt.Sprintf("database.connections.%s.charset", r.connection)) | ||
} | ||
fullConfigs = append(fullConfigs, fullConfig) | ||
} | ||
|
||
return fullConfigs | ||
} |
Oops, something went wrong.