hydra.relational module

An interpretation of Codd’s Relational Model, as described in ‘A Relational Model of Data for Large Shared Data Banks’ (1970). Types (‘domains’) and values are parameterized so as to allow for application-specific implementations. No special support is provided for ‘nonsimple’ domains; i.e. relations are assumed to be normalized.

class hydra.relational.ColumnName(value: T)

Bases: Node[str]

A name for a domain which serves to identify the role played by that domain in the given relation; a ‘role name’ in Codd.

TYPE_ = Name(value='hydra.relational.ColumnName')
class hydra.relational.ColumnSchema(name: Annotated[ColumnName, 'A unique name for the column'], domain: Annotated[T, 'The domain (type) of the column'])

Bases: Generic[T]

An abstract specification of the domain represented by a column in a relation; a role.

class Builder(_name: 'ColumnName' = None, _domain: 'T' = None)

Bases: Generic[T]

build()
domain(domain)
name(name)
DOMAIN = Name(value='domain')
NAME = Name(value='name')
TYPE_ = Name(value='hydra.relational.ColumnSchema')
static builder()
domain: Annotated[T, 'The domain (type) of the column']
name: Annotated[ColumnName, 'A unique name for the column']
with_domain(domain)
with_name(name)
class hydra.relational.ForeignKey(foreign_relation: Annotated[RelationName, 'The name of the target relation'], keys: Annotated[Mapping[ColumnName, ColumnName], 'The mapping of source column names to target column names. The target column names must together make up the primary key of the target relation.'])

Bases: object

A mapping from certain columns of a source relation to primary key columns of a target relation.

class Builder(_foreign_relation: 'RelationName' = None, _keys: 'Mapping[ColumnName, ColumnName]' = None)

Bases: object

build()
foreign_relation(foreign_relation)
keys(keys)
FOREIGN_RELATION = Name(value='foreignRelation')
KEYS = Name(value='keys')
TYPE_ = Name(value='hydra.relational.ForeignKey')
static builder()
foreign_relation: Annotated[RelationName, 'The name of the target relation']
keys: Annotated[Mapping[ColumnName, ColumnName], 'The mapping of source column names to target column names. The target column names must together make up the primary key of the target relation.']
with_foreign_relation(foreign_relation)
with_keys(keys)
class hydra.relational.PrimaryKey(value: T)

Bases: Node[Sequence[ColumnName]]

A primary key of a relation, specified either as a single column, or as a list of columns.

TYPE_ = Name(value='hydra.relational.PrimaryKey')
class hydra.relational.Relation(value: T)

Bases: Node[Sequence[Row[V]]], Generic[V]

A set of distinct n-tuples; a table.

TYPE_ = Name(value='hydra.relational.Relation')
class hydra.relational.RelationName(value: T)

Bases: Node[str]

A unique relation (table) name.

TYPE_ = Name(value='hydra.relational.RelationName')
class hydra.relational.RelationSchema(name: Annotated[RelationName, 'A unique name for the relation'], columns: Annotated[Sequence[ColumnSchema[T]], 'A list of column specifications'], primary_keys: Annotated[Sequence[PrimaryKey], 'Any number of primary keys for the relation, each of which must be valid for this relation'], foreign_keys: Annotated[Sequence[ForeignKey], 'Any number of foreign keys, each of which must be valid for both this relation and the target relation'])

Bases: Generic[T]

An abstract relation; the name and columns of a relation without its actual data.

class Builder(_name: 'RelationName' = None, _columns: 'Sequence[ColumnSchema[T]]' = None, _primary_keys: 'Sequence[PrimaryKey]' = None, _foreign_keys: 'Sequence[ForeignKey]' = None)

Bases: Generic[T]

build()
columns(columns)
foreign_keys(foreign_keys)
name(name)
primary_keys(primary_keys)
COLUMNS = Name(value='columns')
FOREIGN_KEYS = Name(value='foreignKeys')
NAME = Name(value='name')
PRIMARY_KEYS = Name(value='primaryKeys')
TYPE_ = Name(value='hydra.relational.RelationSchema')
static builder()
columns: Annotated[Sequence[ColumnSchema[T]], 'A list of column specifications']
foreign_keys: Annotated[Sequence[ForeignKey], 'Any number of foreign keys, each of which must be valid for both this relation and the target relation']
name: Annotated[RelationName, 'A unique name for the relation']
primary_keys: Annotated[Sequence[PrimaryKey], 'Any number of primary keys for the relation, each of which must be valid for this relation']
with_columns(columns)
with_foreign_keys(foreign_keys)
with_name(name)
with_primary_keys(primary_keys)
class hydra.relational.Relationship(value: T)

Bases: Node[Set[Mapping[ColumnName, V]]], Generic[V]

A domain-unordered (string-indexed, rather than position-indexed) relation.

TYPE_ = Name(value='hydra.relational.Relationship')
class hydra.relational.Row(value: T)

Bases: Node[Sequence[V]], Generic[V]

An n-tuple which is an element of a given relation.

TYPE_ = Name(value='hydra.relational.Row')