Easier raw SQL, with or without an ORM.
Project description
The Binder class
A Binder abstracts differences in the underlying database’s bind variable syntax and also grabs bind variables from a list of arguments, using dict, then attribute lookup.
Using native database binds also helps to protect you against SQL injection attacks.
supported: Postgresql, sqlite3, Oracle, MySQL
Simple sqlite3 example:
from pynoorm.binder import Binder binder = Binder.factory("qmark") #just for test... assign a custid to binder for attribute lookup binder.custid = "AMAZON" query, parameters = binder("select * from orders where custid = %(custid)s", dict(custid="ACME"), binder)
query and parameters are now in the sqlite3/qmark format:
>>> print(query) select * from orders where custid = ? >>> print(parameters) ('ACME',)
Oracle, with mutiple parameters?:
import cx_Oracle binder_ora = Binder.factory(cx_Oracle.paramstyle) tqry = "select * from orders where custid = %(custid)s and has_shipped = %(shipped)s" query, parameters = binder_ora(tqry, dict(custid="ACME", shipped=1), binder) >>> print(query) select * from orders where custid = :custid and has_shipped = :shipped >>> print(parameters) {'shipped': 1, 'custid': 'ACME'}
History
0.1.0 (2016-02-17)
First release on github.
0.1.1 (2016-02-22)
Registered on PyPI
0.2.0 (2016-04-12)
Added support for Python 3.3+ and MySQL
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
pynoorm-0.2.0.tar.gz
(19.1 kB
view hashes)