summaryrefslogtreecommitdiff
path: root/internal/data/users.sql.go
blob: c92021da954431b4ae00639d1fb886faa09d81a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Code generated by sqlc. DO NOT EDIT.
// versions:
//   sqlc v1.27.0
// source: users.sql

package data

import (
	"context"

	"crypto/ed25519"
	"github.com/kyren223/eko/pkg/snowflake"
)

const createUser = `-- name: CreateUser :one
INSERT INTO users (
  id, name, public_key
) VALUES (
  ?, ?, ?
)
RETURNING id, name, public_key
`

type CreateUserParams struct {
	ID        snowflake.ID
	Name      string
	PublicKey ed25519.PublicKey
}

func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
	row := q.db.QueryRowContext(ctx, createUser, arg.ID, arg.Name, arg.PublicKey)
	var i User
	err := row.Scan(&i.ID, &i.Name, &i.PublicKey)
	return i, err
}

const getUserById = `-- name: GetUserById :one
SELECT id, name, public_key FROM users
WHERE id = ?
`

func (q *Queries) GetUserById(ctx context.Context, id snowflake.ID) (User, error) {
	row := q.db.QueryRowContext(ctx, getUserById, id)
	var i User
	err := row.Scan(&i.ID, &i.Name, &i.PublicKey)
	return i, err
}

const getUserByPublicKey = `-- name: GetUserByPublicKey :one
SELECT id, name, public_key FROM users
WHERE public_key = ?
`

func (q *Queries) GetUserByPublicKey(ctx context.Context, publicKey ed25519.PublicKey) (User, error) {
	row := q.db.QueryRowContext(ctx, getUserByPublicKey, publicKey)
	var i User
	err := row.Scan(&i.ID, &i.Name, &i.PublicKey)
	return i, err
}

const setUserName = `-- name: SetUserName :one
UPDATE users SET
  name = ?
WHERE id = ?
RETURNING id, name, public_key
`

type SetUserNameParams struct {
	Name string
	ID   snowflake.ID
}

func (q *Queries) SetUserName(ctx context.Context, arg SetUserNameParams) (User, error) {
	row := q.db.QueryRowContext(ctx, setUserName, arg.Name, arg.ID)
	var i User
	err := row.Scan(&i.ID, &i.Name, &i.PublicKey)
	return i, err
}

const setUserPublicKey = `-- name: SetUserPublicKey :one
UPDATE users SET
  public_key = ?
WHERE id = ?
RETURNING id, name, public_key
`

type SetUserPublicKeyParams struct {
	PublicKey ed25519.PublicKey
	ID        snowflake.ID
}

func (q *Queries) SetUserPublicKey(ctx context.Context, arg SetUserPublicKeyParams) (User, error) {
	row := q.db.QueryRowContext(ctx, setUserPublicKey, arg.PublicKey, arg.ID)
	var i User
	err := row.Scan(&i.ID, &i.Name, &i.PublicKey)
	return i, err
}