| 23 | } |
| 24 | |
| 25 | func (p *Repository) Insert(ctx context.Context, pokemon Pokemon) error { |
| 26 | _, err := p.db.Exec( |
| 27 | ctx, |
| 28 | "INSERT INTO pokemon (id, name, types, created_at, updated_at) VALUES ($1, $2, $3, $4, $5)", |
| 29 | pokemon.ID, |
| 30 | pokemon.Name, |
| 31 | pokemon.Types, |
| 32 | pokemon.CreatedAt, |
| 33 | pokemon.UpdatedAt, |
| 34 | ) |
| 35 | if err != nil { |
| 36 | return fmt.Errorf("failed to insert pokemon: %w", err) |
| 37 | } |
| 38 | |
| 39 | return nil |
| 40 | } |
| 41 | |
| 42 | func (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") |