After abandoning Lisp for about six months, I'm using it again for
generating boilerplate code in web applications. The idea is, you
supply a schema, associations, and other data written as
s-expressions, and you get pretty much all the database access code
you're likely to need (outside of weird ad-hoc reporting queries).

There have been plenty of people who have written database access tier
generators in other languages, but they always make you supply the
metadata as XML, which is much weaker than s-expressions. Even Ruby's
power is no match for CLOS and the MOP.

So, for just generating schemas, this code:

(emit-table (make-table posts :cols (list (varchar 'title :maxlen 50
:unique :not-null) created-at (text 'content :indexed :not-null))))

Evaluates to:

CREATE TABLE POSTS(
ID SERIAL  PRIMARY KEY,
TITLE VARCHAR(50) NOT NULL UNIQUE,
CREATED_AT timestamp(0) with time zone DEFAULT now(),
CONTENT TEXT NOT NULL);

CREATE INDEX POSTS_CONTENT_G5535 ON POSTS(CONTENT);
CREATE INDEX POSTS_TITLE_G5724 ON POSTS(TITLE);

I've added Rails-style associations so that it compiles to PostgreSQL
stored procedures (rather than parameterized queries in a
general-purpose language) to do pretty much all the automatically
generated methods in, say, ActiveRecord provide, and then some. I
think it's a pretty good way to go if you're not living in a city that
has Ruby/Rails jobs (i.e., pretty much any city other than San
Francisco).

You get a fraction of what ActiveRecord has to offer without preachy
my-way-or-the-highway bullshit from pouty twenty-something artfags who
act like they have decades of experience when they only have a few
years. Hooray!

Warren
_______________________________________________
Gardeners mailing list
[email protected]
http://www.lispniks.com/mailman/listinfo/gardeners

Reply via email to