feat: add support for creating users and chirps
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: chirps.sql
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const createChirp = `-- name: CreateChirp :one
|
||||
INSERT INTO chirps (id, created_at, updated_at, body, user_id)
|
||||
VALUES (
|
||||
gen_random_uuid(),
|
||||
NOW(),
|
||||
NOW(),
|
||||
$1,
|
||||
$2
|
||||
)
|
||||
RETURNING id, created_at, updated_at, body, user_id
|
||||
`
|
||||
|
||||
type CreateChirpParams struct {
|
||||
Body string
|
||||
UserID uuid.UUID
|
||||
}
|
||||
|
||||
func (q *Queries) CreateChirp(ctx context.Context, arg CreateChirpParams) (Chirp, error) {
|
||||
row := q.db.QueryRowContext(ctx, createChirp, arg.Body, arg.UserID)
|
||||
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