diff options
| author | Kyren223 <Kyren223@proton.me> | 2024-11-03 19:33:30 +0200 |
|---|---|---|
| committer | Kyren223 <Kyren223@proton.me> | 2024-11-03 19:33:30 +0200 |
| commit | ff3140a4089819489130a0908178a63eff20f708 (patch) | |
| tree | def568e1deca7461f814e55af7d9e09720e0b0ae /internal/data/users.sql.go | |
| parent | a637ea9c335c385985a23510a4174d837fb51faf (diff) | |
feat: add username and timestamp to messages
Diffstat (limited to 'internal/data/users.sql.go')
| -rw-r--r-- | internal/data/users.sql.go | 23 |
1 files changed, 18 insertions, 5 deletions
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 |
