
# Binder - A Python SQL Mapper.

Binder is a lightweight SQL mapper for Python.

Install using setup.py:

    python setup.py install


## About

Binder lets you define schemas and perform SQL operations using native Python
data types and methods.  Binder takes care of SQL query generation, parameter
passing and data conversion.

Binder is explicitly designed to be a transparent SQL mapping that gives you
direct control of what database queries are executed.

To achieve this, Binder is designed as follows:

- one SQL row maps to one Python dictionary
- one SQL column maps to one key in the Python dictionary
- one SQL query maps to one python method in the API

Note that Binder is *NOT* an ORM and does not provide ORM style features such
as parent child containment, lazy loading, etc.

Currently, Binder supports the SQLite (via Python's built-in sqlite3 module)
and MySQL (via the MySQLdb python module)

See manual.txt for full documentation.


## Quick Tour

Define the schema for a table:

    >>> from binder import *
    >>> Trades = Table("trades",
    ...     DateCol("date"), UnicodeCol("trans", 4), UnicodeCol("symbol", 4),
    ...     IntCol("qty"), FloatCol("price")
    ... )

Creating a new database using SQLite and create the table we defined above:

    >>> conn = SqliteConnection("readme.db3")
    >>> conn.create_table(Trades)

Insert a row using a regular Python dictionary:

    >>> from datetime import date
    >>> row = {
    ...     "date":date(2006, 1, 5), "trans":"BUY", "symbol":"RHAT",
    ...     "qty":100, "price":35
    ... }
    >>> conn.insert(Trades, row)
    >>> conn.commit()

Finally, retrieve the data:

    >>> conn.select(Trades)
    [{'date': datetime.date(2006, 1, 5), 'symbol': u'RHAT', 'trans': u'BUY', 'price'
    : 35.0, 'qty': 100}]


