hornet.db – Database Connectivity

Database API for HORNET. Allows simplified interaction with many relational database systems.

hornet.db is a simple wrapper for SQLAlchemy.

Create an in-memory database, using hornet.db.create_engine():

>>> db = create_engine('sqlite://')

Establish a connection:

>>> conn = db.connect()

Create some test data:

>>> r = conn.execute('CREATE TABLE test (id INTEGER)')
>>> r = conn.execute('INSERT INTO test VALUES (23)')

Perform a select from the new table and print the results:

>>> result = conn.execute('SELECT * FROM test')
>>> for r in result: print r
(23,)

You should always make sure you close the connection, preferably in a finally block:

>>> conn.close()

Module author: John Paulett <john.paulett -at- vanderbilt.edu>

hornet.db.create_engine()
Create an instance of the database, from which you can obtain connections. Takes in a database connection string (e.g. dialect://user:password@host/dbname[?key=value..]). See sqlalchemy.create_engine() for more details.

Previous topic

hornet.application – Hornet

Next topic

hornet.event – Events

This Page