-
Notifications
You must be signed in to change notification settings - Fork 60
Open
Description
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.
Metadata
Metadata
Assignees
Labels
No labels