Hi all,

I'd like to build a clojure api to a mysql database. Have done this
previously using ruby's ActiveRecord which makes this very easy. clj-
record apparently provides the same kind of functionality.

The clj-record README shows how to create an interface to a table
(let's say "employees") with:

    (ns our-warehouse.employee
      (:require clj-record.boot))

    (def db ...a clojure.contrib.sql db-spec...)

    (clj-record.core/init-model)

As you see, the connection to the database is made within a namespace
that is specific to one particular table. Is there an idiomatic way
to:
- create the connection first (namespace would be for *database*
rather than *table*, so "our-warehouse* in the example above instead
of "our-warehouse.employee")
- create and initialize all the clj-record functions within that
namespace?

As there are a lot of tables (but the code for connecting to each very
short): is it possible to do all those definitions in the same file?

Or am I thinking too much using my ruby background? A small ruby
example for 2 classes:

    ActiveRecord::Base.establish_connection(
      :adapter  => "mysql",
      :host     => "localhost",
      :username => "myuser",
      :password => "mypass",
      :database => "somedatabase"
    )

    class Employee < ActiveRecord::Base
      belongs_to :company
    end

    class Company < ActiveRecord::Base
      has_many :employees
    end

Any help/direction appreciated.

Thanks,
jan.

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to