Records

class sqlian.Record(keys, values)

A single row of data from a database.

You typically don’t need to create instances of this class, but interact with instances returned by a sqlian.standard.Database query.

__eq__(other)

Test record equality.

Two records are equal if their keys and values both match. Ordering matters.

__getattr__(key)

Access content in the record.

This works like the string indexing of __getitem__() to provide a simpler syntax under common usage. Always prefer __getitem__() (the square bracket syntax) if you want to access columns with a variable.

__getitem__(key)

Access content in the record.

Records support both numeric (sequence-like) and string (mapping-like) indexing.

Slicing is not supported. Use the values() method, which returns a slicible object.

__len__()

How many columns there are in this row.

get(key, default=None)

Get an item in the record, return default on failure.

This works similarly with the standard mapping interface, but also supports numeric indexing.

items()

Returns an iterable of 2-tuples containing keys and values.

This works similarly with the standard mapping interface.

keys()

Returns a sequence containing keys (column names) in this row.

This works similarly with the standard mapping interface.

values()

Returns a sequence containing values in this row.

This works similarly with the standard mapping interface.

class sqlian.RecordCollection(record_generator)

A sequence of records.

Record collections are backed by record generators. Results are fetched on demand. This class conforms to the standard sequence interface, and can be seamlessly treated as such.

classmethod from_cursor(cursor)

Create a RecordCollection from a DB-API 2.0 cursor.

This method automatically extract useful information for DB-API 2.0 to generate records. Discrepencies in various interfaces are generally taken care of by this method, and you should use it instead of the basic constructor when returning records for a database query.