fairdm.utils.location.db#

The constraints and index a model with a location lists in its own Meta.

Module Contents#

Functions#

location_constraints

Return the check constraints that keep a record’s three location fields consistent.

geography_index

Return the index that distance lookups on a location read.

API#

location_constraints()#

Return the check constraints that keep a record’s three location fields consistent.

An uncertainty is null or zero or more, and an elevation or an uncertainty needs a point. A concrete model lists these in its own Meta.constraints, because a type that subclasses Sample without a Meta of its own would otherwise inherit them onto a table that has none of the columns.

Returns: A list of two check constraints, named from the app label and class name of the model that lists them.

geography_index(name)#

Return the index that distance lookups on a location read.

The expression has to match the one the lookups cast to, or PostgreSQL will not use it. A model that declares its own Meta.indexes lists this index there, because a Meta that sets indexes replaces an inherited list.

Args: name: The index name, 30 characters or fewer.

Returns: A GiST index on the location as a geography.