mirror of
https://github.com/Kyren223/eko.git
synced 2025-09-05 21:18:14 +00:00
208 lines
4.4 KiB
Go
208 lines
4.4 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.29.0
|
|
// source: users.sql
|
|
|
|
package data
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"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, description, is_public_dm, is_deleted
|
|
`
|
|
|
|
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,
|
|
&i.Description,
|
|
&i.IsPublicDM,
|
|
&i.IsDeleted,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const deleteUser = `-- name: DeleteUser :exec
|
|
UPDATE users SET
|
|
is_deleted = true
|
|
WHERE id = ? AND is_deleted = false
|
|
`
|
|
|
|
func (q *Queries) DeleteUser(ctx context.Context, id snowflake.ID) error {
|
|
_, err := q.db.ExecContext(ctx, deleteUser, id)
|
|
return err
|
|
}
|
|
|
|
const getUserById = `-- name: GetUserById :one
|
|
SELECT id, name, public_key, description, is_public_dm, is_deleted FROM users
|
|
WHERE id = ? AND is_deleted = false
|
|
`
|
|
|
|
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,
|
|
&i.Description,
|
|
&i.IsPublicDM,
|
|
&i.IsDeleted,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getUserByPublicKey = `-- name: GetUserByPublicKey :one
|
|
SELECT id, name, public_key, description, is_public_dm, is_deleted 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,
|
|
&i.Description,
|
|
&i.IsPublicDM,
|
|
&i.IsDeleted,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getUserData = `-- name: GetUserData :one
|
|
SELECT data FROM user_data
|
|
WHERE user_id = ?
|
|
`
|
|
|
|
func (q *Queries) GetUserData(ctx context.Context, userID snowflake.ID) (string, error) {
|
|
row := q.db.QueryRowContext(ctx, getUserData, userID)
|
|
var data string
|
|
err := row.Scan(&data)
|
|
return data, err
|
|
}
|
|
|
|
const getUsersByIds = `-- name: GetUsersByIds :many
|
|
SELECT id, name, public_key, description, is_public_dm, is_deleted FROM users
|
|
WHERE id IN (/*SLICE:ids*/?)
|
|
`
|
|
|
|
func (q *Queries) GetUsersByIds(ctx context.Context, ids []snowflake.ID) ([]User, error) {
|
|
query := getUsersByIds
|
|
var queryParams []interface{}
|
|
if len(ids) > 0 {
|
|
for _, v := range ids {
|
|
queryParams = append(queryParams, v)
|
|
}
|
|
query = strings.Replace(query, "/*SLICE:ids*/?", strings.Repeat(",?", len(ids))[1:], 1)
|
|
} else {
|
|
query = strings.Replace(query, "/*SLICE:ids*/?", "NULL", 1)
|
|
}
|
|
rows, err := q.db.QueryContext(ctx, query, queryParams...)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
var items []User
|
|
for rows.Next() {
|
|
var i User
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Description,
|
|
&i.IsPublicDM,
|
|
&i.IsDeleted,
|
|
); 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 setUserData = `-- name: SetUserData :one
|
|
INSERT INTO user_data (
|
|
user_id, data
|
|
) VALUES (
|
|
?1, ?2
|
|
)
|
|
ON CONFLICT DO
|
|
UPDATE SET
|
|
user_id = EXCLUDED.user_id, data = EXCLUDED.data
|
|
WHERE user_id = EXCLUDED.user_id
|
|
RETURNING user_id, data
|
|
`
|
|
|
|
type SetUserDataParams struct {
|
|
UserID snowflake.ID
|
|
Data string
|
|
}
|
|
|
|
func (q *Queries) SetUserData(ctx context.Context, arg SetUserDataParams) (UserData, error) {
|
|
row := q.db.QueryRowContext(ctx, setUserData, arg.UserID, arg.Data)
|
|
var i UserData
|
|
err := row.Scan(&i.UserID, &i.Data)
|
|
return i, err
|
|
}
|
|
|
|
const updateUser = `-- name: UpdateUser :one
|
|
UPDATE users SET
|
|
name = ?, description = ?, is_public_dm = ?
|
|
WHERE id = ?
|
|
RETURNING id, name, public_key, description, is_public_dm, is_deleted
|
|
`
|
|
|
|
type UpdateUserParams struct {
|
|
Name string
|
|
Description string
|
|
IsPublicDM bool
|
|
ID snowflake.ID
|
|
}
|
|
|
|
func (q *Queries) UpdateUser(ctx context.Context, arg UpdateUserParams) (User, error) {
|
|
row := q.db.QueryRowContext(ctx, updateUser,
|
|
arg.Name,
|
|
arg.Description,
|
|
arg.IsPublicDM,
|
|
arg.ID,
|
|
)
|
|
var i User
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.Name,
|
|
&i.PublicKey,
|
|
&i.Description,
|
|
&i.IsPublicDM,
|
|
&i.IsDeleted,
|
|
)
|
|
return i, err
|
|
}
|