sql

package
v0.6.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 15, 2025 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// CreateRefreshTokensTableQuery is the SQL query to create the refresh_tokens table
	CreateRefreshTokensTableQuery = `CREATE TABLE IF NOT EXISTS refresh_tokens (jti TEXT PRIMARY KEY)`

	// InsertRefreshTokenQuery is the SQL query to insert a new refresh token
	InsertRefreshTokenQuery = `INSERT OR IGNORE INTO refresh_tokens (jti) VALUES (?)`

	// DeleteRefreshTokenQuery is the SQL query to delete a refresh token
	DeleteRefreshTokenQuery = `DELETE FROM refresh_tokens WHERE jti = ?`

	// CheckRefreshTokenQuery is the SQL query to check if a refresh token exists
	CheckRefreshTokenQuery = `SELECT COUNT(1) FROM refresh_tokens WHERE jti = ?`

	// CreateAccessTokensTableQuery is the SQL query to create the access_tokens table
	CreateAccessTokensTableQuery = `CREATE TABLE IF NOT EXISTS access_tokens (jti TEXT PRIMARY KEY)`

	// InsertAccessTokenQuery is the SQL query to insert a new access token
	InsertAccessTokenQuery = `INSERT OR IGNORE INTO access_tokens (jti) VALUES (?)`

	// DeleteAccessTokenQuery is the SQL query to delete an access token
	DeleteAccessTokenQuery = `DELETE FROM access_tokens WHERE jti = ?`

	// CheckAccessTokenQuery is the SQL query to check if an access token exists
	CheckAccessTokenQuery = `SELECT COUNT(1) FROM access_tokens WHERE jti = ?`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DefaultService

type DefaultService struct {
	godatabasessql.Handler
	// contains filtered or unexported fields
}

DefaultService is the default implementation of the Service interface

func NewDefaultService

func NewDefaultService(
	handler godatabasessql.Handler,
	consumer gojwtrabbitmqconsumer.Consumer,
	logger *slog.Logger,
) (*DefaultService, error)

NewDefaultService creates a new DefaultService

Parameters:

  • handler: the SQL connection handler
  • consumer: the RabbitMQ consumer
  • logger: the logger (optional, can be nil)

Returns:

  • *DefaultService: the DefaultService instance
  • error: an error if the data source or driver name is empty

func (*DefaultService) Connect

func (d *DefaultService) Connect() error

Connect opens the database connection

Returns:

  • error: an error if the connection could not be opened

func (*DefaultService) DB

func (d *DefaultService) DB() (*sql.DB, error)

DB is a helper function to get the database connection

Returns:

  • *sql.DB: the database connection

func (*DefaultService) Disconnect

func (d *DefaultService) Disconnect() error

Disconnect closes the database connection

Returns:

  • error: an error if the connection could not be closed

func (*DefaultService) IsAccessTokenValid added in v0.6.3

func (d *DefaultService) IsAccessTokenValid(jti string) (bool, error)

IsAccessTokenValid checks if the given access token JTI exists in the database

Parameters:

  • jti: the access token JTI to validate

Returns:

  • bool: true if the access token JTI exists, false otherwise
  • error: an error if the validation could not be performed

func (*DefaultService) IsRefreshTokenValid added in v0.6.3

func (d *DefaultService) IsRefreshTokenValid(jti string) (bool, error)

IsRefreshTokenValid checks if the given refresh token JTI exists in the database

Parameters:

  • jti: the refresh token JTI to validate

Returns:

  • bool: true if the refresh token JTI exists, false otherwise
  • error: an error if the validation could not be performed

func (*DefaultService) Start

func (d *DefaultService) Start(ctx context.Context) error

Start starts the service to listen for messages and update the SQLite database

Parameters:

  • ctx: the context for managing cancellation and timeouts

Returns:

  • error: an error if the service could not be started

func (*DefaultService) ValidateClaims

func (d *DefaultService) ValidateClaims(
	claims map[string]interface{},
	token gojwttoken.Token,
) (bool, error)

ValidateClaims validates the JWT claims

Parameters:

  • claims: the JWT claims to validate
  • token: the token type

Returns:

  • bool: true if the claims are valid, false otherwise
  • error: an error if the validation could not be performed

type Service

type Service interface {
	gojwtclaims.Validator
	godatabasessql.Handler
	Start(ctx context.Context)
	IsRefreshTokenValid(jti string) (bool, error)
	IsAccessTokenValid(jti string) (bool, error)
}

Service is the interface for the SQLite service for JWT IDs

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL