mirror of
https://github.com/steveiliop56/tinyauth.git
synced 2026-06-02 17:40:14 +00:00
114 lines
3.4 KiB
Go
114 lines
3.4 KiB
Go
// Code generated by cmd/gen/sqlc-wrapper. DO NOT EDIT.
|
|
package postgres
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
"errors"
|
|
|
|
"github.com/tinyauthapp/tinyauth/internal/repository"
|
|
)
|
|
|
|
// Store wraps *Queries and implements repository.Store.
|
|
type Store struct {
|
|
q *Queries
|
|
}
|
|
|
|
// NewStore wraps a *Queries to satisfy repository.Store.
|
|
func NewStore(q *Queries) repository.Store {
|
|
return &Store{q: q}
|
|
}
|
|
|
|
var errorMap = map[error]error{
|
|
sql.ErrNoRows: repository.ErrNotFound,
|
|
}
|
|
|
|
func mapErr(err error) error {
|
|
for from, to := range errorMap {
|
|
if errors.Is(err, from) {
|
|
return to
|
|
}
|
|
}
|
|
return err
|
|
}
|
|
|
|
func (s *Store) CreateOIDCSession(ctx context.Context, arg repository.CreateOIDCSessionParams) (repository.OidcSession, error) {
|
|
r, err := s.q.CreateOIDCSession(ctx, CreateOIDCSessionParams(arg))
|
|
if err != nil {
|
|
return repository.OidcSession{}, mapErr(err)
|
|
}
|
|
return repository.OidcSession(r), nil
|
|
}
|
|
|
|
func (s *Store) CreateSession(ctx context.Context, arg repository.CreateSessionParams) (repository.Session, error) {
|
|
r, err := s.q.CreateSession(ctx, CreateSessionParams(arg))
|
|
if err != nil {
|
|
return repository.Session{}, mapErr(err)
|
|
}
|
|
return repository.Session(r), nil
|
|
}
|
|
|
|
func (s *Store) DeleteExpiredOIDCSessions(ctx context.Context, arg repository.DeleteExpiredOIDCSessionsParams) error {
|
|
return mapErr(s.q.DeleteExpiredOIDCSessions(ctx, DeleteExpiredOIDCSessionsParams(arg)))
|
|
}
|
|
|
|
func (s *Store) DeleteExpiredSessions(ctx context.Context, expiry int64) error {
|
|
return mapErr(s.q.DeleteExpiredSessions(ctx, expiry))
|
|
}
|
|
|
|
func (s *Store) DeleteOIDCSessionBySub(ctx context.Context, sub string) error {
|
|
return mapErr(s.q.DeleteOIDCSessionBySub(ctx, sub))
|
|
}
|
|
|
|
func (s *Store) DeleteSession(ctx context.Context, uuid string) error {
|
|
return mapErr(s.q.DeleteSession(ctx, uuid))
|
|
}
|
|
|
|
func (s *Store) GetOIDCSessionByAccessTokenHash(ctx context.Context, accessTokenHash string) (repository.OidcSession, error) {
|
|
r, err := s.q.GetOIDCSessionByAccessTokenHash(ctx, accessTokenHash)
|
|
if err != nil {
|
|
return repository.OidcSession{}, mapErr(err)
|
|
}
|
|
return repository.OidcSession(r), nil
|
|
}
|
|
|
|
func (s *Store) GetOIDCSessionByRefreshTokenHash(ctx context.Context, refreshTokenHash string) (repository.OidcSession, error) {
|
|
r, err := s.q.GetOIDCSessionByRefreshTokenHash(ctx, refreshTokenHash)
|
|
if err != nil {
|
|
return repository.OidcSession{}, mapErr(err)
|
|
}
|
|
return repository.OidcSession(r), nil
|
|
}
|
|
|
|
func (s *Store) GetOIDCSessionBySub(ctx context.Context, sub string) (repository.OidcSession, error) {
|
|
r, err := s.q.GetOIDCSessionBySub(ctx, sub)
|
|
if err != nil {
|
|
return repository.OidcSession{}, mapErr(err)
|
|
}
|
|
return repository.OidcSession(r), nil
|
|
}
|
|
|
|
func (s *Store) GetSession(ctx context.Context, uuid string) (repository.Session, error) {
|
|
r, err := s.q.GetSession(ctx, uuid)
|
|
if err != nil {
|
|
return repository.Session{}, mapErr(err)
|
|
}
|
|
return repository.Session(r), nil
|
|
}
|
|
|
|
func (s *Store) UpdateOIDCSession(ctx context.Context, arg repository.UpdateOIDCSessionParams) (repository.OidcSession, error) {
|
|
r, err := s.q.UpdateOIDCSession(ctx, UpdateOIDCSessionParams(arg))
|
|
if err != nil {
|
|
return repository.OidcSession{}, mapErr(err)
|
|
}
|
|
return repository.OidcSession(r), nil
|
|
}
|
|
|
|
func (s *Store) UpdateSession(ctx context.Context, arg repository.UpdateSessionParams) (repository.Session, error) {
|
|
r, err := s.q.UpdateSession(ctx, UpdateSessionParams(arg))
|
|
if err != nil {
|
|
return repository.Session{}, mapErr(err)
|
|
}
|
|
return repository.Session(r), nil
|
|
}
|