You are not logged in Log in Join
You are here: Home » Members » Tres Seaver's Zope.org Site » Announcing sqladapters-1.0 » View NewsItem

Log in
Name

Password

 

Announcing sqladapters-1.0

Agendaless Consulting is pleased to announce the release of version 1.0 of its sqladapters product.

Overview

This product allows developers to create filesystem-based SQL+DTML templates, and bind them to adapters using ZCML. These adapters can then apply a number of policies:

  • They can bind the adapter to a named RDBMS connection.
  • They can add an initial namespace mapping to the DTML namespace, via a user-supplied callable.
  • They can filter / post-process the results of the query, again using a user-supplied callable.
  • They can cache the results for an interval defined on a per-adapter basis.

The results of each SQL query are returned as a very lightweight object, resembling a sequence of dicts, one per row. This result set does not suffer from the leak which afflicts ZSQL.Result objects in Zope > 2.8.

Example Usage

In her product, Jane defines a SQL template in file 'sql/some_query.sql':

     SELECT c.first_name, c.last_name, c.email
       FROM customers c
       <dtml-sqlgroup where="where">
        <dtml-sqltest customer_id column="c.id" type="int" />
       </dtml-sqlgroup>

The ZCML directive would look something like:

     <configure xmlns="http://namespaces.zope.org/zope"
                xmlns:sqladapter="http://namespaces.agendaless.com/sqladapter">

      <sqladapter:adapter
        for=".interfaces.ISomeContentInterface"
        name="some_query"
        permission="zope.Public"
        template="sql/some_query.sql"
        mapping=".somemodule.somefunction"
        connection="connetion_name"
        />

     </configure>

In Python code, she would use that adapter as:

     from zope.component import getAdapter
     from Products.sqladapters.interfaces import ISQLAdapter

     query = ISQLAdapter(some_obj)
     for row in query():
        print row['first_name'], row['last_name']

Where to Get It

https://agendaless.com/Members/tseaver/software/sqladapters/sqladapters-1.0/

Reporting Bugs

https://agendaless.com/Members/tseaver/software/sqladapters/issues/