gaffer_postgres (gaffer v0.7.0)

View Source

Pure SQL query builder and serializer for Postgres drivers.

Summary

Types

A list of queries to be run in one transaction.

A parameterized SQL query.

Functions

Query that takes a transaction-scoped advisory lock on the migrations table.

Query that fetches applied versions and their stored SQL checksums.

Query that fetches the currently applied migration versions.

SHA-256 over the concatenated SQL strings of a query list.

Queries to create the applied migrations table if it does not exist.

Query to atomically claim available jobs for execution.

Query to delete a job by ID.

Query to fetch a job by ID.

Query to list jobs matching the given filters.

Query to delete jobs older than per-state cutoffs for a queue.

Returns upsert queries for a single encoded job.

Queries to roll back a migration and remove its applied record.

Queries to apply a migration and record it as applied.

Sorted list of all schema migrations as {Version, Up, Down} tuples.

Query to delete a queue by name.

Query to check whether a queue name exists.

Query to register a queue name. No-op if already registered.

Query to list all registered queue names.

Types

queries()

-type queries() :: [query()].

A list of queries to be run in one transaction.

query()

-type query() :: {QueryString :: iodata(), Values :: list()}.

A parameterized SQL query.

The QueryString will contain $1 etc. which each will correspond to the nth value in Values.

Functions

advisory_lock()

-spec advisory_lock() -> queries().

Query that takes a transaction-scoped advisory lock on the migrations table.

The lock is released automatically when the surrounding transaction commits or rolls back. Concurrent boots running this query inside their own migrate transaction will serialise on it.

applied_checksums()

-spec applied_checksums() -> queries().

Query that fetches applied versions and their stored SQL checksums.

applied_versions()

-spec applied_versions() -> queries().

Query that fetches the currently applied migration versions.

checksum(Queries)

-spec checksum(queries()) -> binary().

SHA-256 over the concatenated SQL strings of a query list.

Used to detect post-deploy edits to a migration's up-queries: the value computed at apply time is stored in gaffer_schema_migrations.sql_checksum and compared against the recomputed value on every subsequent boot.

ensure_migrations_table()

-spec ensure_migrations_table() -> queries().

Queries to create the applied migrations table if it does not exist.

job_claim/2

-spec job_claim(map(), map()) -> queries().

Query to atomically claim available jobs for execution.

job_delete(ID)

-spec job_delete(term()) -> queries().

Query to delete a job by ID.

job_get(ID)

-spec job_get(term()) -> queries().

Query to fetch a job by ID.

job_list/1

-spec job_list(map()) -> queries().

Query to list jobs matching the given filters.

job_prune(Queue, Opts)

-spec job_prune(gaffer:queue(), map()) -> queries().

Query to delete jobs older than per-state cutoffs for a queue.

job_write(Encoded)

-spec job_write(map()) -> queries().

Returns upsert queries for a single encoded job.

migrate_down/1

-spec migrate_down({pos_integer(), _, queries()}) -> queries().

Queries to roll back a migration and remove its applied record.

migrate_up/1

-spec migrate_up({pos_integer(), queries(), _}) -> queries().

Queries to apply a migration and record it as applied.

migrations(Opts)

-spec migrations(Opts :: map()) -> [{Version :: pos_integer(), Up :: queries(), Down :: queries()}].

Sorted list of all schema migrations as {Version, Up, Down} tuples.

queue_delete(Name)

-spec queue_delete(gaffer:queue()) -> queries().

Query to delete a queue by name.

queue_exists(Name)

-spec queue_exists(gaffer:queue()) -> queries().

Query to check whether a queue name exists.

queue_insert(Name)

-spec queue_insert(gaffer:queue()) -> queries().

Query to register a queue name. No-op if already registered.

queue_list()

-spec queue_list() -> queries().

Query to list all registered queue names.