Skip to main content
Help us improve Python packaging – donate today!

Simple sqlalchemy wrapper

Project Description

SAW / SQLAlchemy Rap Wrapper

About me:

This is a library that tries to make SQLAlchemy usage more easy. SQLAlchemy
gives you a lot of different ways to acomplish what you want to do, and
SAW tryies to give you 'one common and easy way to do a specific task'
without interfering if you need to use all the power of SQLAlchemy.

My documentation is a doctest:

You can learn about how to use me reading this doctest, and if you want
to modify me, feel free to read my unittests, i think it'll be helpfull.

You can excecute me as a doctest using the script: *rundoctest* .
For example:
(bash)(saw)$: ./rundoctest

Introduction to saw, configuring the database and declaring a model:

Generally, (when using me) you'll be defining two things to work with
* Database settings like what engine are you using (postgresql, oracle,
mysql, whatever), port, user, password, blah, blah, etc ...
* Your database model, as model we mean Table definitions, their
Columns, Relatinos, types, blah, blah, etc.

Let's go with the first thing, define the database settings, we are going
to use a sqlite db in memory:

>>> import saw
>>> db = saw.DB(name='doctest', engine='sqlite', in_memory=True)

Our db doesnt have any tables, yet.

>>> assert len(db.tables.keys()) == 0

Lets define a Person model object that will be respresented as a Table
in the database:

>>> 'Person' in db.tables

>>> class Person(db.Model):
... __tablename__ = u'Person'
... name = saw.Column(u'name',
... saw.VARCHAR,
... primary_key=True)
... def __init__(self, name):
... = name
... def __repr__(self):
... return u'Person("%s")' %

Now, create the new model/table defined above:

>>> db.create()
>>> 'Person' in db.tables

Insert, query and delete registers

We can add a new person like:

>>> db.insert(Person(name='Foo'))

We can query the database like:

>>> with db.query as query:
... person = query(db.tables.Person).first()
... assert person is not None

To delete this person you can do like:

>>> db.delete(person)
>>> with db.query as query:
... assert query(db.tables.Person).first() is None

That's all! If you would like to know more about how to make more complex
queries, you can read:

Release history Release notifications

This version
History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
saw-0.1.2.tar.gz (6.1 kB) Copy SHA256 hash SHA256 Source None Jul 26, 2013

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page