Giter Site home page Giter Site logo

binder's Introduction

Binder - A Python SQL Mapper.

Binder is a lightweight SQL mapper for Python that lets you perform SQL operations using native Python data types and methods:

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

A database row is mapped to a Python dictionary containing native Python data types. Binder gives you control of what SQL query is executed, while taking care of query generation, parameter passing and data conversion.

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

See manual.txt for full documentation.

Installing

Install using pip:

pip install binder

Install from source:

python setup.py install

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}]

binder's People

Contributors

divtxt avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

joepie91

binder's Issues

float does not roundtrip in Postgres & MySQL

From test_insert.py:

def test_roundtrip_float_fidelity(self):
    ...
        # XXX Postgres & Mysql roundtrip issues
        # Postgres: http://psycopg.lighthouseapp.com/projects/62710/tickets/145
        # MySQL: http://sourceforge.net/p/mysql-python/bugs/292/
    ...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.