MCPcopy Create free account
hub / github.com/dreamsofcode-io/grpc / FindByID

Method FindByID

pokemon-api/pokedex/repo.go:72–94  ·  view source on GitHub ↗
(ctx context.Context, id int32)

Source from the content-addressed store, hash-verified

70}
71
72func (p *Repository) FindByID(ctx context.Context, id int32) (Pokemon, error) {
73 res := Pokemon{}
74
75 err := p.db.QueryRow(
76 ctx,
77 "SELECT id, name, types, created_at, updated_at FROM pokemon WHERE id = $1",
78 id,
79 ).Scan(
80 &res.ID,
81 &res.Name,
82 &res.Types,
83 &res.CreatedAt,
84 &res.UpdatedAt,
85 )
86
87 if errors.Is(err, pgx.ErrNoRows) {
88 return Pokemon{}, ErrNotFound
89 } else if err != nil {
90 return Pokemon{}, fmt.Errorf("failed to find pokemon by id: %w", err)
91 }
92
93 return res, nil
94}
95
96func (p *Repository) Update(ctx context.Context, pokemon Pokemon) error {
97 res, err := p.db.Exec(

Callers 2

ReadOneMethod · 0.80
UpdateMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected