postgres

package
v0.0.0-...-2fba9dd Latest Latest
Warning

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

Go to latest
Published: Mar 24, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const DefaultQueryTimeout = "5000" // 5 seconds in milliseconds

DefaultQueryTimeout is the default timeout for database queries. Can be overridden via DSN parameter: ?statement_timeout=5000

View Source
const DefaultTablePrefix = ""

DefaultTablePrefix is the default prefix for table names. Empty by default for backward compatibility.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Store)

Option configures the Store.

func WithTablePrefix

func WithTablePrefix(prefix string) Option

WithTablePrefix sets the table name prefix.

type Store

type Store struct {
	// contains filtered or unexported fields
}

Store implements UserStore, TokenStore, and CredentialStore using PostgreSQL.

func New

func New(pool *pgxpool.Pool, opts ...Option) *Store

New creates a new PostgreSQL store.

func NewWithDSN

func NewWithDSN(ctx context.Context, dsn string, opts ...Option) (*Store, error)

NewWithDSN creates a new PostgreSQL store from a connection string.

func (*Store) Close

func (s *Store) Close()

Close closes the connection pool.

func (*Store) Create

func (s *Store) Create(ctx context.Context, user *entity.User) error

Create persists a new user.

func (*Store) Delete

func (s *Store) Delete(ctx context.Context, id string) error

Delete removes a user by ID.

func (*Store) GetByEmail

func (s *Store) GetByEmail(ctx context.Context, email string) (*entity.User, error)

GetByEmail retrieves a user by email address.

func (*Store) GetByID

func (s *Store) GetByID(ctx context.Context, id string) (*entity.User, error)

GetByID retrieves a user by ID.

func (*Store) GetPasswordHash

func (s *Store) GetPasswordHash(ctx context.Context, userID string) (string, error)

GetPasswordHash retrieves a password hash for a user.

func (*Store) GetRefreshToken

func (s *Store) GetRefreshToken(ctx context.Context, hash string) (*entity.RefreshToken, error)

GetRefreshToken retrieves a refresh token by its hash.

func (*Store) Ping

func (s *Store) Ping(ctx context.Context) error

Ping checks the database connection.

func (*Store) RevokeTokens

func (s *Store) RevokeTokens(ctx context.Context, hash string) error

RevokeTokens revokes a token and all tokens in its family.

func (*Store) SavePasswordHash

func (s *Store) SavePasswordHash(ctx context.Context, userID, hash string) error

SavePasswordHash stores a password hash for a user.

func (*Store) SaveRefreshToken

func (s *Store) SaveRefreshToken(ctx context.Context, token *entity.RefreshToken) error

SaveRefreshToken persists a refresh token.

func (*Store) TablePrefix

func (s *Store) TablePrefix() string

TablePrefix returns the current table prefix.

Jump to

Keyboard shortcuts

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