Uploaded Clinorm, an ORM-like system for Clojure

37 views
Skip to first unread message

J. Pablo" Fernández

unread,
Nov 28, 2008, 2:06:54 PM11/28/08
to clo...@googlegroups.com
CLinorm Is Not an ORM. Basically because it is not object oriented. It's
in its very very early stages of development. It's basically useless and
I'm developed on a need-to-function basis for another project I'm doing
which is not public yet. The reason to upload it is so that other people
can take a look and give me the feedback about the design and my code
(I'm not an expert Lisper) and in case anybody else needs such a system,
collaboration is welcome.

Clinorm comes with various parts. The two *external* ones are
com.kvardekdu.clinorm and com.kvardekdu.clinorm.sql. Let's start with
the first as it is the most important one. This package allows you to
define models like this:

(clinorm/defmodel :users
[[:username :string]
[:age :integer]
[:email :string]])

that generates a structure called users with three fields, username, age
and email and generates, for now, two functions (many, many more in the
future), create-table-users and drop-table-users. These functions have
very self-explanatory names. The table has all the fields defined there.
The plan is to also contain an auto-increment id, but it'll be stored as
meta-data in the structure objects. Many other functions will be
generated in the function, such as (get-users ...), (delete-users ...),
etc. I still don't know how relationships are going to be managed, but I
have an idea in my mind.

The second most important package, over which the previous one is built,
is com.kvardekdu.clinorm.sql which allows you to connect using JDBC and
a nice syntax like this:

(clinorm.sql/connect {
:type :derby
:file-name "/tmp/blah.db"
:create true}))

Note: only derby supported at the moment, and not very extensively.
That returns the connection, but also the sql package manages
connections, maybe in a non-lispy way. There's a global default
connection (many, many programs only talk to one and only one database)
and also a map of named connections (some programs talk to a fixed set
of databases, like two, very distinctive, like one is derby, the other
is mysql, or one is production, the other is qa). But if that's not good
enough for you, just take the connection returned by connect and manage
it anyway you want. All SQL functions and methods should take an
optional connection parameter.

And it also allows you to run queries like this:

(clinorm.sql/create-table :users
[[:id :integer :auto-increment]
[:username :string]
[:age :intere]]))

and it should also allow to run things like

(clinorm.sql/select [:table1 :table2]
[:where (= (user_id table1) (id table2))])

or similar; but only creating and dropping table is supported for now.
This is heavily inspired in CL-SQL. It should be a portable SQL-like
language that gets converted into various different SQLs in the back. So
far only Derby is supported and no preparations for others have been
made, the design is in-flux at the moment! Hey, this was only the work
of my little free time in a week.

Yes, feel free to consider this whole thing vapor-ware, you'd probably
be right. Or you can help me build it ;) Note that I didn't say
"released", I only uploaded it to:

http://github.com/pupeno/clinorm

Enjoy!
--
J. Pablo Fernández <pup...@pupeno.com> http://pupeno.com

signature.asc
Reply all
Reply to author
Forward
0 new messages