3bd237d562
Фаза 2, Task 1: добавлена таблица sessions и nullable password_hash у users, sqlc-запросы и *Store-обёртки (CreateUser, GetUserByEmail, CreateProjectForUser, GetProjectOwned, GetUserProject, CreateSession, GetSessionUser, DeleteSession, RegisterUser в транзакции), интеграционные тесты на testcontainers. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BwxdSt4reTm7Dj1oxRvpP3
55 lines
1.3 KiB
Go
55 lines
1.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: sessions.sql
|
|
|
|
package db
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/jackc/pgx/v5/pgtype"
|
|
)
|
|
|
|
const createSession = `-- name: CreateSession :exec
|
|
INSERT INTO sessions (id, user_id, token_hash, expires_at) VALUES ($1, $2, $3, $4)
|
|
`
|
|
|
|
type CreateSessionParams struct {
|
|
ID uuid.UUID `json:"id"`
|
|
UserID uuid.UUID `json:"user_id"`
|
|
TokenHash string `json:"token_hash"`
|
|
ExpiresAt pgtype.Timestamptz `json:"expires_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) error {
|
|
_, err := q.db.Exec(ctx, createSession,
|
|
arg.ID,
|
|
arg.UserID,
|
|
arg.TokenHash,
|
|
arg.ExpiresAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const deleteSession = `-- name: DeleteSession :exec
|
|
DELETE FROM sessions WHERE token_hash = $1
|
|
`
|
|
|
|
func (q *Queries) DeleteSession(ctx context.Context, tokenHash string) error {
|
|
_, err := q.db.Exec(ctx, deleteSession, tokenHash)
|
|
return err
|
|
}
|
|
|
|
const getSessionUser = `-- name: GetSessionUser :one
|
|
SELECT user_id FROM sessions WHERE token_hash = $1 AND expires_at > now()
|
|
`
|
|
|
|
func (q *Queries) GetSessionUser(ctx context.Context, tokenHash string) (uuid.UUID, error) {
|
|
row := q.db.QueryRow(ctx, getSessionUser, tokenHash)
|
|
var user_id uuid.UUID
|
|
err := row.Scan(&user_id)
|
|
return user_id, err
|
|
}
|