Replace scs postgresstore with a sqlc-backed SessionStore.
Keep scs for cookies and session API while sessions DDL and queries live in the same sqlc stack as the rest of Postgres.
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
// Code generated by sqlc. DO NOT EDIT.
|
||||
// versions:
|
||||
// sqlc v1.31.1
|
||||
// source: sessions.sql
|
||||
|
||||
package sqlc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
)
|
||||
|
||||
const deleteExpiredSessions = `-- name: DeleteExpiredSessions :exec
|
||||
DELETE FROM sessions
|
||||
WHERE expiry <= now()
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteExpiredSessions(ctx context.Context) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteExpiredSessions)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteSession = `-- name: DeleteSession :exec
|
||||
DELETE FROM sessions
|
||||
WHERE token = $1
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteSession(ctx context.Context, token string) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteSession, token)
|
||||
return err
|
||||
}
|
||||
|
||||
const getSession = `-- name: GetSession :one
|
||||
SELECT data
|
||||
FROM sessions
|
||||
WHERE token = $1 AND expiry > now()
|
||||
`
|
||||
|
||||
func (q *Queries) GetSession(ctx context.Context, token string) ([]byte, error) {
|
||||
row := q.db.QueryRowContext(ctx, getSession, token)
|
||||
var data []byte
|
||||
err := row.Scan(&data)
|
||||
return data, err
|
||||
}
|
||||
|
||||
const upsertSession = `-- name: UpsertSession :exec
|
||||
INSERT INTO sessions (token, data, expiry)
|
||||
VALUES ($1, $2, $3)
|
||||
ON CONFLICT (token) DO UPDATE
|
||||
SET data = excluded.data, expiry = excluded.expiry
|
||||
`
|
||||
|
||||
type UpsertSessionParams struct {
|
||||
Token string
|
||||
Data []byte
|
||||
Expiry time.Time
|
||||
}
|
||||
|
||||
func (q *Queries) UpsertSession(ctx context.Context, arg UpsertSessionParams) error {
|
||||
_, err := q.db.ExecContext(ctx, upsertSession, arg.Token, arg.Data, arg.Expiry)
|
||||
return err
|
||||
}
|
||||
Reference in New Issue
Block a user