feat: add support for creating users and chirps
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: users.sql
|
||||
|
||||
package database
|
||||
|
||||
import (
|
||||
"context"
|
||||
|
||||
"github.com/google/uuid"
|
||||
)
|
||||
|
||||
const createUser = `-- name: CreateUser :one
|
||||
INSERT INTO users (id, created_at, updated_at, email)
|
||||
VALUES (
|
||||
gen_random_uuid(),
|
||||
NOW(),
|
||||
NOW(),
|
||||
$1
|
||||
)
|
||||
RETURNING id, created_at, updated_at, email
|
||||
`
|
||||
|
||||
func (q *Queries) CreateUser(ctx context.Context, email string) (User, error) {
|
||||
row := q.db.QueryRowContext(ctx, createUser, email)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Email,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const deleteAllUsers = `-- name: DeleteAllUsers :exec
|
||||
DELETE FROM users
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteAllUsers(ctx context.Context) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteAllUsers)
|
||||
return err
|
||||
}
|
||||
|
||||
const getUserById = `-- name: GetUserById :one
|
||||
SELECT id, created_at, updated_at, email FROM users
|
||||
WHERE id = $1
|
||||
`
|
||||
|
||||
func (q *Queries) GetUserById(ctx context.Context, id uuid.UUID) (User, error) {
|
||||
row := q.db.QueryRowContext(ctx, getUserById, id)
|
||||
var i User
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.CreatedAt,
|
||||
&i.UpdatedAt,
|
||||
&i.Email,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
Reference in New Issue
Block a user