Documentation ¶
Overview ¶
pgclient.go - postgres backend client
TODO: make the client delete expired stuff... but when? 1. on demand through a DeleteExpired call 2. On a ticker calling the same every N
tricky part seems to be wait for execution when at end of program, want to always wait on the single exec
easy to prove?
Index ¶
- Variables
- type PgClient
- func (c *PgClient) Count(prefix string) (int, error)
- func (c *PgClient) CountAll() (int, error)
- func (c *PgClient) CreateTable() error
- func (c *PgClient) Delete(path string) error
- func (c *PgClient) List(prefix string) ([]string, error)
- func (c *PgClient) ListDetail(prefix string) ([]backend.Detailer, error)
- func (c *PgClient) LoadDetail(path string) (backend.Detailer, error)
- func (c *PgClient) LoadRaw(path string) ([]byte, error)
- func (c *PgClient) Purge() (int, error)
- func (c *PgClient) SaveRaw(path string, raw_obj []byte) error
- func (c *PgClient) SaveRawExpiry(path string, raw_obj []byte, expiry time.Time) error
- func (c *PgClient) Schema() string
- func (c *PgClient) Shutdown() error
- func (c *PgClient) String() string
- type PgDetailer
Constants ¶
This section is empty.
Variables ¶
var DatabaseUrlEnvVar = "DATABASE_URL"
Override if using multiple databases in your process.
var DefaultTable = "obj_store"
var DeleteTestingHackKeyWord = "DELETE"
This is a really annoying hack, but it saves us the trouble of making a pgxpool mock just for this package:
var ErrNotFound = pgx.ErrNoRows
Functions ¶
This section is empty.
Types ¶
type PgClient ¶
PgClient is a BackendClient for PostgreSQL databases.
func New ¶
New returns a new PgClient using DefaultTable and a pool from DatabaseUrlEnvVar, with PurgeOnShutdown true.
func NewForPool ¶
NewForPool returns a new PgClient with the provided Pool, with defaults as in New.
func (*PgClient) Count ¶
Count returns the number of non-expired objects beginning with prefix. If none are found, zero is returned.
func (*PgClient) CountAll ¶
CountAll returns the total number of non-expired objects in the database.
func (*PgClient) CreateTable ¶
CreateTable executes the SQL returned from Schema on the current database. If the table exists an error is returned. For obvious reasons there is no corresponding DropTable function.
func (*PgClient) Delete ¶
Delete deletes the object at path.
For security reasons, if the object is already expired it will still be deleted. (It would be possible to DELETE RETURNING and thus check the expiry and return a different error if the caller deletes an expired object, but that use-case seems silly. You want it gone, we make it gone.)
If the object does not exist, the error returned will be ErrNotFound.
func (*PgClient) List ¶
List returns an array of all objects beginning with prefix. An empty array is not considered an error.
func (*PgClient) ListDetail ¶
ListDetail returns an array of all Detailers describing all objects beginning with prefix. An empty array is not considered an error.
For S3, this operation may be slow if paged results are returned!
func (*PgClient) LoadDetail ¶
LoadDetail retrieves the details of the object at path and returns its a jsobs.Detailer. If the object does not exist, the error returned will be ErrNotFound.
func (*PgClient) LoadRaw ¶
LoadRaw retrieves the object at path and returns its raw value. If the object does not exist, the error returned will be ErrNotFound.
func (*PgClient) Purge ¶
Purge deletes expired items from the database. Returns the number of rows deleted.
func (*PgClient) SaveRawExpiry ¶
SaveRawExpiry saves the raw bytes to the database for availability until expiry.
type PgDetailer ¶
type PgDetailer struct {
// contains filtered or unexported fields
}
PgDetailer implements backend.Detailer to describe an object.
func (*PgDetailer) Expires ¶
func (d *PgDetailer) Expires() bool
Expires implements backend.Detailer.
func (*PgDetailer) Expiry ¶
func (d *PgDetailer) Expiry() time.Time
Expiry implements backend.Detailer. If Expires returns false then Expiry must be ignored.
func (*PgDetailer) Modified ¶
func (d *PgDetailer) Modified() time.Time
Modified implements backend.Detailer.
func (*PgDetailer) Scan ¶
func (d *PgDetailer) Scan(row pgx.Row) error
Scan scans a database row. TODO: figure out why this works inversely from the documentation, is it a bug here, or there, or what?