Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions generators/base/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"path"
"strings"

"github.com/dizzyfool/genna/lib"
genna "github.com/dizzyfool/genna/lib"
"github.com/dizzyfool/genna/model"
"github.com/dizzyfool/genna/util"

Expand Down Expand Up @@ -128,8 +128,6 @@ func AddFlags(command *cobra.Command) {
flags.StringSlice(customTypesFlag, []string{}, "set custom types separated by comma\nformat: <postgresql_type>:<go_import>.<go_type>\nexamples: uuid:github.com/google/uuid.UUID,point:src/model.Point,bytea:string\n")

flags.IntP(GoPgVer, "g", 10, "specify go-pg version (8, 9 and 10 are supported)")

return
}

// ReadFlags reads basic flags from command
Expand Down Expand Up @@ -183,7 +181,7 @@ func ReadFlags(command *cobra.Command) (conn, output, pkg string, tables []strin
customTypes.Add(model.TypePGUuid, "uuid.UUID", "github.com/google/uuid")
}

if gopgVer < 8 && gopgVer > 10 {
if gopgVer < 8 || gopgVer > 10 {
err = fmt.Errorf("go-pg version %d not supported", gopgVer)
return
}
Expand Down
2 changes: 1 addition & 1 deletion generators/model/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func TestGenerator_Generate(t *testing.T) {
generator.options.FollowFKs = true
generator.options.CustomTypes.Add(model.TypePGUuid, "uuid.UUID", "github.com/google/uuid")
generator.options.GoPgVer = 10
//generator.options.AddJSONTag = true
// generator.options.AddJSONTag = true

if err := generator.Generate(); err != nil {
t.Errorf("generate error = %v", err)
Expand Down
2 changes: 1 addition & 1 deletion generators/search/generator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func TestGenerator_Generate(t *testing.T) {
generator.options.Output = path.Join(os.TempDir(), "search_test.go")
generator.options.FollowFKs = true
generator.options.CustomTypes.Add(model.TypePGUuid, "uuid.UUID", "github.com/google/uuid")
//generator.options.AddJSONTag = true
// generator.options.AddJSONTag = true

if err := generator.Generate(); err != nil {
t.Errorf("generate error = %v", err)
Expand Down
6 changes: 3 additions & 3 deletions lib/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ import (

// queryLogger helper struct for query logging
type queryLogger struct {
logger log.Logger
logger *log.Logger
}

// newQueryLogger creates new helper struct for query logging
func newQueryLogger(logger log.Logger) queryLogger {
func newQueryLogger(logger *log.Logger) queryLogger {
return queryLogger{logger: logger}
}

Expand Down Expand Up @@ -58,7 +58,7 @@ func newDatabase(url string, logger *log.Logger) (orm.DB, error) {
client := pg.Connect(options)

if logger != nil {
client.AddQueryHook(newQueryLogger(*logger))
client.AddQueryHook(newQueryLogger(logger))
}

return client, nil
Expand Down
1 change: 1 addition & 0 deletions lib/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func (r relation) Target() table {
}

type column struct {
// nolint this field is required by go-pg
tableName struct{} `pg:",discard_unknown_columns"`

Schema string `pg:"schema_name"`
Expand Down
12 changes: 4 additions & 8 deletions model/entity.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,12 @@ func NewEntity(schema, pgName string, columns []Column, relations []Relation) En
impIndex: map[string]struct{}{},
}

if columns != nil {
for _, col := range columns {
entity.AddColumn(col)
}
for _, col := range columns {
entity.AddColumn(col)
}

if relations != nil {
for _, rel := range relations {
entity.AddRelation(rel)
}
for _, rel := range relations {
entity.AddRelation(rel)
}

return entity
Expand Down
4 changes: 2 additions & 2 deletions util/texts.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func Underscore(s string) string {
// Sanitize makes string suitable for golang var, const, field, type name
func Sanitize(s string) string {
rgxp := regexp.MustCompile(`[^a-zA-Z\d\-_]`)
sanitized := strings.Replace(rgxp.ReplaceAllString(s, ""), "-", "_", -1)
sanitized := strings.ReplaceAll(rgxp.ReplaceAllString(s, ""), "-", "_")

if len(sanitized) != 0 && ((sanitized[0] >= '0' && sanitized[0] <= '9') || sanitized[0] == '_') {
sanitized = "T" + sanitized
Expand All @@ -118,7 +118,7 @@ func EntityName(s string) string {
for i := ln; i >= 0; i-- {
split := splitted[i]
singular := Singular(split)
if strings.ToLower(singular) != strings.ToLower(split) {
if !strings.EqualFold(singular, split) {
splitted[i] = strings.Title(singular)
break
}
Expand Down