[postmodern-devel] Submarine announcement

Ryszard Szopa ryszard.szopa at gmail.com
Tue Aug 28 15:49:28 UTC 2007


Hello Marijn and Postmodern users,

I was a bit dissatisfied with Postmodern's DAO system and lack of
support for foreign keys. At first, I wrote just a patch that added
support for foreign keys, but it turned the macro DEFTABLE into
something that had more than 100 lines and was pretty unmaintainable.
So, I left Postmodern's sources alone and wrote a library over it,
something between Postmodern and an object persistency library. I've
used it in some of my projects at work, and now I decided to make it
open source. In a couple of days I'll start it a common-lisp.net
project and announce it to c.l.l.

In the meantime, I will be very grateful for any comments. I encourage
you to at least take a look at the example file:
http://bender.streamtech.nl/darcs/submarine/doc/example.lisp

Here are the contents of my README file:

Submarine is a Common Lisp library that's somewhere between a
PostgreSQL library an an object persistency system.  It uses
Postmodern to communicate with the database. The basic idea is that
you create your classes in the metaclass DB-CLASS and submarine cares
about creating SQL tables or, if the tables already exist, checking if
they conform to the provided specification.  Moreover, Submarine
supports an intuitive way of expressing both one-to-many and
many-to-many relations.

Getting submarine
=================

At the moment there's only a darcs repository available:

    darcs pull http://bender.streamtech.nl/darcs/submarine/

You will also need my mop-utilities, which may be incorporated into
submarine in the close future:

    darcs get http://bender.streamtech.nl/darcs/mop-utils

Dependencies
============

Submarine depends on Postmodern and Iterate.
It uses also my library of MOP utilities, MOP-UTILS, which may become
a separate library in the future.  On platforms other than SBCL,
mop-utils needs Closer-mop.

License
=======

Submarine is released under a BSD-like license. Which approximately
means you can use the code in whatever way you like, except for
passing it off as your own or releasing a modified version without
indication that it is not the original.

Relation to Postmodern
======================

Submarine started as a patch that added, among others, foreign keys
support to Postmodern.  This meant hacking the DEFTABLE macro and
TABLE and TABLEFIELD classes.  After some time I realized that my
modified Postmodern macros had become far too large and heavy to be
easy maintainable. So, I decided to leave Postmodern's code as it was
and write a separate library.

Introduction for Postmodern users
=================================

Submarine tries to keep as much as possible of Postmodern's original
API. I use the same terminology, and functions with similar names will
probably do very similar things. My purpose was twofold. First of all,
I wanted to make porting programs using Postmodern to Submarine
easy. Secondly, this would allow me to use some of Marijn Haverbeke's
superb documentation nearly without any changes.

Main differences between Postmodern and Submarine:

 * You don't have to create DAO (database access object) classes and SQL
tables separately. You just create classes belonging to a certain
metaclass, and the library cares of the rest.

 * If the table with an appropriate name exists in the database,
Submarine will test if it has columns with the right names and
types. If a column does not exist or has a wrong type, Submarine will
offer the user a possibility to fix it. Submarine will warn, but do
nothing about any additional columns in the table.

 * Each DB-CLASS class has its own connection specification. This means
that you can just access your objects, without wrapping them in a
WITH-CONNECTION macro, and they will care about setting the right
connection.

 * DAO is a basis class for DB-CLASS classes, and methods that are
supposed to work on an object of any DB-CLASS class use DAO as a
dispatch type. Of course, you don't have to use DAO as a base class,
but it makes a lot of things easier.

 * Submarine supports foreign keys. If you define a DB-CLASS class
with a slot whose type is another DB-CLASS, it is treated as foreign
key and an appropriate constraint is added to the database.

 * Submarine provides a function to retrieve all the elements of a
given type standing in a many-to-one relation with some DAO object.

 * The DEF-MANY-TO-MANY macro defines a many-to-many relation between
two classes and creates methods appropriate to their retrieval (it
creates a link table in the database).

 * DB-CLASS slots have an additional attribute TRANSIENT. If you set
it to a non-NIL value, it will behave just as a
STANDARD-SLOT-DEFINITION and will be ignored in database related
operations.

 * Submarine uses MOP rather than macros to achieve its purposes. This
makes it easier to maintain and to extend.

At the moment there's no real documentation apart from docstrings, but
there's a poor man's tutorial in the file
http://bender.streamtech.nl/darcs/submarine/doc/example.lisp (this
should give you a pretty good overview of the possibilities of
Submarine.

Bests,

    -- Richard
-- 
http://szopa.tasak.gda.pl/



More information about the postmodern-devel mailing list