diff --git a/core/codegen/base.builder.go b/core/codegen/base.builder.go index 52d917cc..9f86be9a 100644 --- a/core/codegen/base.builder.go +++ b/core/codegen/base.builder.go @@ -308,9 +308,11 @@ func (b *build) buildBaseFile(node *field.NodeTable) error { jen.Id("Relate").Call().Op("*").Qual(b.subPkg(def.PkgRelate), node.NameGo()), ) - f.Line() - f.Func(). - Params(jen.Id("c").Op("*").Id("ClientImpl")). + f.Line(). + Add(comment(` +` + node.NameGo() + `Repo returns a new repository instance for the ` + node.NameGo() + ` model. + `)). + Func().Params(jen.Id("c").Op("*").Id("ClientImpl")). Id(node.NameGo() + "Repo").Params().Id(node.NameGo() + "Repo"). Block( jen.Return( @@ -358,9 +360,11 @@ func (b *build) buildBaseFile(node *field.NodeTable) error { ), ) - f.Line() - f.Func(). - Params(jen.Id("r").Op("*").Id(node.NameGoLower())). + f.Line(). + Add(comment(` +Query returns a new query builder for the `+node.NameGo()+` model. + `)). + Func().Params(jen.Id("r").Op("*").Id(node.NameGoLower())). Id("Query").Params(). Qual(pkgQuery, "Builder"). Types( @@ -374,9 +378,12 @@ func (b *build) buildBaseFile(node *field.NodeTable) error { )), ) - f.Line() - f.Func(). - Params(jen.Id("r").Op("*").Id(node.NameGoLower())). + f.Line(). + Add(comment(` +Create creates a new record for the `+node.NameGo()+` model. +The ID will be generated automatically as a ULID. + `)). + Func().Params(jen.Id("r").Op("*").Id(node.NameGoLower())). Id("Create"). Params( jen.Id("ctx").Qual("context", "Context"), @@ -402,9 +409,11 @@ func (b *build) buildBaseFile(node *field.NodeTable) error { ), ) - f.Line() - f.Func(). - Params(jen.Id("r").Op("*").Id(node.NameGoLower())). + f.Line(). + Add(comment(` +CreateWithID creates a new record for the `+node.NameGo()+` model with the given id. + `)). + Func().Params(jen.Id("r").Op("*").Id(node.NameGoLower())). Id("CreateWithID"). Params( jen.Id("ctx").Qual("context", "Context"), @@ -432,9 +441,12 @@ func (b *build) buildBaseFile(node *field.NodeTable) error { ), ) - f.Line() - f.Func(). - Params(jen.Id("r").Op("*").Id(node.NameGoLower())). + f.Line(). + Add(comment(` +Read returns the record for the given id, if it exists. +The returned bool indicates whether the record was found or not. + `)). + Func().Params(jen.Id("r").Op("*").Id(node.NameGoLower())). Id("Read"). Params( jen.Id("ctx").Qual("context", "Context"), @@ -450,9 +462,11 @@ func (b *build) buildBaseFile(node *field.NodeTable) error { ), ) - f.Line() - f.Func(). - Params(jen.Id("r").Op("*").Id(node.NameGoLower())). + f.Line(). + Add(comment(` +Update updates the record for the given model. + `)). + Func().Params(jen.Id("r").Op("*").Id(node.NameGoLower())). Id("Update"). Params( jen.Id("ctx").Qual("context", "Context"), @@ -479,9 +493,11 @@ func (b *build) buildBaseFile(node *field.NodeTable) error { ), ) - f.Line() - f.Func(). - Params(jen.Id("r").Op("*").Id(node.NameGoLower())). + f.Line(). + Add(comment(` +Delete deletes the record for the given model. + `)). + Func().Params(jen.Id("r").Op("*").Id(node.NameGoLower())). Id("Delete"). Params( jen.Id("ctx").Qual("context", "Context"), @@ -503,9 +519,11 @@ func (b *build) buildBaseFile(node *field.NodeTable) error { ), ) - f.Line() - f.Func(). - Params(jen.Id("r").Op("*").Id(node.NameGoLower())). + f.Line(). + Add(comment(` +Refresh refreshes the given model with the remote data. + `)). + Func().Params(jen.Id("r").Op("*").Id(node.NameGoLower())). Id("Refresh"). Params( jen.Id("ctx").Qual("context", "Context"), @@ -532,9 +550,11 @@ func (b *build) buildBaseFile(node *field.NodeTable) error { ), ) - f.Line() - f.Func(). - Params(jen.Id("r").Op("*").Id(node.NameGoLower())). + f.Line(). + Add(comment(` +Relate returns a new relate instance for the `+node.NameGo()+` model. + `)). + Func().Params(jen.Id("r").Op("*").Id(node.NameGoLower())). Id("Relate").Params(). Op("*").Qual(b.subPkg(def.PkgRelate), node.NameGo()). Block( @@ -593,3 +613,20 @@ func (b *build) basePkgName() string { func (b *build) subPkg(pkg string) string { return path.Join(b.basePkg(), pkg) } + +// +// -- HELPER +// + +func comment(text string) jen.Code { + var code jen.Statement + + text = strings.TrimSpace(text) + lines := strings.Split(text, "\n") + + for _, line := range lines { + code.Comment(line).Line() + } + + return &code +} diff --git a/tests/basic/gen/som/node.all_field_types.go b/tests/basic/gen/som/node.all_field_types.go index a29255f1..f2c834ad 100644 --- a/tests/basic/gen/som/node.all_field_types.go +++ b/tests/basic/gen/som/node.all_field_types.go @@ -21,6 +21,7 @@ type AllFieldTypesRepo interface { Relate() *relate.AllFieldTypes } +// AllFieldTypesRepo returns a new repository instance for the AllFieldTypes model. func (c *ClientImpl) AllFieldTypesRepo() AllFieldTypesRepo { return &allFieldTypes{repo: &repo[model.AllFieldTypes, conv.AllFieldTypes]{ db: c.db, @@ -35,10 +36,13 @@ type allFieldTypes struct { *repo[model.AllFieldTypes, conv.AllFieldTypes] } +// Query returns a new query builder for the AllFieldTypes model. func (r *allFieldTypes) Query() query.Builder[model.AllFieldTypes, conv.AllFieldTypes] { return query.NewAllFieldTypes(r.db, r.unmarshal) } +// Create creates a new record for the AllFieldTypes model. +// The ID will be generated automatically as a ULID. func (r *allFieldTypes) Create(ctx context.Context, allFieldTypes *model.AllFieldTypes) error { if allFieldTypes == nil { return errors.New("the passed node must not be nil") @@ -49,6 +53,7 @@ func (r *allFieldTypes) Create(ctx context.Context, allFieldTypes *model.AllFiel return r.create(ctx, allFieldTypes) } +// CreateWithID creates a new record for the AllFieldTypes model with the given id. func (r *allFieldTypes) CreateWithID(ctx context.Context, id string, allFieldTypes *model.AllFieldTypes) error { if allFieldTypes == nil { return errors.New("the passed node must not be nil") @@ -59,10 +64,13 @@ func (r *allFieldTypes) CreateWithID(ctx context.Context, id string, allFieldTyp return r.createWithID(ctx, id, allFieldTypes) } +// Read returns the record for the given id, if it exists. +// The returned bool indicates whether the record was found or not. func (r *allFieldTypes) Read(ctx context.Context, id string) (*model.AllFieldTypes, bool, error) { return r.read(ctx, id) } +// Update updates the record for the given model. func (r *allFieldTypes) Update(ctx context.Context, allFieldTypes *model.AllFieldTypes) error { if allFieldTypes == nil { return errors.New("the passed node must not be nil") @@ -73,6 +81,7 @@ func (r *allFieldTypes) Update(ctx context.Context, allFieldTypes *model.AllFiel return r.update(ctx, allFieldTypes.ID(), allFieldTypes) } +// Delete deletes the record for the given model. func (r *allFieldTypes) Delete(ctx context.Context, allFieldTypes *model.AllFieldTypes) error { if allFieldTypes == nil { return errors.New("the passed node must not be nil") @@ -80,6 +89,7 @@ func (r *allFieldTypes) Delete(ctx context.Context, allFieldTypes *model.AllFiel return r.delete(ctx, allFieldTypes.ID(), allFieldTypes) } +// Refresh refreshes the given model with the remote data. func (r *allFieldTypes) Refresh(ctx context.Context, allFieldTypes *model.AllFieldTypes) error { if allFieldTypes == nil { return errors.New("the passed node must not be nil") @@ -90,6 +100,7 @@ func (r *allFieldTypes) Refresh(ctx context.Context, allFieldTypes *model.AllFie return r.refresh(ctx, allFieldTypes.ID(), allFieldTypes) } +// Relate returns a new relate instance for the AllFieldTypes model. func (r *allFieldTypes) Relate() *relate.AllFieldTypes { return relate.NewAllFieldTypes(r.db, r.unmarshal) } diff --git a/tests/basic/gen/som/node.fields_like_db_response.go b/tests/basic/gen/som/node.fields_like_db_response.go index 74d07b41..60ea8c5e 100644 --- a/tests/basic/gen/som/node.fields_like_db_response.go +++ b/tests/basic/gen/som/node.fields_like_db_response.go @@ -21,6 +21,7 @@ type FieldsLikeDBResponseRepo interface { Relate() *relate.FieldsLikeDBResponse } +// FieldsLikeDBResponseRepo returns a new repository instance for the FieldsLikeDBResponse model. func (c *ClientImpl) FieldsLikeDBResponseRepo() FieldsLikeDBResponseRepo { return &fieldsLikeDbresponse{repo: &repo[model.FieldsLikeDBResponse, conv.FieldsLikeDBResponse]{ db: c.db, @@ -35,10 +36,13 @@ type fieldsLikeDbresponse struct { *repo[model.FieldsLikeDBResponse, conv.FieldsLikeDBResponse] } +// Query returns a new query builder for the FieldsLikeDBResponse model. func (r *fieldsLikeDbresponse) Query() query.Builder[model.FieldsLikeDBResponse, conv.FieldsLikeDBResponse] { return query.NewFieldsLikeDBResponse(r.db, r.unmarshal) } +// Create creates a new record for the FieldsLikeDBResponse model. +// The ID will be generated automatically as a ULID. func (r *fieldsLikeDbresponse) Create(ctx context.Context, fieldsLikeDbresponse *model.FieldsLikeDBResponse) error { if fieldsLikeDbresponse == nil { return errors.New("the passed node must not be nil") @@ -49,6 +53,7 @@ func (r *fieldsLikeDbresponse) Create(ctx context.Context, fieldsLikeDbresponse return r.create(ctx, fieldsLikeDbresponse) } +// CreateWithID creates a new record for the FieldsLikeDBResponse model with the given id. func (r *fieldsLikeDbresponse) CreateWithID(ctx context.Context, id string, fieldsLikeDbresponse *model.FieldsLikeDBResponse) error { if fieldsLikeDbresponse == nil { return errors.New("the passed node must not be nil") @@ -59,10 +64,13 @@ func (r *fieldsLikeDbresponse) CreateWithID(ctx context.Context, id string, fiel return r.createWithID(ctx, id, fieldsLikeDbresponse) } +// Read returns the record for the given id, if it exists. +// The returned bool indicates whether the record was found or not. func (r *fieldsLikeDbresponse) Read(ctx context.Context, id string) (*model.FieldsLikeDBResponse, bool, error) { return r.read(ctx, id) } +// Update updates the record for the given model. func (r *fieldsLikeDbresponse) Update(ctx context.Context, fieldsLikeDbresponse *model.FieldsLikeDBResponse) error { if fieldsLikeDbresponse == nil { return errors.New("the passed node must not be nil") @@ -73,6 +81,7 @@ func (r *fieldsLikeDbresponse) Update(ctx context.Context, fieldsLikeDbresponse return r.update(ctx, fieldsLikeDbresponse.ID(), fieldsLikeDbresponse) } +// Delete deletes the record for the given model. func (r *fieldsLikeDbresponse) Delete(ctx context.Context, fieldsLikeDbresponse *model.FieldsLikeDBResponse) error { if fieldsLikeDbresponse == nil { return errors.New("the passed node must not be nil") @@ -80,6 +89,7 @@ func (r *fieldsLikeDbresponse) Delete(ctx context.Context, fieldsLikeDbresponse return r.delete(ctx, fieldsLikeDbresponse.ID(), fieldsLikeDbresponse) } +// Refresh refreshes the given model with the remote data. func (r *fieldsLikeDbresponse) Refresh(ctx context.Context, fieldsLikeDbresponse *model.FieldsLikeDBResponse) error { if fieldsLikeDbresponse == nil { return errors.New("the passed node must not be nil") @@ -90,6 +100,7 @@ func (r *fieldsLikeDbresponse) Refresh(ctx context.Context, fieldsLikeDbresponse return r.refresh(ctx, fieldsLikeDbresponse.ID(), fieldsLikeDbresponse) } +// Relate returns a new relate instance for the FieldsLikeDBResponse model. func (r *fieldsLikeDbresponse) Relate() *relate.FieldsLikeDBResponse { return relate.NewFieldsLikeDBResponse(r.db, r.unmarshal) } diff --git a/tests/basic/gen/som/node.group.go b/tests/basic/gen/som/node.group.go index 950b6958..b73f338a 100644 --- a/tests/basic/gen/som/node.group.go +++ b/tests/basic/gen/som/node.group.go @@ -21,6 +21,7 @@ type GroupRepo interface { Relate() *relate.Group } +// GroupRepo returns a new repository instance for the Group model. func (c *ClientImpl) GroupRepo() GroupRepo { return &group{repo: &repo[model.Group, conv.Group]{ db: c.db, @@ -35,10 +36,13 @@ type group struct { *repo[model.Group, conv.Group] } +// Query returns a new query builder for the Group model. func (r *group) Query() query.Builder[model.Group, conv.Group] { return query.NewGroup(r.db, r.unmarshal) } +// Create creates a new record for the Group model. +// The ID will be generated automatically as a ULID. func (r *group) Create(ctx context.Context, group *model.Group) error { if group == nil { return errors.New("the passed node must not be nil") @@ -49,6 +53,7 @@ func (r *group) Create(ctx context.Context, group *model.Group) error { return r.create(ctx, group) } +// CreateWithID creates a new record for the Group model with the given id. func (r *group) CreateWithID(ctx context.Context, id string, group *model.Group) error { if group == nil { return errors.New("the passed node must not be nil") @@ -59,10 +64,13 @@ func (r *group) CreateWithID(ctx context.Context, id string, group *model.Group) return r.createWithID(ctx, id, group) } +// Read returns the record for the given id, if it exists. +// The returned bool indicates whether the record was found or not. func (r *group) Read(ctx context.Context, id string) (*model.Group, bool, error) { return r.read(ctx, id) } +// Update updates the record for the given model. func (r *group) Update(ctx context.Context, group *model.Group) error { if group == nil { return errors.New("the passed node must not be nil") @@ -73,6 +81,7 @@ func (r *group) Update(ctx context.Context, group *model.Group) error { return r.update(ctx, group.ID(), group) } +// Delete deletes the record for the given model. func (r *group) Delete(ctx context.Context, group *model.Group) error { if group == nil { return errors.New("the passed node must not be nil") @@ -80,6 +89,7 @@ func (r *group) Delete(ctx context.Context, group *model.Group) error { return r.delete(ctx, group.ID(), group) } +// Refresh refreshes the given model with the remote data. func (r *group) Refresh(ctx context.Context, group *model.Group) error { if group == nil { return errors.New("the passed node must not be nil") @@ -90,6 +100,7 @@ func (r *group) Refresh(ctx context.Context, group *model.Group) error { return r.refresh(ctx, group.ID(), group) } +// Relate returns a new relate instance for the Group model. func (r *group) Relate() *relate.Group { return relate.NewGroup(r.db, r.unmarshal) } diff --git a/tests/basic/gen/som/node.url_example.go b/tests/basic/gen/som/node.url_example.go index cab5ae1f..dbd1de0d 100644 --- a/tests/basic/gen/som/node.url_example.go +++ b/tests/basic/gen/som/node.url_example.go @@ -21,6 +21,7 @@ type URLExampleRepo interface { Relate() *relate.URLExample } +// URLExampleRepo returns a new repository instance for the URLExample model. func (c *ClientImpl) URLExampleRepo() URLExampleRepo { return &urlexample{repo: &repo[model.URLExample, conv.URLExample]{ db: c.db, @@ -35,10 +36,13 @@ type urlexample struct { *repo[model.URLExample, conv.URLExample] } +// Query returns a new query builder for the URLExample model. func (r *urlexample) Query() query.Builder[model.URLExample, conv.URLExample] { return query.NewURLExample(r.db, r.unmarshal) } +// Create creates a new record for the URLExample model. +// The ID will be generated automatically as a ULID. func (r *urlexample) Create(ctx context.Context, urlexample *model.URLExample) error { if urlexample == nil { return errors.New("the passed node must not be nil") @@ -49,6 +53,7 @@ func (r *urlexample) Create(ctx context.Context, urlexample *model.URLExample) e return r.create(ctx, urlexample) } +// CreateWithID creates a new record for the URLExample model with the given id. func (r *urlexample) CreateWithID(ctx context.Context, id string, urlexample *model.URLExample) error { if urlexample == nil { return errors.New("the passed node must not be nil") @@ -59,10 +64,13 @@ func (r *urlexample) CreateWithID(ctx context.Context, id string, urlexample *mo return r.createWithID(ctx, id, urlexample) } +// Read returns the record for the given id, if it exists. +// The returned bool indicates whether the record was found or not. func (r *urlexample) Read(ctx context.Context, id string) (*model.URLExample, bool, error) { return r.read(ctx, id) } +// Update updates the record for the given model. func (r *urlexample) Update(ctx context.Context, urlexample *model.URLExample) error { if urlexample == nil { return errors.New("the passed node must not be nil") @@ -73,6 +81,7 @@ func (r *urlexample) Update(ctx context.Context, urlexample *model.URLExample) e return r.update(ctx, urlexample.ID(), urlexample) } +// Delete deletes the record for the given model. func (r *urlexample) Delete(ctx context.Context, urlexample *model.URLExample) error { if urlexample == nil { return errors.New("the passed node must not be nil") @@ -80,6 +89,7 @@ func (r *urlexample) Delete(ctx context.Context, urlexample *model.URLExample) e return r.delete(ctx, urlexample.ID(), urlexample) } +// Refresh refreshes the given model with the remote data. func (r *urlexample) Refresh(ctx context.Context, urlexample *model.URLExample) error { if urlexample == nil { return errors.New("the passed node must not be nil") @@ -90,6 +100,7 @@ func (r *urlexample) Refresh(ctx context.Context, urlexample *model.URLExample) return r.refresh(ctx, urlexample.ID(), urlexample) } +// Relate returns a new relate instance for the URLExample model. func (r *urlexample) Relate() *relate.URLExample { return relate.NewURLExample(r.db, r.unmarshal) }