Personal tools
You are here: Home Members tseaver Software sqladapters sqladapters-1.0 sqladapters-1.0 README
Document Actions

sqladapters-1.0 README

by Tres Seaver last modified 2007-05-22 20:25

sqladapters Product README

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.

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


Powered by Plone CMS, the Open Source Content Management System

This site conforms to the following standards: