add sessions
This commit is contained in:
@@ -176,6 +176,22 @@ func (q *Queries) CreateRedirectURI(ctx context.Context, arg CreateRedirectURIPa
|
||||
return err
|
||||
}
|
||||
|
||||
const createSession = `-- name: CreateSession :exec
|
||||
INSERT INTO sessions (id, user_id, expires_at)
|
||||
VALUES (?, ?, ?)
|
||||
`
|
||||
|
||||
type CreateSessionParams struct {
|
||||
ID string
|
||||
UserID string
|
||||
ExpiresAt time.Time
|
||||
}
|
||||
|
||||
func (q *Queries) CreateSession(ctx context.Context, arg CreateSessionParams) error {
|
||||
_, err := q.db.ExecContext(ctx, createSession, arg.ID, arg.UserID, arg.ExpiresAt)
|
||||
return err
|
||||
}
|
||||
|
||||
const createToken = `-- name: CreateToken :exec
|
||||
INSERT INTO tokens (token_type, token_value, user_id, client_id, scope, expires_at)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
@@ -291,6 +307,16 @@ func (q *Queries) DeleteOldAuthCodes(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteOldSessions = `-- name: DeleteOldSessions :exec
|
||||
DELETE FROM sessions
|
||||
WHERE expires_at < CURRENT_TIMESTAMP
|
||||
`
|
||||
|
||||
func (q *Queries) DeleteOldSessions(ctx context.Context) error {
|
||||
_, err := q.db.ExecContext(ctx, deleteOldSessions)
|
||||
return err
|
||||
}
|
||||
|
||||
const deleteOldTokens = `-- name: DeleteOldTokens :exec
|
||||
DELETE FROM tokens
|
||||
WHERE expires_at < CURRENT_TIMESTAMP
|
||||
@@ -434,6 +460,24 @@ func (q *Queries) GetOIDCClientByID(ctx context.Context, id string) (Client, err
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getSessionByID = `-- name: GetSessionByID :one
|
||||
SELECT id, user_id, created_at, expires_at
|
||||
FROM sessions
|
||||
WHERE id = ?
|
||||
`
|
||||
|
||||
func (q *Queries) GetSessionByID(ctx context.Context, id string) (Session, error) {
|
||||
row := q.db.QueryRowContext(ctx, getSessionByID, id)
|
||||
var i Session
|
||||
err := row.Scan(
|
||||
&i.ID,
|
||||
&i.UserID,
|
||||
&i.CreatedAt,
|
||||
&i.ExpiresAt,
|
||||
)
|
||||
return i, err
|
||||
}
|
||||
|
||||
const getSvgCount = `-- name: GetSvgCount :one
|
||||
SELECT COUNT(*) as count FROM svg_icon
|
||||
`
|
||||
@@ -554,7 +598,7 @@ FROM clients
|
||||
WHERE owner = ?
|
||||
`
|
||||
|
||||
// -------- go-oidc
|
||||
// -------- go-oidc ----------
|
||||
func (q *Queries) GetUserClients(ctx context.Context, owner string) ([]Client, error) {
|
||||
rows, err := q.db.QueryContext(ctx, getUserClients, owner)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user