golang-template/internal/database/sqlc/sessions.sql.go
Leo 43219268e9 feat: Add Sliding expiration for user_sessions
The user_session is valid for 24 hours, but the session will be bumped if it has been over an hour since the last update. An hour was set as a deadline, so that we would not update the user_session rows too often.
2026-08-17 23:47:11 +03:00

85 lines
2 KiB
Go

// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.29.0
// source: sessions.sql
package sqlc
import (
"context"
)
const deleteSessionById = `-- name: DeleteSessionById :exec
DELETE FROM user_session WHERE id = $1
`
func (q *Queries) DeleteSessionById(ctx context.Context, id string) error {
_, err := q.db.ExecContext(ctx, deleteSessionById, id)
return err
}
const insertSession = `-- name: InsertSession :one
INSERT INTO user_session (id, secret_hash, user_id)
VALUES ($1, $2, $3)
RETURNING id, secret_hash, user_id, last_verified_at, created_at, updated_at
`
type InsertSessionParams struct {
ID string
SecretHash []byte
UserID string
}
func (q *Queries) InsertSession(ctx context.Context, arg InsertSessionParams) (UserSession, error) {
row := q.db.QueryRowContext(ctx, insertSession, arg.ID, arg.SecretHash, arg.UserID)
var i UserSession
err := row.Scan(
&i.ID,
&i.SecretHash,
&i.UserID,
&i.LastVerifiedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const selectSessionById = `-- name: SelectSessionById :one
SELECT id, secret_hash, user_id, last_verified_at, created_at, updated_at
FROM user_session
WHERE id = $1
`
func (q *Queries) SelectSessionById(ctx context.Context, id string) (UserSession, error) {
row := q.db.QueryRowContext(ctx, selectSessionById, id)
var i UserSession
err := row.Scan(
&i.ID,
&i.SecretHash,
&i.UserID,
&i.LastVerifiedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}
const updateSessionVerifiedAt = `-- name: UpdateSessionVerifiedAt :one
UPDATE user_session SET last_verified_at = NOW()
WHERE id = $1
RETURNING id, secret_hash, user_id, last_verified_at, created_at, updated_at
`
func (q *Queries) UpdateSessionVerifiedAt(ctx context.Context, id string) (UserSession, error) {
row := q.db.QueryRowContext(ctx, updateSessionVerifiedAt, id)
var i UserSession
err := row.Scan(
&i.ID,
&i.SecretHash,
&i.UserID,
&i.LastVerifiedAt,
&i.CreatedAt,
&i.UpdatedAt,
)
return i, err
}