budgeteer/postgres/users.sql.go
2021-12-06 20:38:55 +00:00

93 lines
1.8 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// source: users.sql
package postgres
import (
"context"
"github.com/google/uuid"
)
const createUser = `-- name: CreateUser :one
INSERT INTO users
(email, name, password)
VALUES ($1, $2, $3)
RETURNING id, email, name, password, last_login
`
type CreateUserParams struct {
Email string
Name string
Password string
}
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
row := q.db.QueryRowContext(ctx, createUser, arg.Email, arg.Name, arg.Password)
var i User
err := row.Scan(
&i.ID,
&i.Email,
&i.Name,
&i.Password,
&i.LastLogin,
)
return i, err
}
const getUser = `-- name: GetUser :one
SELECT id, email, name, password, last_login FROM users
WHERE id = $1
`
func (q *Queries) GetUser(ctx context.Context, id uuid.UUID) (User, error) {
row := q.db.QueryRowContext(ctx, getUser, id)
var i User
err := row.Scan(
&i.ID,
&i.Email,
&i.Name,
&i.Password,
&i.LastLogin,
)
return i, err
}
const getUserByUsername = `-- name: GetUserByUsername :one
SELECT id, email, name, password, last_login FROM users
WHERE email = $1
`
func (q *Queries) GetUserByUsername(ctx context.Context, email string) (User, error) {
row := q.db.QueryRowContext(ctx, getUserByUsername, email)
var i User
err := row.Scan(
&i.ID,
&i.Email,
&i.Name,
&i.Password,
&i.LastLogin,
)
return i, err
}
const updateLastLogin = `-- name: UpdateLastLogin :one
UPDATE users
SET last_login = NOW()
WHERE users.id = $1
RETURNING id, email, name, password, last_login
`
func (q *Queries) UpdateLastLogin(ctx context.Context, id uuid.UUID) (User, error) {
row := q.db.QueryRowContext(ctx, updateLastLogin, id)
var i User
err := row.Scan(
&i.ID,
&i.Email,
&i.Name,
&i.Password,
&i.LastLogin,
)
return i, err
}