65 lines
1.5 KiB
Go
65 lines
1.5 KiB
Go
|
package db
|
||
|
|
||
|
import (
|
||
|
"context"
|
||
|
"database/sql"
|
||
|
|
||
|
"github.com/sqlc-dev/pqtype"
|
||
|
)
|
||
|
|
||
|
const getUser = `-- name: GetUser :one
|
||
|
SELECT
|
||
|
id,
|
||
|
COALESCE(email, '') as email,
|
||
|
password,
|
||
|
username,
|
||
|
COALESCE(avatar_picture, '') as avatar_picture,
|
||
|
banned_at,
|
||
|
banned_until,
|
||
|
COALESCE(ban_reason, '') as ban_reason,
|
||
|
is_permaban,
|
||
|
is_admin,
|
||
|
is_critics,
|
||
|
is_verified,
|
||
|
social_media
|
||
|
FROM USERS
|
||
|
WHERE username = $1
|
||
|
`
|
||
|
|
||
|
type GetUserRow struct {
|
||
|
ID int32 `json:"id"`
|
||
|
Email string `json:"email"`
|
||
|
Password string `json:"-"`
|
||
|
Username string `json:"username"`
|
||
|
AvatarPicture string `json:"avatar_picture"`
|
||
|
BannedAt sql.NullTime `json:"banned_at"`
|
||
|
BannedUntil sql.NullTime `json:"banned_until"`
|
||
|
BanReason string `json:"ban_reason"`
|
||
|
IsPermaban bool `json:"is_permaban"`
|
||
|
IsAdmin bool `json:"is_admin"`
|
||
|
IsCritics bool `json:"is_critics"`
|
||
|
IsVerified bool `json:"is_verified"`
|
||
|
SocialMedia pqtype.NullRawMessage `json:"social_media"`
|
||
|
}
|
||
|
|
||
|
func (q *Queries) GetUser(ctx context.Context, username string) (GetUserRow, error) {
|
||
|
row := q.db.QueryRowContext(ctx, getUser, username)
|
||
|
var i GetUserRow
|
||
|
err := row.Scan(
|
||
|
&i.ID,
|
||
|
&i.Email,
|
||
|
&i.Password,
|
||
|
&i.Username,
|
||
|
&i.AvatarPicture,
|
||
|
&i.BannedAt,
|
||
|
&i.BannedUntil,
|
||
|
&i.BanReason,
|
||
|
&i.IsPermaban,
|
||
|
&i.IsAdmin,
|
||
|
&i.IsCritics,
|
||
|
&i.IsVerified,
|
||
|
&i.SocialMedia,
|
||
|
)
|
||
|
return i, err
|
||
|
}
|