Skip to content

Why Find{{ .Name }} is not generated when there is no columns except primary key? #75

Description

@cloverrose

yo/templates/type.go.tpl

Lines 157 to 196 in 20fce06

// Find{{ .Name }} gets a {{ .Name }} by primary key
func Find{{ .Name }}(ctx context.Context, db YORODB{{ gocustomparamlist .PrimaryKeyFields true true }}) (*{{ .Name }}, error) {
key := spanner.Key{ {{ gocustomparamlist .PrimaryKeyFields false false }} }
row, err := db.ReadRow(ctx, "{{ $table }}", key, {{ .Name }}Columns())
if err != nil {
return nil, newError("Find{{ .Name }}", "{{ $table }}", err)
}
decoder := new{{ .Name }}_Decoder({{ .Name}}Columns())
{{ $short }}, err := decoder(row)
if err != nil {
return nil, newErrorWithCode(codes.Internal, "Find{{ .Name }}", "{{ $table }}", err)
}
return {{ $short }}, nil
}
// Read{{ .Name }} retrieves multiples rows from {{ .Name }} by KeySet as a slice.
func Read{{ .Name }}(ctx context.Context, db YORODB, keys spanner.KeySet) ([]*{{ .Name }}, error) {
var res []*{{ .Name }}
decoder := new{{ .Name }}_Decoder({{ .Name}}Columns())
rows := db.Read(ctx, "{{ $table }}", keys, {{ .Name }}Columns())
err := rows.Do(func(row *spanner.Row) error {
{{ $short }}, err := decoder(row)
if err != nil {
return err
}
res = append(res, {{ $short }})
return nil
})
if err != nil {
return nil, newErrorWithCode(codes.Internal, "Read{{ .Name }}", "{{ $table }}", err)
}
return res, nil
}
{{ end }}

Hi, this is just a question. I want to know the background of it.
I imagine I want to use Find{{ .Name }} method to know the data already exists or not.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions