-
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.
support generate code from yesql.yaml configure
- Loading branch information
Showing
14 changed files
with
143 additions
and
26 deletions.
There are no files selected for viewing
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,58 @@ | ||
package yesql | ||
|
||
import ( | ||
"os" | ||
|
||
"gopkg.in/yaml.v3" | ||
) | ||
|
||
type yesqlConf struct { | ||
Version string `yaml:"version"` | ||
Generator struct { | ||
Engine string `yaml:"engine"` | ||
SqlxPkgName string `yaml:"sqlx_package"` | ||
DefaultStructName string `yaml:"default_struct_name"` | ||
GoFileName string `yaml:"go_file_name"` | ||
} | ||
Sql []struct { | ||
Queries string `yaml:"queries"` | ||
Gen struct { | ||
Package string `yaml:"package"` | ||
Out string `yaml:"out"` | ||
Engine string `yaml:"engine"` | ||
SqlxPkgName string `yaml:"sqlx_package"` | ||
DefaultStructName string `yaml:"default_struct_name"` | ||
GoFileName string `yaml:"go_file_name"` | ||
} | ||
} | ||
} | ||
|
||
func (s *yesqlConf) prepare() { | ||
for i := range s.Sql { | ||
if s.Sql[i].Gen.Engine == "" { | ||
s.Sql[i].Gen.Engine = s.Generator.Engine | ||
} | ||
if s.Sql[i].Gen.SqlxPkgName == "" { | ||
s.Sql[i].Gen.SqlxPkgName = s.Generator.SqlxPkgName | ||
} | ||
if s.Sql[i].Gen.DefaultStructName == "" { | ||
s.Sql[i].Gen.DefaultStructName = s.Generator.DefaultStructName | ||
} | ||
if s.Sql[i].Gen.GoFileName == "" { | ||
s.Sql[i].Gen.GoFileName = s.Generator.GoFileName | ||
} | ||
} | ||
} | ||
|
||
func yesqlConfFrom(path string) (*yesqlConf, error) { | ||
file, err := os.Open(path) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer file.Close() | ||
res := &yesqlConf{} | ||
decoder := yaml.NewDecoder(file) | ||
err = decoder.Decode(res) | ||
res.prepare() | ||
return res, err | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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,28 @@ | ||
version: '1' | ||
|
||
generator: | ||
engine: sqlx | ||
sqlx_package: 'github.com/bitbus/sqlx' | ||
default_struct_name: yesql | ||
go_file_name: yesql | ||
|
||
sql: | ||
- queries: yesql.sql | ||
gen: | ||
package: yesql | ||
out: auto | ||
- queries: yesql_ac.sql | ||
gen: | ||
package: ac | ||
out: auto/ac | ||
go_file_name: ac | ||
- queries: yesql_bc.sql | ||
gen: | ||
package: bc | ||
out: auto/bc | ||
go_file_name: bc | ||
- queries: yesql_cc.sql | ||
gen: | ||
package: cc | ||
out: auto/cc | ||
go_file_name: cc |
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ go 1.18 | |
|
||
require ( | ||
github.com/bitbus/sqlx v1.6.0 | ||
gopkg.in/yaml.v3 v3.0.1 | ||
) |
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,10 +1,9 @@ | ||
github.com/bitbus/sqlx v1.6.0 h1:ewrBydRkyHZqfOqvHVYpiBlqQtLn93B/loa2EwjpZ74= | ||
github.com/bitbus/sqlx v1.6.0/go.mod h1:MemKLfQ600g6PxUVsIDe48PlY3wOquyW2ApeiXoynFo= | ||
github.com/go-sql-driver/mysql v1.6.0 h1:BCTh4TKNUYmOmMUcQ3IipzF5prigylS7XXjEkfCHuOE= | ||
github.com/go-sql-driver/mysql v1.6.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= | ||
github.com/jmoiron/sqlx v1.3.5 h1:vFFPA71p1o5gAeqtEAwLU4dnX2napprKtHr7PYIcN3g= | ||
github.com/jmoiron/sqlx v1.3.5/go.mod h1:nRVWtLre0KfCLJvgxzCsLVMogSvQ1zNJtpYr2Ccp0mQ= | ||
github.com/lib/pq v1.2.0 h1:LXpIM/LZ5xGFhOpXAQUIMM1HdyqzVYM13zNdjCEEcA0= | ||
github.com/lib/pq v1.2.0/go.mod h1:5WUZQaWbwv1U+lTReE5YruASi9Al49XbQIvNi/34Woo= | ||
github.com/mattn/go-sqlite3 v1.14.6 h1:dNPt6NO46WmLVt2DLNpwczCmdV5boIZ6g/tlDrlRUbg= | ||
github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= | ||
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= | ||
github.com/lib/pq v1.10.9 h1:YXG7RB+JIjhP29X+OtkiDnYaXQwpS4JEWq7dtCCRUEw= | ||
github.com/mattn/go-sqlite3 v1.14.17 h1:mCRHCLDUBXgpKAqIKsaAaAsrAlbkeomtRFKXh2L6YIM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= | ||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= | ||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= | ||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= |
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,3 +1,3 @@ | ||
package yesql | ||
|
||
var Version = "v1.8.5" | ||
var Version = "v1.9.0" |
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