// Package store holds the data models and all SQL queries. package store import ( "errors" "github.com/jackc/pgx/v5" "github.com/jackc/pgx/v5/pgconn" "github.com/jackc/pgx/v5/pgxpool" ) var ErrNotFound = errors.New("not found") var ErrConflict = errors.New("already exists") type Store struct { db *pgxpool.Pool } func New(db *pgxpool.Pool) *Store { return &Store{db: db} } // wrap maps driver errors onto the store's sentinel errors. func wrap(err error) error { if err == nil { return nil } if errors.Is(err, pgx.ErrNoRows) { return ErrNotFound } var pgErr *pgconn.PgError if errors.As(err, &pgErr) && pgErr.Code == "23505" { // unique_violation return ErrConflict } return err }