table

class tinychain.collection.table.Schema(key, values=[])[source]

Bases: object

A Table schema which comprises a primary key and value Column s.

class tinychain.collection.table.Table(form=None)[source]

Bases: Collection

A Table defined by a primary key, values, and optional indices.

aggregate(columns, fn)[source]

Apply the given callback to slices of this Table grouped by the given columns.

Returns a stream of tuples of the form (<unique column values>, <callback result>).

Example: orders.aggregate([“customer_id”, “product_id”], Table.count)

columns()[source]

Return the column schema of this Table as a Tuple.

contains(key)[source]

Return True if this Table contains the given key.

count()[source]

Return the number of rows in the given slice of this Table.

delete(key)[source]

Delete the row of this Table with the given key.

insert(key, values=[])[source]

Insert the given row into this Table.

If the key is already present, this will raise a BadRequest error.

is_empty()[source]

Return True if this table contains no rows.

key_columns()[source]

Return the schema of the key columns of this Table.

key_names()[source]

Return the Id s of the key columns of this Table.

limit(limit)[source]

Limit the number of rows returned from this Table.

order_by(columns, reverse=False)[source]

Set the order in which this Table’s rows will be iterated over.

If no index supports the given order, this will raise a BadRequest error.

select(columns)[source]

Return a Table containing only the specified columns.

truncate()[source]

Delete all rows in this Table.

update(**values)[source]

Update the rows of this table with the given values.

upsert(key, values)[source]

Insert the given row into this Table.

If the row is already present, it will be updated with the given values.

where(**bounds)[source]

Return a slice of this Table whose column values fall within the specified range.

If there is no index which supports the given range, this will raise a BadRequest error.

tinychain.collection.table.create_schema(modelclass: Type[Model]) Schema[source]

Create a table schema for the given model.

A key for the table is auto generated using the class_name function, then suffixed with ‘_id’. Each attribute of the model will be considered as a column if it is of type Column or Model.