API

class htables.PostgresqlDB(connection_uri, schema=None, debug=False)

Session pool for a PostgreSQL database. Expects a connection string, for example 'postgresql://localhost/myproject'. If debug is True, a validation is performed on row.save(), to make sure all keys and values are strings. schema is deprecated.

get_session(lazy=False)

Get a Session for talking to the database. If lazy is True then the connection is estabilished only when the first query needs to be executed.

put_session(session)

Retire the session, freeing up its connection, and aborting any non-committed transaction.

class htables.SqliteDB(uri, schema=None)

SQLite database session pool; same api as PostgresqlDB.

class htables.Session(schema, conn, debug=False)

Wrapper for a database connection with methods to access tables and commit/rollback transactions.

__getitem__(name)

Get the Table called name.

get_db_file(id=None)

Access a DbFile. If id is None, a new file is created; otherwise, the requested blob file is returned by id.

del_db_file(id)

Delete the DbFile object with the given id.

commit()

Commit the current transaction.

rollback()

Roll back the current transaction.

class htables.Table(row_cls, session)

A database table with two columns: id (integer primary key) and data (hstore).

exception MultipleRowsFound

Multiple rows matching search critera.

exception Table.RowNotFound

No row matching search criteria.

Table.create_table()

Create the backend SQL table.

Table.drop_table()

Drop the backend SQL table.

Table.find(**kwargs)

Returns an iterator over all matching TableRow objects.

Table.find_first(**kwargs)

Shorthand for calling find() and getting the first result. Raises RowNotFound if no result is found.

Table.find_single(**kwargs)

Shorthand for calling find() and getting the first result. Raises RowNotFound if no result is found. Raises MultipleRowsFound if more than one result is found.

Table.get(obj_id)

Fetches the TableRow with the given id.

Table.new(*args, **kwargs)

Create a new TableRow with auto-incremented id. An INSERT SQL query is executed to generate the id.

Table.query(where={}, order_by=None, offset=0, limit=None, count=False)

Same as find() but results are clipped with offset and limit.

class htables.Row

Database row, represented as a Python dict.

id

Primary key of this row.

delete()

Execute a DELETE query for this row.

save()

Execute an UPDATE query for this row.

class htables.DbFile(session, id)

Database binary blob. It works like a file, but has a simpler API, with methods to read and write a stream of byte chunks.

id

Unique ID of the file. It can be used to request the file later via Session.get_db_file().

iter_data()

Read data from database and return it as a Python generator.

save_from(in_file)

Consume data from in_file (a file-like object) and save to database.

Previous topic

Storing data

Next topic

Changelog

This Page