2023-03-03 05:51:53 +00:00
|
|
|
// Code generated by sqlc. DO NOT EDIT.
|
|
|
|
// versions:
|
|
|
|
// sqlc v1.17.2
|
|
|
|
// source: invites.sql
|
|
|
|
|
|
|
|
package database
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2023-03-04 06:02:24 +00:00
|
|
|
"database/sql"
|
2023-03-03 05:51:53 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const countInvites = `-- name: CountInvites :one
|
|
|
|
SELECT count(*) FROM invites
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) CountInvites(ctx context.Context) (int64, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, countInvites)
|
|
|
|
var count int64
|
|
|
|
err := row.Scan(&count)
|
|
|
|
return count, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const createInvite = `-- name: CreateInvite :one
|
|
|
|
INSERT INTO invites (
|
|
|
|
code, uses, total, expiration
|
|
|
|
) VALUES (
|
|
|
|
?, ?, ?, ?
|
|
|
|
)
|
|
|
|
RETURNING id, code, uses, total, expiration
|
|
|
|
`
|
|
|
|
|
|
|
|
type CreateInviteParams struct {
|
|
|
|
Code string
|
|
|
|
Uses int64
|
2023-03-04 06:02:24 +00:00
|
|
|
Total sql.NullInt64
|
|
|
|
Expiration sql.NullInt64
|
2023-03-03 05:51:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) CreateInvite(ctx context.Context, arg CreateInviteParams) (Invite, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, createInvite,
|
|
|
|
arg.Code,
|
|
|
|
arg.Uses,
|
|
|
|
arg.Total,
|
|
|
|
arg.Expiration,
|
|
|
|
)
|
|
|
|
var i Invite
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Code,
|
|
|
|
&i.Uses,
|
|
|
|
&i.Total,
|
|
|
|
&i.Expiration,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const deleteInvite = `-- name: DeleteInvite :exec
|
|
|
|
DELETE FROM invites
|
|
|
|
WHERE id = ?
|
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) DeleteInvite(ctx context.Context, id int64) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, deleteInvite, id)
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
const getInvite = `-- name: GetInvite :one
|
|
|
|
SELECT id, code, uses, total, expiration FROM invites
|
2023-03-04 06:02:24 +00:00
|
|
|
WHERE code = ? LIMIT 1
|
2023-03-03 05:51:53 +00:00
|
|
|
`
|
|
|
|
|
2023-03-04 06:02:24 +00:00
|
|
|
func (q *Queries) GetInvite(ctx context.Context, code string) (Invite, error) {
|
|
|
|
row := q.db.QueryRowContext(ctx, getInvite, code)
|
2023-03-03 05:51:53 +00:00
|
|
|
var i Invite
|
|
|
|
err := row.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Code,
|
|
|
|
&i.Uses,
|
|
|
|
&i.Total,
|
|
|
|
&i.Expiration,
|
|
|
|
)
|
|
|
|
return i, err
|
|
|
|
}
|
|
|
|
|
|
|
|
const listInvites = `-- name: ListInvites :many
|
|
|
|
SELECT id, code, uses, total, expiration FROM invites
|
2023-03-04 06:02:24 +00:00
|
|
|
ORDER BY id DESC
|
2023-03-03 05:51:53 +00:00
|
|
|
`
|
|
|
|
|
|
|
|
func (q *Queries) ListInvites(ctx context.Context) ([]Invite, error) {
|
|
|
|
rows, err := q.db.QueryContext(ctx, listInvites)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer rows.Close()
|
|
|
|
var items []Invite
|
|
|
|
for rows.Next() {
|
|
|
|
var i Invite
|
|
|
|
if err := rows.Scan(
|
|
|
|
&i.ID,
|
|
|
|
&i.Code,
|
|
|
|
&i.Uses,
|
|
|
|
&i.Total,
|
|
|
|
&i.Expiration,
|
|
|
|
); 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
|
|
|
|
}
|
2023-03-04 06:02:24 +00:00
|
|
|
|
|
|
|
const updateInvite = `-- name: UpdateInvite :exec
|
|
|
|
UPDATE invites
|
|
|
|
SET uses = ?
|
|
|
|
WHERE id = ?
|
|
|
|
`
|
|
|
|
|
|
|
|
type UpdateInviteParams struct {
|
|
|
|
Uses int64
|
|
|
|
ID int64
|
|
|
|
}
|
|
|
|
|
|
|
|
func (q *Queries) UpdateInvite(ctx context.Context, arg UpdateInviteParams) error {
|
|
|
|
_, err := q.db.ExecContext(ctx, updateInvite, arg.Uses, arg.ID)
|
|
|
|
return err
|
|
|
|
}
|