Skip to content

Commit

Permalink
use pluralize
Browse files Browse the repository at this point in the history
  • Loading branch information
S-YOU committed Sep 8, 2020
1 parent bb8b728 commit 5926d22
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 34 deletions.
8 changes: 4 additions & 4 deletions internal/repository/repository_indexes.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions internal/repository/repository_indexes_cached.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions templates/inflection_rule.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
- singular: bonus
plural: bonuses
- singular: UserID
plural: UserIDs
- singular: GroupID
plural: GroupIDs
10 changes: 5 additions & 5 deletions templates/repository_indexes/index.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

{{- if not .Index.IsUnique }}

// Find{{$typeName}}sBy{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }} retrieves multiple rows from '{{ $table }}' as a slice of {{ .Type.Name }}.
// Find{{pluralize $typeName}}By{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }} retrieves multiple rows from '{{ $table }}' as a slice of {{ .Type.Name }}.
// Generated from index '{{ .Index.IndexName }}'.
func ({{$short}} {{$name}}) Find{{$typeName}}sBy{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}(ctx context.Context{{ goparamlist .Fields true true }}) ([]*model.{{ .Type.Name }}, error) {
func ({{$short}} {{$name}}) Find{{pluralize $typeName}}By{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}(ctx context.Context{{ goparamlist .Fields true true }}) ([]*model.{{ .Type.Name }}, error) {
{{ $lname }} := []*model.{{ .Type.Name }}{}
if err := {{$short}}.Builder().
Where("{{ colnamesquery .Fields " AND " }}", Params{
Expand Down Expand Up @@ -43,14 +43,14 @@ func ({{$short}} {{$name}}) Get{{ .FuncName }}(ctx context.Context{{ goparamlist
}
{{- end }}

// Find{{$typeName}}sBy{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}s retrieves multiple rows from '{{ $table }}' as []*model.{{ .Type.Name }}.
// Find{{pluralize $typeName}}By{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{pluralize .Name }}{{ end }} retrieves multiple rows from '{{ $table }}' as []*model.{{ .Type.Name }}.
// Generated from index '{{ .Index.IndexName }}'.
func ({{$short}} {{$name}}) Find{{$typeName}}sBy{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}s(ctx context.Context{{- range .Fields }}, {{goparamname .Name}}s []{{.Type}}{{end}}) ([]*model.{{ .Type.Name }}, error) {
func ({{$short}} {{$name}}) Find{{pluralize $typeName}}By{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{pluralize .Name }}{{ end }}(ctx context.Context{{- range .Fields }}, {{goparamname (pluralize .Name)}} []{{.Type}}{{end}}) ([]*model.{{ .Type.Name }}, error) {
var items []*model.{{ .Type.Name }}
if err := {{$short}}.Builder().Where("{{- range $i, $f := .Fields }}{{ if $i }} AND {{ end }}{{colname $f.Col}} IN UNNEST(@arg{{$i}}){{ end -}}", Params{
{{- range $i, $f := .Fields -}}
{{- if $i }}, {{ end -}}
"arg{{ $i }}": {{ goparamname $f.Name }}s
"arg{{ $i }}": {{goparamname (pluralize .Name)}}
{{- end}}}).Query(ctx).Intos(&items); err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions templates/repository_indexes/type.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
type {{ $database }}Indexes interface {
Get{{.Name}}By{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end -}}
(ctx context.Context{{ goparamlist .PrimaryKeyFields true true }}) (*model.{{ .Name }}, error)
Find{{.Name}}sBy{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ .Name }}s{{ end -}}
(ctx context.Context{{- range .PrimaryKeyFields }}, {{goparamname .Name}}s []{{.Type}}{{end}}) ([]*model.{{ .Name }}, error)
Find{{pluralize .Name}}By{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ pluralize .Name }}{{ end -}}
(ctx context.Context{{- range .PrimaryKeyFields }}, {{goparamname (pluralize .Name)}} []{{.Type}}{{end}}) ([]*model.{{ .Name }}, error)
{{- range .Indexes -}}
{{- if not .Index.IsUnique }}
Find{{$typeName}}sBy{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}(ctx context.Context{{ goparamlist .Fields true true }}) ([]*model.{{ .Type.Name }}, error)
Find{{pluralize $typeName}}By{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}(ctx context.Context{{ goparamlist .Fields true true }}) ([]*model.{{ .Type.Name }}, error)
{{- else }}
Get{{ .FuncName }}(ctx context.Context{{ goparamlist .Fields true true }}) (*model.{{ .Type.Name }}, error)
{{- end }}
Find{{$typeName}}sBy{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}s(ctx context.Context{{- range .Fields }}, {{goparamname .Name}}s []{{.Type}}{{end}}) ([]*model.{{ .Type.Name }}, error)
Find{{pluralize $typeName}}By{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{pluralize .Name }}{{ end }}(ctx context.Context{{- range .Fields }}, {{goparamname (pluralize .Name)}} []{{.Type}}{{end}}) ([]*model.{{ .Type.Name }}, error)
{{- end}}
}

Expand All @@ -42,15 +42,15 @@ func ({{$short}} {{$name}}) Get{{.Name}}By
return {{ $lname }}, nil
}

// Find{{.Name}}sBy{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ .Name }}s{{ end }} retrieves multiple rows from '{{ $table }}' as []*model.{{ .Name }}.
// Find{{pluralize .Name}}By{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ pluralize .Name }}{{ end }} retrieves multiple rows from '{{ $table }}' as []*model.{{ .Name }}.
// Generated from primary key
func ({{$short}} {{$name}}) Find{{.Name}}sBy{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ .Name }}s{{ end -}}
(ctx context.Context{{- range .PrimaryKeyFields }}, {{goparamname .Name}}s []{{.Type}}{{end}}) ([]*model.{{ .Name }}, error) {
func ({{$short}} {{$name}}) Find{{pluralize .Name}}By{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ pluralize .Name }}{{ end -}}
(ctx context.Context{{- range .PrimaryKeyFields }}, {{goparamname (pluralize .Name)}} []{{.Type}}{{end}}) ([]*model.{{ .Name }}, error) {
var items []*model.{{ .Name }}
if err := {{$short}}.Builder().Where("{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }} AND {{ end }}{{colname $f.Col}} IN UNNEST(@arg{{$i}}){{ end -}}", Params{
{{- range $i, $f := .PrimaryKeyFields -}}
{{- if $i }}, {{ end -}}
"arg{{ $i }}": {{ goparamname $f.Name }}s
"arg{{ $i }}": {{goparamname (pluralize .Name)}}
{{- end}}}).
Query(ctx).Intos(&items); err != nil {
return nil, err
Expand Down
10 changes: 5 additions & 5 deletions templates/repository_indexes_cached/index.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@

{{- if not .Index.IsUnique }}

// Get{{$typeName}}sBy{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}Cached retrieves multiple rows from cache or '{{ $table }}' as a slice of {{ .Type.Name }}.
// Get{{pluralize $typeName}}By{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}Cached retrieves multiple rows from cache or '{{ $table }}' as a slice of {{ .Type.Name }}.
// Generated from index '{{ .Index.IndexName }}'.
func ({{$short}} {{$name}}) Find{{$typeName}}sBy{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}Cached(ctx context.Context{{ goparamlist .Fields true true }}) ([]*model.{{ .Type.Name }}, error) {
func ({{$short}} {{$name}}) Find{{pluralize $typeName}}By{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}Cached(ctx context.Context{{ goparamlist .Fields true true }}) ([]*model.{{ .Type.Name }}, error) {
{{ $lname }} := []*model.{{ .Type.Name }}{}
if err := {{$short}}.Builder().
Where("{{ colnamesquery .Fields " AND " }}", Params{
Expand Down Expand Up @@ -44,14 +44,14 @@ func ({{$short}} {{$name}}) Get{{ .FuncName }}Cached(ctx context.Context{{ gopar
}
{{- end }}

// Find{{$typeName}}sBy{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}sCached retrieves multiple rows from '{{ $table }}' or from cache as []*model.{{ .Type.Name }}.
// Find{{pluralize $typeName}}By{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{pluralize .Name }}{{ end }}Cached retrieves multiple rows from '{{ $table }}' or from cache as []*model.{{ .Type.Name }}.
// Generated from unique index '{{ .Index.IndexName }}'.
func ({{$short}} {{$name}}) Find{{$typeName}}sBy{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}sCached(ctx context.Context{{- range .Fields }}, {{goparamname .Name}}s []{{.Type}}{{end}}) ([]*model.{{ .Type.Name }}, error) {
func ({{$short}} {{$name}}) Find{{pluralize $typeName}}By{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{pluralize .Name }}{{ end }}Cached(ctx context.Context{{- range .Fields }}, {{goparamname (pluralize .Name)}} []{{.Type}}{{end}}) ([]*model.{{ .Type.Name }}, error) {
var items []*model.{{ .Type.Name }}
if err := {{$short}}.Builder().Where("{{- range $i, $f := .Fields }}{{ if $i }} AND {{ end }}{{colname $f.Col}} IN UNNEST(@arg{{$i}}){{ end -}}", Params{
{{- range $i, $f := .Fields -}}
{{- if $i }}, {{ end -}}
"arg{{ $i }}": {{ goparamname $f.Name }}s
"arg{{ $i }}": {{goparamname (pluralize .Name)}}
{{- end}}}).QueryCachedIntos(ctx, &items); err != nil {
return nil, err
}
Expand Down
16 changes: 8 additions & 8 deletions templates/repository_indexes_cached/type.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
type {{ $database }}IndexesCached interface {
Get{{.Name}}By{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end -}}
Cached(ctx context.Context{{ goparamlist .PrimaryKeyFields true true }}) (*model.{{ .Name }}, error)
Find{{.Name}}sBy{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ .Name }}s{{ end -}}
Cached(ctx context.Context{{- range .PrimaryKeyFields }}, {{goparamname .Name}}s []{{.Type}}{{end}}) ([]*model.{{ .Name }}, error)
Find{{pluralize .Name}}By{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ pluralize .Name }}{{ end -}}
Cached(ctx context.Context{{- range .PrimaryKeyFields }}, {{goparamname (pluralize .Name) }} []{{.Type}}{{end}}) ([]*model.{{ .Name }}, error)
{{- range .Indexes -}}
{{- if not .Index.IsUnique }}
Find{{$typeName}}sBy{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}Cached(ctx context.Context{{ goparamlist .Fields true true }}) ([]*model.{{ .Type.Name }}, error)
Find{{pluralize $typeName}}By{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}Cached(ctx context.Context{{ goparamlist .Fields true true }}) ([]*model.{{ .Type.Name }}, error)
{{- else }}
Get{{ .FuncName }}Cached(ctx context.Context{{ goparamlist .Fields true true }}) (*model.{{ .Type.Name }}, error)
{{- end }}
Find{{$typeName}}sBy{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{ .Name }}{{ end }}sCached(ctx context.Context{{- range .Fields }}, {{goparamname .Name}}s []{{.Type}}{{end}}) ([]*model.{{ .Type.Name }}, error)
Find{{pluralize $typeName}}By{{- range $i, $f := .Fields }}{{ if $i }}And{{ end }}{{pluralize .Name }}{{ end }}Cached(ctx context.Context{{- range .Fields }}, {{goparamname (pluralize .Name)}} []{{.Type}}{{end}}) ([]*model.{{ .Type.Name }}, error)
{{- end}}
}

Expand All @@ -42,15 +42,15 @@ Cached(ctx context.Context{{ gocustomparamlist .PrimaryKeyFields true true }}) (
return {{ $lname }}, nil
}

// Find{{.Name}}sBy{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ .Name }}s{{ end -}}Cached retrieves multiple rows from '{{ $table }}' or cache as []*model.{{ .Name }}.
// Find{{pluralize .Name}}By{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ pluralize .Name }}{{ end -}}Cached retrieves multiple rows from '{{ $table }}' or cache as []*model.{{ .Name }}.
// Generated from primary key
func ({{$short}} {{$name}}) Find{{.Name}}sBy{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ .Name }}s{{ end -}}
Cached(ctx context.Context{{- range .PrimaryKeyFields }}, {{goparamname .Name}}s []{{.Type}}{{end}}) ([]*model.{{ .Name }}, error) {
func ({{$short}} {{$name}}) Find{{pluralize .Name}}By{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }}And{{ end }}{{ pluralize .Name }}{{ end -}}
Cached(ctx context.Context{{- range .PrimaryKeyFields }}, {{goparamname (pluralize .Name)}} []{{.Type}}{{end}}) ([]*model.{{ .Name }}, error) {
var items []*model.{{ .Name }}
if err := {{$short}}.Builder().Where("{{- range $i, $f := .PrimaryKeyFields }}{{ if $i }} AND {{ end }}{{colname $f.Col}} IN UNNEST(@arg{{$i}}){{ end -}}", Params{
{{- range $i, $f := .PrimaryKeyFields -}}
{{- if $i }}, {{ end -}}
"arg{{ $i }}": {{ goparamname $f.Name }}s
"arg{{ $i }}": {{goparamname (pluralize .Name)}}
{{- end}}}).
QueryCachedIntos(ctx, &items); err != nil {
return nil, err
Expand Down

0 comments on commit 5926d22

Please sign in to comment.