Skip to content

Commit

Permalink
create func plural for template
Browse files Browse the repository at this point in the history
  • Loading branch information
willy182 authored and agungdwiprasetyo committed Oct 24, 2022
1 parent dd22321 commit d5d667e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions cmd/candi/project_generator_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ func formatTemplate() template.FuncMap {
return candihelper.ToCamelCase(v)
},
"snake": func(v string) string {
return candihelper.ToDelimited(v, '_')
},
"plural": func(v string) string {
v = candihelper.Plural(v)

return candihelper.ToDelimited(v, '_')
Expand Down
4 changes: 2 additions & 2 deletions cmd/candi/template_cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ func GetMigrateTables() []interface{} {

templateCmdMigrationInitModule = `-- +goose Up
-- +goose StatementBegin
CREATE TABLE IF NOT EXISTS {{snake .ModuleName}} (
CREATE TABLE IF NOT EXISTS {{plural .ModuleName}} (
"id" VARCHAR(255) NOT NULL PRIMARY KEY,
"field" VARCHAR(255),
"created_at" TIMESTAMPTZ(6),
Expand All @@ -134,7 +134,7 @@ CREATE TABLE IF NOT EXISTS {{snake .ModuleName}} (
-- +goose Down
-- +goose StatementBegin
DROP TABLE IF EXISTS {{snake .ModuleName}};
DROP TABLE IF EXISTS {{plural .ModuleName}};
-- +goose StatementEnd
`
)
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ go 1.16
require (
github.com/HdrHistogram/hdrhistogram-go v1.1.0 // indirect
github.com/Shopify/sarama v1.29.0
github.com/gertd/go-pluralize v0.2.1 // indirect
github.com/gertd/go-pluralize v0.2.1
github.com/go-playground/locales v0.13.0
github.com/go-playground/universal-translator v0.17.0
github.com/go-playground/validator/v10 v10.6.0
Expand Down

0 comments on commit d5d667e

Please sign in to comment.