From ff3140a4089819489130a0908178a63eff20f708 Mon Sep 17 00:00:00 2001 From: Kyren223 Date: Sun, 3 Nov 2024 19:33:30 +0200 Subject: feat: add username and timestamp to messages --- internal/data/users.sql.go | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'internal/data/users.sql.go') diff --git a/internal/data/users.sql.go b/internal/data/users.sql.go index 1ca03ce..c92021d 100644 --- a/internal/data/users.sql.go +++ b/internal/data/users.sql.go @@ -16,30 +16,43 @@ 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 + 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.PublicKey) + 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 getUser = `-- name: GetUser :one +const getUserById = `-- name: GetUserById :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) +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 -- cgit v1.3.1