<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en-us" xmlns="http://www.w3.org/2005/Atom"><title>Simon Willison's Weblog: sqlobject</title><link href="http://simonwillison.net/" rel="alternate"/><link href="http://simonwillison.net/tags/sqlobject.atom" rel="self"/><id>http://simonwillison.net/</id><updated>2007-08-02T08:36:56+00:00</updated><author><name>Simon Willison</name></author><entry><title>Cabochon event server</title><link href="https://simonwillison.net/2007/Aug/2/project/#atom-tag" rel="alternate"/><published>2007-08-02T08:36:56+00:00</published><updated>2007-08-02T08:36:56+00:00</updated><id>https://simonwillison.net/2007/Aug/2/project/#atom-tag</id><summary type="html">
    
&lt;p&gt;&lt;strong&gt;&lt;a href="http://www.openplans.org/projects/cabochon"&gt;Cabochon event server&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
Written in Python (on top of SQLObject and Paste), uses JSON for messages, allows event consumers to subscribe with a callback URL.


    &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/cabochon"&gt;cabochon&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/callbacks"&gt;callbacks&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/events"&gt;events&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/json"&gt;json&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/paste"&gt;paste&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/python"&gt;python&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/sqlobject"&gt;sqlobject&lt;/a&gt;&lt;/p&gt;



</summary><category term="cabochon"/><category term="callbacks"/><category term="events"/><category term="json"/><category term="paste"/><category term="python"/><category term="sqlobject"/></entry><entry><title>SQLObject</title><link href="https://simonwillison.net/2003/Sep/2/sqlObject/#atom-tag" rel="alternate"/><published>2003-09-02T01:10:48+00:00</published><updated>2003-09-02T01:10:48+00:00</updated><id>https://simonwillison.net/2003/Sep/2/sqlObject/#atom-tag</id><summary type="html">
    &lt;p&gt;My new favourite toy is &lt;a href="http://sqlobject.org/"&gt;SQLObject&lt;/a&gt;, an object-relational mapper which makes heavy use of Python's &lt;a href="http://www.python.org/doc/current/ref/specialnames.html"&gt;special method names&lt;/a&gt; to create objects which can be used to transparently access and modify data in a relational database. I tried to write something like this in &lt;acronym title="PHP: Hypertext Preprocessor"&gt;PHP&lt;/acronym&gt; once before and failed miserably, but SQLObject has such an elegant design that I'm just annoyed I didn't find out about it sooner. Here's some example code, adapted from the SQLOBject site:&lt;/p&gt;

&lt;pre&gt;&lt;code class="python"&gt;from SQLObject import *
# Set up a database connection
__connection__ = PyPgSQLConnection()

# This class defines a table
class Person(SQLObject):
    firstName = StringCol(length=100)
    middleInitial = StringCol(length=1, default=None)
    lastName = StringCol(length=100)

# Now create the table (if running for the first time)
Person.createTable()

# Create a record for me
p = Person.new(firstName='Simon', lastName='Willison')

print p
# Outputs &amp;lt;Person 1 firstName='Simon' middleInitial=None lastName='Willison'&amp;gt;

# Set my middle initial (updates the database)
p.middleInitial = 'P'

# Print my full name
print p.firstName, p.middleInitial, p.lastName
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;SQLObject has plenty more tricks up its sleeve: it can create class definitions by introspecting a database table, handle one to many and many to many joins, and generate complicated SELECT statements on the fly using simple, database independant syntax. It comes with support for MySQL, Postgres and SQLite. Postgres support uses the psycopg module, but we use &lt;a href="http://pypgsql.sourceforge.net/"&gt;pyPgSQL&lt;/a&gt; so I wrote a simple connection wrapper to support that module which I've &lt;a href="http://sourceforge.net/mailarchive/forum.php?thread_id=3057051&amp;amp;forum_id=30269" title="SQLObject ported to pyPgSQL"&gt;submitted&lt;/a&gt; to the SQLObject mailing list.&lt;/p&gt;
    
        &lt;p&gt;Tags: &lt;a href="https://simonwillison.net/tags/python"&gt;python&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/sqlite"&gt;sqlite&lt;/a&gt;, &lt;a href="https://simonwillison.net/tags/sqlobject"&gt;sqlobject&lt;/a&gt;&lt;/p&gt;
    

</summary><category term="python"/><category term="sqlite"/><category term="sqlobject"/></entry></feed>