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

Method FindAll

pokemon-api/pokedex/repo.go:42–70  ·  view source on GitHub ↗
(ctx context.Context)

Source from the content-addressed store, hash-verified

40}
41
42func (p *Repository) FindAll(ctx context.Context) ([]Pokemon, error) {
43 rows, err := p.db.Query(ctx, "SELECT id, name, types, created_at, updated_at FROM pokemon")
44 if err != nil {
45 return nil, fmt.Errorf("failed to find all pokemon: %w", err)
46 }
47
48 defer rows.Close()
49 res := make([]Pokemon, 0)
50
51 for rows.Next() {
52 var pokemon Pokemon
53
54 err := rows.Scan(
55 &pokemon.ID,
56 &pokemon.Name,
57 &pokemon.Types,
58 &pokemon.CreatedAt,
59 &pokemon.UpdatedAt,
60 )
61
62 if err != nil {
63 return nil, fmt.Errorf("failed to scan pokemon: %w", err)
64 }
65
66 res = append(res, pokemon)
67 }
68
69 return res, nil
70}
71
72func (p *Repository) FindByID(ctx context.Context, id int32) (Pokemon, error) {
73 res := Pokemon{}

Callers 1

ReadMethod · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected