getting chirps!
This commit is contained in:
21
internal/dataMaps/maps.go
Normal file
21
internal/dataMaps/maps.go
Normal file
@@ -0,0 +1,21 @@
|
||||
package dataMaps
|
||||
|
||||
import (
|
||||
"github.com/google/uuid"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Chirp struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Body string `json:"body"`
|
||||
UserID uuid.UUID `json:"user_id"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
ID uuid.UUID `json:"id"`
|
||||
CreatedAt time.Time `json:"created_at"`
|
||||
UpdatedAt time.Time `json:"updated_at"`
|
||||
Email string `json:"email"`
|
||||
}
|
||||
43
internal/database/GetAllChirps.sql.go
Normal file
43
internal/database/GetAllChirps.sql.go
Normal file
@@ -0,0 +1,43 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// source: GetAllChirps.sql
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
)
|
||||
|
||||
const getAllChirps = `-- name: GetAllChirps :many
|
||||
SELECT id, created_at, updated_at, body, user_id FROM chirps ORDER BY created_at
|
||||
`
|
||||
|
||||
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
|
||||
}
|
||||
29
internal/database/GetChirpByID.sql.go
Normal file
29
internal/database/GetChirpByID.sql.go
Normal file
@@ -0,0 +1,29 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.28.0
|
||||
// source: GetChirpByID.sql
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
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