Files
eko/internal/data/users.sql.go
2024-10-27 17:04:08 +02:00

85 lines
1.8 KiB
Go

// 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 (
?, 'User' || abs(random()) % 1000000, ?
)
RETURNING id, name, public_key
`
type CreateUserParams struct {
ID snowflake.ID
PublicKey ed25519.PublicKey
}
func (q *Queries) CreateUser(ctx context.Context, arg CreateUserParams) (User, error) {
row := q.db.QueryRowContext(ctx, createUser, arg.ID, arg.PublicKey)
var i User
err := row.Scan(&i.ID, &i.Name, &i.PublicKey)
return i, err
}
const getUser = `-- name: GetUser :one
SELECT id, name, public_key FROM users
WHERE id = ?
`
func (q *Queries) GetUser(ctx context.Context, id snowflake.ID) (User, error) {
row := q.db.QueryRowContext(ctx, getUser, id)
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
}