feat: we made it better...aka i did too many things and don't remember
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user