My favorites | Sign in
Project Logo
Project hosting is currently READ-ONLY for network maintenance.
                
Show all Featured wiki pages:
Install
People details
Project owners:
  benchline

OVERVIEW:

Each sql command can be run in one line of code.

The results are returned in lists of lightweight objects (db_row.py) which have an optional implementation in C that is used if installed. The row objects give many methods of accessing the data like:

row.fields.fieldname
row['fieldname']
row[1] # complete backwards compatibility with existing DBAPI return values

USAGE:

>>> import sqlite3 # or any DBAPI compliant database module
>>> import edendb
>>> conn = sqlite3.connect(filename)
>>> db = edendb.EdenDB(conn)

# data manipulation statments
>>> db.dml("create table people (name varchar(10), age integer, pet varchar(10))")

# insert
>>> cols = ['name','age','pet']
>>> db.insert('people', cols, ['paul',102,'cat'])
>>> db.insert('people', cols, ['tom',88,'dog'])
>>> db.insert('people', cols, ['janise',10,'butterfly'])
>>> db.insert('people', cols, ['guido',2,'snake'])

# delete
>>> db.delete('people', 'age = 10')

# selecting
>>> db.select_one_value('count(*) as cnt', 'people')
3
>>> rows = db.select(['name','age'], 'people', 'age > 30', iter=True)
>>> for row in rows: # rows is an iterator so the database rows are loaded into memory one at a time
>>>     print row.fields.field1, row['field2'], row[0]
>>> # without the iter=True in the select method a list of rows is returned
>>> db.select(['name','age'], 'people', 'age > 30')
[(u'paul', 102), (u'tom', 88)]

# update
>>> db.update('people', ['name'], ['Paul'], "name = 'paul'")
>>> row = db.select_one_row(['*'], 'people', "name = 'Paul'")
>>> row
(u'Paul', 102, u'cat')
>>> row[1]
102
>>> row.fields.pet
u'cat'
>>> row['name']
u'Paul'
>>> conn.close()

See the doctests in eden_db.py for more examples.

TESTS:

cd edendb
python test.py -h

LIMITATIONS:

For example.

select count(*) from tablename        # this throws an exeption
select count(*) as cnt from tablename # this works

db_row.py AND C IMPLEMENTATION:

To get the speedup and low memory overhead of the C implementation, download and install the following (assuming you are on Ubuntu).

sudo aptitude install build-essentials python-dev
wget http://opensource.theopalgroup.com/files/db_row-0.8.tgz
tar -zxvf db_row-0.8.tgz
cd db_row-0.8
sudo python setup.py install

Incidentally, the db_row.py file is the same as the one from the above tarball.

Thanks to Kevin Jacobs (jacobs@theopalgroup.com) for the awesome db_row module!









Hosted by Google Code