<?xml version="1.0" encoding="UTF-8" ?>
<rdf:RDF xmlns="http://usefulinc.com/ns/doap#" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"><Project><name>simpleQL</name>
<shortdesc>Efficient filtering of SQL tables with generator expressions.</shortdesc>
<description>This module allows you to access a (DB API 2) SQL table using nothing
but Python to build the query::

    &gt;&gt;&gt; import re
    &gt;&gt;&gt; from pysqlite2 import dbapi2 as sqlite
    &gt;&gt;&gt; from simpleql.table import Table

    &gt;&gt;&gt; conn = sqlite.connect(":memory:")
    &gt;&gt;&gt; curs = conn.cursor()
    &gt;&gt;&gt; curs.execute("CREATE TABLE test (a integer, b char(1))")
    &gt;&gt;&gt; curs.executemany("INSERT INTO test (a, b) VALUES (?, ?)", ([1,'a'], [2,'b'], [3,'c']))
    &gt;&gt;&gt; conn.commit()

    &gt;&gt;&gt; table = Table(conn, "test", verbose=1)
    &gt;&gt;&gt; for row in table:
    ...     print row
    ...
    SELECT a, b FROM test;
    {'a': 1, 'b': u'a'}
    {'a': 2, 'b': u'b'}
    {'a': 3, 'b': u'c'}

Note that each row in the table is a dictionary. We can filter this
using a generator expression::

    &gt;&gt;&gt; aspan = (1, 3)
    &gt;&gt;&gt; for row in (t for t in table if min(aspan) &lt; t['a'] &lt; max(aspan)):
    ...     print row
    ... 
    SELECT a, b FROM test WHERE (1&lt;a) AND (a&lt;3);
    {'a': 2, 'b': u'b'}

(This is a *fake* example, the filtering does not work in interactive
mode.)

As you can see, the query string is built from a generator expression.
You can also use list comprehensions. Regular expressions are
supported by the use of the
``re.search`` method::

    &gt;&gt;&gt; filtered = [t for t in table if re.search('a', t['b'])]
    SELECT a, b FROM test WHERE b LIKE "%a%";
    &gt;&gt;&gt; print filtered
    [{'a': 1, 'b': u'a'}]

The advantage of this approach over the `similar recipe
&lt;http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442447&gt;`_ is
that if the (efficient) query builder fails when it encounters a
complex filter the data will still be filtered (unefficiently) by
the generator expression.</description>
<homepage rdf:resource="http://dealmeida.net/projects/simpleql" />
<maintainer><foaf:Person><foaf:name>Roberto De Almeida</foaf:name>
<foaf:mbox_sha1sum>fef18002ad02a3927382e7c14b098d0dde3ee6bb</foaf:mbox_sha1sum></foaf:Person></maintainer>
<release><Version><revision>0.1.2.2</revision></Version></release>
</Project></rdf:RDF>