Skip to main content

Easy-to-use database-agnostic SQL frontend

Project description

This module implements some nice common features for database access:

  • Common parameters for database setup (no more “db” vs. “database” when you switch back-ends)

  • Single-line SQL statements and single-row SELECTs:

    >>> db.Do("insert ...")
    >>> db.commit()
    >>> try: foo,bar = db.DoFn("select ... where id=123")
    >>> except sqlmix.NoData: print "Could not find your stuff"
    >>> else: print "Foo is",foo,"and bar is",bar,"-- happy now?"
  • SELECT statements which can be used as iterators:

    >>> for a,b in db.DoSelect("select ..."):
    >>>     ...
  • … or you can get the result as a dict, or through a callback.

  • A common and clear syntax for placing values in SQL statements. (The Python DBI supports five incompatible ones.)

    >>> foo,bar = db.DoFn("select ... where id=${key}", key=whatever)

An adapter for the Twisted framework is included. It runs all queries in long-lived threads, with minimal overhead, packages the results in Deferred objects or simply uses a callback from the DB thread.

Sqlmix supports transactions, retrying them, and callback-on-final-success.

This module makes no attempt whatsoever to hide database-specific SQL syntax.

Project details

Supported by

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