// Code generated by sqlc. DO NOT EDIT. // versions: // sqlc v1.31.1 // source: oauth.sql package sqlcdb import ( "context" "github.com/jackc/pgx/v5/pgtype" ) const countOAuthSessionsByDID = `-- name: CountOAuthSessionsByDID :one SELECT COUNT(*) FROM oauth_sessions WHERE did = $1 ` func (q *Queries) CountOAuthSessionsByDID(ctx context.Context, did string) (int64, error) { row := q.db.QueryRow(ctx, countOAuthSessionsByDID, did) var count int64 err := row.Scan(&count) return count, err } const createOAuthSession = `-- name: CreateOAuthSession :exec INSERT INTO oauth_sessions (id, did, handle, pds, email, access_token, refresh_token, token_endpoint, issuer, dpop_crv, dpop_d, dpop_x, dpop_y, access_token_expires_at, expires_at, created_at) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15, NOW()) ON CONFLICT (id) DO UPDATE SET access_token = EXCLUDED.access_token, refresh_token = EXCLUDED.refresh_token, access_token_expires_at = EXCLUDED.access_token_expires_at, expires_at = EXCLUDED.expires_at ` type CreateOAuthSessionParams struct { ID string `json:"id"` Did string `json:"did"` Handle string `json:"handle"` Pds string `json:"pds"` Email string `json:"email"` AccessToken string `json:"accessToken"` RefreshToken string `json:"refreshToken"` TokenEndpoint string `json:"tokenEndpoint"` Issuer string `json:"issuer"` DpopCrv string `json:"dpopCrv"` DpopD string `json:"dpopD"` DpopX string `json:"dpopX"` DpopY string `json:"dpopY"` AccessTokenExpiresAt pgtype.Timestamptz `json:"accessTokenExpiresAt"` ExpiresAt pgtype.Timestamptz `json:"expiresAt"` } func (q *Queries) CreateOAuthSession(ctx context.Context, arg CreateOAuthSessionParams) error { _, err := q.db.Exec(ctx, createOAuthSession, arg.ID, arg.Did, arg.Handle, arg.Pds, arg.Email, arg.AccessToken, arg.RefreshToken, arg.TokenEndpoint, arg.Issuer, arg.DpopCrv, arg.DpopD, arg.DpopX, arg.DpopY, arg.AccessTokenExpiresAt, arg.ExpiresAt, ) return err } const deleteExpiredOAuthSessions = `-- name: DeleteExpiredOAuthSessions :exec DELETE FROM oauth_sessions WHERE expires_at <= NOW() ` func (q *Queries) DeleteExpiredOAuthSessions(ctx context.Context) error { _, err := q.db.Exec(ctx, deleteExpiredOAuthSessions) return err } const deleteExpiredPendingAuthsOAuth = `-- name: DeleteExpiredPendingAuthsOAuth :exec DELETE FROM oauth_pending_auths WHERE created_at < $1 ` func (q *Queries) DeleteExpiredPendingAuthsOAuth(ctx context.Context, createdAt pgtype.Timestamptz) error { _, err := q.db.Exec(ctx, deleteExpiredPendingAuthsOAuth, createdAt) return err } const deleteOAuthSession = `-- name: DeleteOAuthSession :exec DELETE FROM oauth_sessions WHERE id = $1 ` func (q *Queries) DeleteOAuthSession(ctx context.Context, id string) error { _, err := q.db.Exec(ctx, deleteOAuthSession, id) return err } const deleteOAuthSessionsByDID = `-- name: DeleteOAuthSessionsByDID :exec DELETE FROM oauth_sessions WHERE did = $1 ` func (q *Queries) DeleteOAuthSessionsByDID(ctx context.Context, did string) error { _, err := q.db.Exec(ctx, deleteOAuthSessionsByDID, did) return err } const deletePendingAuthOAuth = `-- name: DeletePendingAuthOAuth :exec DELETE FROM oauth_pending_auths WHERE state = $1 ` func (q *Queries) DeletePendingAuthOAuth(ctx context.Context, state string) error { _, err := q.db.Exec(ctx, deletePendingAuthOAuth, state) return err } const getLatestOAuthSessionByDID = `-- name: GetLatestOAuthSessionByDID :one SELECT id, did, handle, pds, email, access_token, refresh_token, token_endpoint, issuer, dpop_crv, dpop_d, dpop_x, dpop_y, access_token_expires_at, expires_at, created_at FROM oauth_sessions WHERE did = $1 AND expires_at > NOW() ORDER BY created_at DESC LIMIT 1 ` func (q *Queries) GetLatestOAuthSessionByDID(ctx context.Context, did string) (OauthSession, error) { row := q.db.QueryRow(ctx, getLatestOAuthSessionByDID, did) var i OauthSession err := row.Scan( &i.ID, &i.Did, &i.Handle, &i.Pds, &i.Email, &i.AccessToken, &i.RefreshToken, &i.TokenEndpoint, &i.Issuer, &i.DpopCrv, &i.DpopD, &i.DpopX, &i.DpopY, &i.AccessTokenExpiresAt, &i.ExpiresAt, &i.CreatedAt, ) return i, err } const getOAuthSessionByID = `-- name: GetOAuthSessionByID :one SELECT did, handle, pds, email, access_token, refresh_token, token_endpoint, issuer, dpop_crv, dpop_d, dpop_x, dpop_y, access_token_expires_at, expires_at, created_at FROM oauth_sessions WHERE id = $1 AND expires_at > NOW() ` type GetOAuthSessionByIDRow struct { Did string `json:"did"` Handle string `json:"handle"` Pds string `json:"pds"` Email string `json:"email"` AccessToken string `json:"accessToken"` RefreshToken string `json:"refreshToken"` TokenEndpoint string `json:"tokenEndpoint"` Issuer string `json:"issuer"` DpopCrv string `json:"dpopCrv"` DpopD string `json:"dpopD"` DpopX string `json:"dpopX"` DpopY string `json:"dpopY"` AccessTokenExpiresAt pgtype.Timestamptz `json:"accessTokenExpiresAt"` ExpiresAt pgtype.Timestamptz `json:"expiresAt"` CreatedAt pgtype.Timestamptz `json:"createdAt"` } func (q *Queries) GetOAuthSessionByID(ctx context.Context, id string) (GetOAuthSessionByIDRow, error) { row := q.db.QueryRow(ctx, getOAuthSessionByID, id) var i GetOAuthSessionByIDRow err := row.Scan( &i.Did, &i.Handle, &i.Pds, &i.Email, &i.AccessToken, &i.RefreshToken, &i.TokenEndpoint, &i.Issuer, &i.DpopCrv, &i.DpopD, &i.DpopX, &i.DpopY, &i.AccessTokenExpiresAt, &i.ExpiresAt, &i.CreatedAt, ) return i, err } const getPendingAuthOAuth = `-- name: GetPendingAuthOAuth :one SELECT did, handle, pds, issuer, token_endpoint, pkce_verifier, dpop_crv, dpop_d, dpop_x, dpop_y, dpop_nonce, created_at FROM oauth_pending_auths WHERE state = $1 ` type GetPendingAuthOAuthRow struct { Did string `json:"did"` Handle string `json:"handle"` Pds string `json:"pds"` Issuer string `json:"issuer"` TokenEndpoint string `json:"tokenEndpoint"` PkceVerifier string `json:"pkceVerifier"` DpopCrv string `json:"dpopCrv"` DpopD string `json:"dpopD"` DpopX string `json:"dpopX"` DpopY string `json:"dpopY"` DpopNonce string `json:"dpopNonce"` CreatedAt pgtype.Timestamptz `json:"createdAt"` } func (q *Queries) GetPendingAuthOAuth(ctx context.Context, state string) (GetPendingAuthOAuthRow, error) { row := q.db.QueryRow(ctx, getPendingAuthOAuth, state) var i GetPendingAuthOAuthRow err := row.Scan( &i.Did, &i.Handle, &i.Pds, &i.Issuer, &i.TokenEndpoint, &i.PkceVerifier, &i.DpopCrv, &i.DpopD, &i.DpopX, &i.DpopY, &i.DpopNonce, &i.CreatedAt, ) return i, err } const savePendingAuthOAuth = `-- name: SavePendingAuthOAuth :exec INSERT INTO oauth_pending_auths (state, did, handle, pds, issuer, token_endpoint, pkce_verifier, dpop_crv, dpop_d, dpop_x, dpop_y, dpop_nonce, created_at) VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13) ON CONFLICT (state) DO UPDATE SET did = EXCLUDED.did, handle = EXCLUDED.handle, pds = EXCLUDED.pds, issuer = EXCLUDED.issuer, token_endpoint = EXCLUDED.token_endpoint, pkce_verifier = EXCLUDED.pkce_verifier, dpop_crv = EXCLUDED.dpop_crv, dpop_d = EXCLUDED.dpop_d, dpop_x = EXCLUDED.dpop_x, dpop_y = EXCLUDED.dpop_y, dpop_nonce = EXCLUDED.dpop_nonce, created_at = EXCLUDED.created_at ` type SavePendingAuthOAuthParams struct { State string `json:"state"` Did string `json:"did"` Handle string `json:"handle"` Pds string `json:"pds"` Issuer string `json:"issuer"` TokenEndpoint string `json:"tokenEndpoint"` PkceVerifier string `json:"pkceVerifier"` DpopCrv string `json:"dpopCrv"` DpopD string `json:"dpopD"` DpopX string `json:"dpopX"` DpopY string `json:"dpopY"` DpopNonce string `json:"dpopNonce"` CreatedAt pgtype.Timestamptz `json:"createdAt"` } func (q *Queries) SavePendingAuthOAuth(ctx context.Context, arg SavePendingAuthOAuthParams) error { _, err := q.db.Exec(ctx, savePendingAuthOAuth, arg.State, arg.Did, arg.Handle, arg.Pds, arg.Issuer, arg.TokenEndpoint, arg.PkceVerifier, arg.DpopCrv, arg.DpopD, arg.DpopX, arg.DpopY, arg.DpopNonce, arg.CreatedAt, ) return err } const updateOAuthSessionTokens = `-- name: UpdateOAuthSessionTokens :exec UPDATE oauth_sessions SET access_token = $2, refresh_token = $3, access_token_expires_at = $4 WHERE id = $1 ` type UpdateOAuthSessionTokensParams struct { ID string `json:"id"` AccessToken string `json:"accessToken"` RefreshToken string `json:"refreshToken"` AccessTokenExpiresAt pgtype.Timestamptz `json:"accessTokenExpiresAt"` } func (q *Queries) UpdateOAuthSessionTokens(ctx context.Context, arg UpdateOAuthSessionTokensParams) error { _, err := q.db.Exec(ctx, updateOAuthSessionTokens, arg.ID, arg.AccessToken, arg.RefreshToken, arg.AccessTokenExpiresAt, ) return err }