invitea/database/invites.sql.go

135 lines
2.5 KiB
Go
Raw Normal View History

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.17.2
// source: invites.sql
package database
import (
"context"
"database/sql"
)
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
Total sql.NullInt64
Expiration sql.NullInt64
}
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
WHERE code = ? LIMIT 1
`
func (q *Queries) GetInvite(ctx context.Context, code string) (Invite, error) {
row := q.db.QueryRowContext(ctx, getInvite, code)
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
ORDER BY id DESC
`
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
}
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
}