Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
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
databases:
* 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
False

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


Now, create the new model/table defined above:

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

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:

http://docs.sqlalchemy.org/en/rel_0_8/orm/query.html#sqlalchemy.orm.query.Query

Release History

Release History

This version
History Node

0.1.2

History Node

0.1.1

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
saw-0.1.2.tar.gz (6.1 kB) Copy SHA256 Checksum SHA256 Source Jul 26, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting