feat(dbq): generate session queries

Adds Insert/Get/Touch/Delete helpers over the sessions table.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-04-20 20:15:45 -04:00
parent 1741b57a0b
commit c8a4a930ea
3 changed files with 108 additions and 0 deletions
+9
View File
@@ -29,6 +29,15 @@ type Artist struct {
UpdatedAt pgtype.Timestamptz
}
type Session struct {
ID pgtype.UUID
UserID pgtype.UUID
TokenHash []byte
UserAgent string
CreatedAt pgtype.Timestamptz
LastSeenAt pgtype.Timestamptz
}
type Track struct {
ID pgtype.UUID
Title string
+83
View File
@@ -0,0 +1,83 @@
// Code generated by sqlc. DO NOT EDIT.
// versions:
// sqlc v1.27.0
// source: sessions.sql
package dbq
import (
"context"
"github.com/jackc/pgx/v5/pgtype"
)
const deleteSession = `-- name: DeleteSession :exec
DELETE FROM sessions WHERE id = $1
`
func (q *Queries) DeleteSession(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, deleteSession, id)
return err
}
const deleteSessionByTokenHash = `-- name: DeleteSessionByTokenHash :exec
DELETE FROM sessions WHERE token_hash = $1
`
func (q *Queries) DeleteSessionByTokenHash(ctx context.Context, tokenHash []byte) error {
_, err := q.db.Exec(ctx, deleteSessionByTokenHash, tokenHash)
return err
}
const getSessionByTokenHash = `-- name: GetSessionByTokenHash :one
SELECT id, user_id, token_hash, user_agent, created_at, last_seen_at FROM sessions WHERE token_hash = $1
`
func (q *Queries) GetSessionByTokenHash(ctx context.Context, tokenHash []byte) (Session, error) {
row := q.db.QueryRow(ctx, getSessionByTokenHash, tokenHash)
var i Session
err := row.Scan(
&i.ID,
&i.UserID,
&i.TokenHash,
&i.UserAgent,
&i.CreatedAt,
&i.LastSeenAt,
)
return i, err
}
const insertSession = `-- name: InsertSession :one
INSERT INTO sessions (user_id, token_hash, user_agent)
VALUES ($1, $2, $3)
RETURNING id, user_id, token_hash, user_agent, created_at, last_seen_at
`
type InsertSessionParams struct {
UserID pgtype.UUID
TokenHash []byte
UserAgent string
}
func (q *Queries) InsertSession(ctx context.Context, arg InsertSessionParams) (Session, error) {
row := q.db.QueryRow(ctx, insertSession, arg.UserID, arg.TokenHash, arg.UserAgent)
var i Session
err := row.Scan(
&i.ID,
&i.UserID,
&i.TokenHash,
&i.UserAgent,
&i.CreatedAt,
&i.LastSeenAt,
)
return i, err
}
const touchSessionLastSeen = `-- name: TouchSessionLastSeen :exec
UPDATE sessions SET last_seen_at = now() WHERE id = $1
`
func (q *Queries) TouchSessionLastSeen(ctx context.Context, id pgtype.UUID) error {
_, err := q.db.Exec(ctx, touchSessionLastSeen, id)
return err
}
+16
View File
@@ -0,0 +1,16 @@
-- name: InsertSession :one
INSERT INTO sessions (user_id, token_hash, user_agent)
VALUES ($1, $2, $3)
RETURNING *;
-- name: GetSessionByTokenHash :one
SELECT * FROM sessions WHERE token_hash = $1;
-- name: TouchSessionLastSeen :exec
UPDATE sessions SET last_seen_at = now() WHERE id = $1;
-- name: DeleteSession :exec
DELETE FROM sessions WHERE id = $1;
-- name: DeleteSessionByTokenHash :exec
DELETE FROM sessions WHERE token_hash = $1;