feat: we made it better...aka i did too many things and don't remember

This commit is contained in:
Stevan Freeborn
2026-08-15 10:48:29 -05:00
parent 5c5a126d88
commit c3fded4492
14 changed files with 919 additions and 72 deletions
+61
View File
@@ -40,3 +40,64 @@ func (q *Queries) CreateChirp(ctx context.Context, arg CreateChirpParams) (Chirp
)
return i, err
}
const deleteChirpById = `-- name: DeleteChirpById :exec
DELETE FROM chirps WHERE id = $1
`
func (q *Queries) DeleteChirpById(ctx context.Context, id uuid.UUID) error {
_, err := q.db.ExecContext(ctx, deleteChirpById, id)
return err
}
const getAllChirps = `-- name: GetAllChirps :many
SELECT id, created_at, updated_at, body, user_id FROM chirps
ORDER BY created_at ASC
`
func (q *Queries) GetAllChirps(ctx context.Context) ([]Chirp, error) {
rows, err := q.db.QueryContext(ctx, getAllChirps)
if err != nil {
return nil, err
}
defer rows.Close()
var items []Chirp
for rows.Next() {
var i Chirp
if err := rows.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.Body,
&i.UserID,
); err != nil {
return nil, err
}
items = append(items, i)
}
if err := rows.Close(); err != nil {
return nil, err
}
if err := rows.Err(); err != nil {
return nil, err
}
return items, nil
}
const getChirpById = `-- name: GetChirpById :one
SELECT id, created_at, updated_at, body, user_id FROM chirps
WHERE id = $1
`
func (q *Queries) GetChirpById(ctx context.Context, id uuid.UUID) (Chirp, error) {
row := q.db.QueryRowContext(ctx, getChirpById, id)
var i Chirp
err := row.Scan(
&i.ID,
&i.CreatedAt,
&i.UpdatedAt,
&i.Body,
&i.UserID,
)
return i, err
}