stupidb.row

Module containing classes for representing rows.

Classes

AbstractRow(piece, *pieces[, _id, _hash])

The base immutable row type of StupidDB.

JoinedRow(left, right, *[, _id, _hash])

A concrete AbstractRow subclass for two-child relations.

Row(piece, *pieces[, _id, _hash])

A concrete AbstractRow subclass for single child relations.

class stupidb.row.AbstractRow(piece, *pieces, _id=- 1, _hash=None)[source]

The base immutable row type of StupidDB.

This is the primitive immutable tuple type of the objects that are in user facing APIs. They behave nearly identically to a standard typing.Mapping, with the exception that they are hashable and values can be accessed with square-bracket syntax as well as dot notation.

pieces

One or more mappings that make up row. One for most relations, and two for joins.

_id

The index of this row in a table. This a private field whose details are subject to change without notice.

_hash

The hash of the row’s data. This stored on the instance to avoid recomputation in SetOperation instances, for example.

abstract property data: Mapping[str, Any]

Return the underlying data for this row.

Return type

Mapping[str, Any]

class stupidb.row.JoinedRow(left, right, *, _id=- 1, _hash=None)[source]

A concrete AbstractRow subclass for two-child relations.

This row type is used to represent rows of a relation with two children. Currently this is only used for Join relations.

Note

JoinedRow is the row type yielded when iterating over an instance of Join. If you want to consume the rows of a join and there are overlapping column names in the left and right relations you must select from the left and right attributes of instances of this class to disambiguate.

left

A row from the left relation

right

A row from the right relation

property data: Mapping[str, Any]

Return the underlying data of the row.

Return type

Mapping[str, Any]

classmethod from_mapping(*args, **kwargs)[source]

Raise an error.

A JoinedRow cannot be constructed from an arbitrary typing.Mapping.

Return type

JoinedRow

class stupidb.row.Row(piece, *pieces, _id=- 1, _hash=None)[source]

A concrete AbstractRow subclass for single child relations.

property data: Mapping[str, Any]

Return the underlying mapping of this Row.

Return type

Mapping[str, Any]

classmethod from_mapping(mapping, *, _id=- 1)[source]

Construct a Row instance from any mapping with string keys.

Parameters
  • mapping (Mapping[str, Any]) – Any mapping with str keys.

  • _id (int) – A new row id for the returned Row instance.

Return type

AbstractRow

merge(other)[source]

Combine the typing.Mapping other with this one.

Parameters

other (Mapping[str, Any]) – Any Mapping whose keys are instances of str.

Return type

Row