dynamic namespace generation using clj-record

2010-10-27 Thread takashi
Hello Jimm

I've been testing the clojure library clj-record and it is very
usefull. But I have a question, I'm a 'noob' on clojure language and
I'm wondering if it is possible to write a macro or something to get
namespaces generated for every table in my database, for example I
inicialize the model of one table 'keyword' in a keyword.clj file:

(ns interp.keyword
  (:use interp.conn) ;for db connection
  (:require clj-record.boot))
(clj-record.core/init-model
:table-name "keyword")

I already try to use create-ns and with-ns to define a namespace but
din't work. Something like:

(with-ns (create-ns 'interp.keyword)
(:require clj-record.boot)
(:use interp.conn)
(clj-record.core/init-model
:table-name "keyword")
)

Any advices? thank you in advance!

Regards!

-- 
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


Re: clj-record Library: Handling Namespaces

2010-10-20 Thread Stefan Rohlfing
I apologize for presenting you with a moving target. That was
definitely not my attention.

I should have realized I messed up the content of the files but
unfortunately had no clue what all these exceptions meant.

Therefore I really appreciate your detailed description of the
conclusion you draw from the different error messages.

Thanks again for your great help!

Stefan





On Oct 20, 8:34 pm, Meikel Brandmeyer  wrote:
> Hi,
>
> On 20 Okt., 14:04, Stefan Rohlfing  wrote:
>
> > I really learned at lot about dealing with namespaces today.
>
> I hope you also learned a bit about error messages. ;)
>
> "No such var: user/create": That means you get past the namespace
> declaration. Hence they load fine. But in the user namespace the model-
> init call was obviously not done. => Possible questions: maybe the
> file was not saved? maybe there is a spurious .class file around
> messing up things from a previous AOT compilation run?
>
> "EOF while reading": Now something changed. Either in one of
> the :required namespaces was a syntax error introduced, or the init-
> model now happens and the syntax error is in a-r.program.core after
> the user/create call.
>
> I remembered darkly that I had once trouble with Vars which had the
> same name as an alias. Hence my questions: "Did you try the same with
> charge instead of user?" => Different alias. Does it work? Then the
> problem could be the alias.
>
> "No such namespace: charge": So the alias is not done. That means that
> the error is either in user, during its alias creation or charge
> itself. Just to be sure my question: "Does it work with a different
> alias instead of user?"
>
> "Unable to resolve symbol: user=> in this context": again something
> changed in the files between our conversation. So we are targeting a
> moving target. Hence my request to really check the files and - if in
> doubt - use a fresh repl to get a clear foundattion.
>
> There were several occasions in the above description, where I'm
> expected an exception, but you didn't report one, and where I'm not
> sure whether this was due to the repl interaction or other side
> effects (eg. unsaved files, etc.). Also your positive report in the
> end leaves the question why it actually works now. From the code you
> pasted it should have worked from the beginning.
>
> Anyway, it works. :)
>
> Sincerely
> Meikel

-- 
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


Re: clj-record Library: Handling Namespaces

2010-10-20 Thread Meikel Brandmeyer
Hi,

On 20 Okt., 14:04, Stefan Rohlfing  wrote:

> I really learned at lot about dealing with namespaces today.

I hope you also learned a bit about error messages. ;)

"No such var: user/create": That means you get past the namespace
declaration. Hence they load fine. But in the user namespace the model-
init call was obviously not done. => Possible questions: maybe the
file was not saved? maybe there is a spurious .class file around
messing up things from a previous AOT compilation run?

"EOF while reading": Now something changed. Either in one of
the :required namespaces was a syntax error introduced, or the init-
model now happens and the syntax error is in a-r.program.core after
the user/create call.

I remembered darkly that I had once trouble with Vars which had the
same name as an alias. Hence my questions: "Did you try the same with
charge instead of user?" => Different alias. Does it work? Then the
problem could be the alias.

"No such namespace: charge": So the alias is not done. That means that
the error is either in user, during its alias creation or charge
itself. Just to be sure my question: "Does it work with a different
alias instead of user?"

"Unable to resolve symbol: user=> in this context": again something
changed in the files between our conversation. So we are targeting a
moving target. Hence my request to really check the files and - if in
doubt - use a fresh repl to get a clear foundattion.

There were several occasions in the above description, where I'm
expected an exception, but you didn't report one, and where I'm not
sure whether this was due to the repl interaction or other side
effects (eg. unsaved files, etc.). Also your positive report in the
end leaves the question why it actually works now. From the code you
pasted it should have worked from the beginning.

Anyway, it works. :)

Sincerely
Meikel

-- 
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


Re: clj-record Library: Handling Namespaces

2010-10-20 Thread Stefan Rohlfing
You were right again. I left a code snippet from the book in
charge.clj and forgot to remove it later.

Now everything seems to work fine, even when importing the active-
record.user namespace as 'user':


(ns active-record.program.core
   (:require [active-record.user :as user])
   (:require [active-record.charge :as charge]))

(user/create
 {:login "my-login"
  :first_name "Stefan"
  :last_name "Rohl"
  :password "secret"
  :email_address "ste...@example.com"})

;; {:email_address "ste...@example.com", :password "secret",
;;  :last_name "Rohl", :first_name "Stefan", :login "my-login",
;;  :id 8}

(charge/create
 {:user_id 8,
  :amount_dollars 27
  :amount_cents 91
  :category "meals"
  :vendor_name "Metro"
  :date "2010-01-15"})

;; {:date "2010-01-15", :vendor_name "Metro", :category "meals",
;;  :amount_cents 91, :amount_dollars 27, :id 7,
;;  :user_id 8}



Thank you so much for your help! I really learned at lot about dealing
with namespaces today.

Stefan


On Oct 20, 5:45 pm, Meikel Brandmeyer  wrote:
> Hi,
>
> On 20 Okt., 11:35, Stefan Rohlfing  wrote:
>
> > Evaluating your suggested declaration:
>
> >  (ns active-record.program.core
> >    (:require [active-record.user :as u])
> >    (:require [active-record.charge :as charge]))
>
> > I get the following error message:
>
> > ;; Unable to resolve symbol: user=> in this context
> > ;;   [Thrown class java.lang.Exception]
>
> You copy'n'pasted a clojure prompt somewhere or your repl is messed
> up. Please check your files thoroughly and (if necessary) start with a
> fresh repl.
>
> Sincerely
> Meikel

-- 
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


Re: clj-record Library: Handling Namespaces

2010-10-20 Thread Meikel Brandmeyer
Hi,

On 20 Okt., 11:35, Stefan Rohlfing  wrote:

> Evaluating your suggested declaration:
>
>  (ns active-record.program.core
>    (:require [active-record.user :as u])
>    (:require [active-record.charge :as charge]))
>
> I get the following error message:
>
> ;; Unable to resolve symbol: user=> in this context
> ;;   [Thrown class java.lang.Exception]

You copy'n'pasted a clojure prompt somewhere or your repl is messed
up. Please check your files thoroughly and (if necessary) start with a
fresh repl.

Sincerely
Meikel

-- 
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


Re: clj-record Library: Handling Namespaces

2010-10-20 Thread Stefan Rohlfing
Evaluating your suggested declaration:

 (ns active-record.program.core
   (:require [active-record.user :as u])
   (:require [active-record.charge :as charge]))

I get the following error message:

;; Unable to resolve symbol: user=> in this context
;;   [Thrown class java.lang.Exception]

The same happens if I do not include the active-record.user namespace:

(ns active-record.program.core
   (:require [active-record.charge :as charge]))


;; Unable to resolve symbol: user=> in this context
;;   [Thrown class java.lang.Exception]


On Oct 20, 5:23 pm, Meikel Brandmeyer  wrote:
> Hi,
>
> On 20 Okt., 11:09, Stefan Rohlfing  wrote:
>
> > Yes, I also tried charge/create. The error message is different, but
> > it still does not work:
>
> More evidence for a problem with the user alias. Try a different one
> like (:require [active-record.user :as u]).
>
> Sincerely
> Meikel

-- 
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


Re: clj-record Library: Handling Namespaces

2010-10-20 Thread Meikel Brandmeyer
Hi,

On 20 Okt., 11:09, Stefan Rohlfing  wrote:

> Yes, I also tried charge/create. The error message is different, but
> it still does not work:

More evidence for a problem with the user alias. Try a different one
like (:require [active-record.user :as u]).

Sincerely
Meikel

-- 
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


Re: clj-record Library: Handling Namespaces

2010-10-20 Thread Stefan Rohlfing
Yes, I also tried charge/create. The error message is different, but
it still does not work:

;; No such namespace: charge
;;  [Thrown class java.lang.Exception]


On Oct 20, 5:03 pm, Meikel Brandmeyer  wrote:
> Hi,
>
> On 20 Okt., 10:46, Stefan Rohlfing  wrote:
>
> > You are right, there was a syntax error in charge.clj. However, after
> > correcting the error I get the same error message as with the other
> > namespace declaration:
>
> Did you try the same with charge/create? Examples in books are not
> necessarily correct.
>
> Sincerely
> Meikel

-- 
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


Re: clj-record Library: Handling Namespaces

2010-10-20 Thread Meikel Brandmeyer
Hi,

On 20 Okt., 10:46, Stefan Rohlfing  wrote:

> You are right, there was a syntax error in charge.clj. However, after
> correcting the error I get the same error message as with the other
> namespace declaration:

Did you try the same with charge/create? Examples in books are not
necessarily correct.

Sincerely
Meikel

-- 
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


Re: clj-record Library: Handling Namespaces

2010-10-20 Thread Stefan Rohlfing
You are right, there was a syntax error in charge.clj. However, after
correcting the error I get the same error message as with the other
namespace declaration:

;; No such var: user/create
;;   [Thrown class java.lang.Exception]

On Oct 20, 4:37 pm, Meikel Brandmeyer  wrote:
> Hi,
>
> On 20 Okt., 10:09, Stefan Rohlfing  wrote:
>
> > ;; EOF while reading
> > ;;  [Thrown class java.lang.Exception]
>
> Are you sure, that you don't have some syntax error somewhere?
>
> Sincerely
> Meikel

-- 
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


Re: clj-record Library: Handling Namespaces

2010-10-20 Thread Meikel Brandmeyer
Hi,

On 20 Okt., 10:09, Stefan Rohlfing  wrote:

> ;; EOF while reading
> ;;  [Thrown class java.lang.Exception]

Are you sure, that you don't have some syntax error somewhere?

Sincerely
Meikel

-- 
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


Re: clj-record Library: Handling Namespaces

2010-10-20 Thread Stefan Rohlfing
The name 'user' is taken from an example in the book. The author
executes the code at the REPL like this:

(require '(active-record [user :as user]))

user=> (user/create {:login "rob"
 :first_name "Robert"
 :last_name "Berger"
 :password "secret"
     :email_address "r...@runa.com"})

And then there is the clj-record macro 'init-model' that creates a
model out of a Clojure namespace. However, I don't quite understand
how this affects bringing in the namespaces.
Here is the code:
http://github.com/duelinmarkers/clj-record/blob/master/src/clj_record/core.clj
(at the bottom)



On Oct 20, 4:20 pm, Michael Wood  wrote:
> On 20 October 2010 10:09, Stefan Rohlfing  wrote:
>
>
>
>
>
>
>
>
>
> > Dear Clojure group,
>
> > I am currently reading chapter 9.1 MySQL & clj-record of 'Clojure in
> > Action'.
>
> > clj-record seems pretty awesome, but I once again got lost in
> > namespace jungle.
>
> > Here is a concrete example:
>
> > --- 
> > -
>
> > File 1: src/active-record/credentials.clj
> > [Database credentials]
>
> > (ns active-record.credentials)
>
> > (def db
> >     {:classname "com.mysql.jdbc.Driver"
> >      :subprotocol "mysql"
> >      :user ""
> >      :password ""
> >      :subname "//localhost:3306/damages_dev"
> >      })
>
> > --- 
> > -
>
> > File 2: src/active-record/user.clj
> > [Belongs to the database name with the name 'users']
>
> > (ns active-record.user
> >  (:use [active-record.credentials :only [db]])
> >  (:require clj-record.boot))
>
> >  (clj-record.core/init-model
> >   (:associations
> >    (has-many charges)))
>
> > --- 
> > -
>
> > File 3: src/active-record/charge.clj
> > [Belongs to the database name with the name 'charges']
>
> > (ns active-record.user
> >  (:use [active-record.credentials :only [db]])
> >  (:require clj-record.boot))
>
> >  (clj-record.core/init-model
> >   (:associations
> >    (has-many charges)))
>
> > --- 
> > -
>
> > I want to add/remove/alter table entries in a different file:
>
> > File 4: src/active-record/program/core.clj
>
> > All my efforts to import the user.clj and charge.clj namespaces have
> > failed so far. For example, I have tried the following namespace
> > declaration:
>
> >  (ns active-record.program.core
> >   (:require [active-record.user :as user])
>
> Just a guess, but try something other than "user".  The user namespace
> is the default namespace when using the repl and maybe there's some
> sort of conflict there.
>
> I'm not sure how likely that is, but it's worth a try, I think :)
>
>
>
>
>
>
>
>
>
> >   (:require [active-record.charge :as charge])
> >     (:require clj-record.boot))
>
> > (user/create
> >  {:login "rob"
> > :first_name "Robert"
> > :last_name "Berger"
> > :password "secret"
> > :email_address "r...@runa.com"})
>
> > ;; No such var: user/create
> > ;;  [Thrown class java.lang.Exception]
>
> > This one doesn't work either:
>
> >  (ns active-record.program.core
> >   (:require [active-record.user :as user])
> >   (:require [active-record.charge :as charge]))
>
> > ;; EOF while reading
> > ;;  [Thrown class java.lang.Exception]
>
> > Can anybody tell me what went wrong in the example above?
>
> --
> Michael Wood 

-- 
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


Re: clj-record Library: Handling Namespaces

2010-10-20 Thread Michael Wood
On 20 October 2010 10:09, Stefan Rohlfing  wrote:
> Dear Clojure group,
>
> I am currently reading chapter 9.1 MySQL & clj-record of 'Clojure in
> Action'.
>
> clj-record seems pretty awesome, but I once again got lost in
> namespace jungle.
>
> Here is a concrete example:
>
> 
>
> File 1: src/active-record/credentials.clj
> [Database credentials]
>
> (ns active-record.credentials)
>
> (def db
>     {:classname "com.mysql.jdbc.Driver"
>      :subprotocol "mysql"
>      :user ""
>      :password ""
>      :subname "//localhost:3306/damages_dev"
>      })
>
>
> 
>
> File 2: src/active-record/user.clj
> [Belongs to the database name with the name 'users']
>
>
> (ns active-record.user
>  (:use [active-record.credentials :only [db]])
>  (:require clj-record.boot))
>
>
>  (clj-record.core/init-model
>   (:associations
>    (has-many charges)))
>
>
> 
>
>
> File 3: src/active-record/charge.clj
> [Belongs to the database name with the name 'charges']
>
>
> (ns active-record.user
>  (:use [active-record.credentials :only [db]])
>  (:require clj-record.boot))
>
>
>  (clj-record.core/init-model
>   (:associations
>    (has-many charges)))
>
>
> 
>
> I want to add/remove/alter table entries in a different file:
>
> File 4: src/active-record/program/core.clj
>
> All my efforts to import the user.clj and charge.clj namespaces have
> failed so far. For example, I have tried the following namespace
> declaration:
>
>  (ns active-record.program.core
>   (:require [active-record.user :as user])

Just a guess, but try something other than "user".  The user namespace
is the default namespace when using the repl and maybe there's some
sort of conflict there.

I'm not sure how likely that is, but it's worth a try, I think :)

>   (:require [active-record.charge :as charge])
>     (:require clj-record.boot))
>
> (user/create
>  {:login "rob"
> :first_name "Robert"
> :last_name "Berger"
> :password "secret"
> :email_address "r...@runa.com"})
>
> ;; No such var: user/create
> ;;  [Thrown class java.lang.Exception]
>
> This one doesn't work either:
>
>  (ns active-record.program.core
>   (:require [active-record.user :as user])
>   (:require [active-record.charge :as charge]))
>
> ;; EOF while reading
> ;;  [Thrown class java.lang.Exception]
>
> Can anybody tell me what went wrong in the example above?

-- 
Michael Wood 

-- 
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


clj-record Library: Handling Namespaces

2010-10-20 Thread Stefan Rohlfing
Dear Clojure group,

I am currently reading chapter 9.1 MySQL & clj-record of 'Clojure in
Action'.

clj-record seems pretty awesome, but I once again got lost in
namespace jungle.

Here is a concrete example:



File 1: src/active-record/credentials.clj
[Database credentials]

(ns active-record.credentials)

(def db
 {:classname "com.mysql.jdbc.Driver"
  :subprotocol "mysql"
  :user ""
  :password ""
  :subname "//localhost:3306/damages_dev"
  })




File 2: src/active-record/user.clj
[Belongs to the database name with the name 'users']


(ns active-record.user
  (:use [active-record.credentials :only [db]])
  (:require clj-record.boot))


  (clj-record.core/init-model
   (:associations
(has-many charges)))





File 3: src/active-record/charge.clj
[Belongs to the database name with the name 'charges']


(ns active-record.user
  (:use [active-record.credentials :only [db]])
  (:require clj-record.boot))


  (clj-record.core/init-model
   (:associations
(has-many charges)))




I want to add/remove/alter table entries in a different file:

File 4: src/active-record/program/core.clj

All my efforts to import the user.clj and charge.clj namespaces have
failed so far. For example, I have tried the following namespace
declaration:

 (ns active-record.program.core
   (:require [active-record.user :as user])
   (:require [active-record.charge :as charge])
 (:require clj-record.boot))


(user/create
 {:login "rob"
:first_name "Robert"
:last_name "Berger"
:password "secret"
:email_address "r...@runa.com"})

;; No such var: user/create
;;  [Thrown class java.lang.Exception]



This one doesn't work either:

 (ns active-record.program.core
   (:require [active-record.user :as user])
   (:require [active-record.charge :as charge]))

;; EOF while reading
;;  [Thrown class java.lang.Exception]



Can anybody tell me what went wrong in the example above?


Stefan

-- 
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


Re: Clj-record

2009-09-01 Thread John D. Hume

On Tue, Sep 1, 2009 at 4:43 PM, Luc
Prefontaine wrote:
> Hi John,
>
> Clj-record will make its way into production in a couple of weeks.
>
> It's been working flawlessly in high volume tests here.

Hi Luc,
That's great to hear. I recently set up a Google Group for clj-record,
so you may want to sign up.
http://groups.google.com/group/clj-record-dev

It's very low-volume. In fact, it's basically no-volume. :)

Thanks for the encouragement.
-hume.

-- 
http://elhumidor.blogspot.com/

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Clj-record

2009-09-01 Thread Luc Prefontaine
Hi John,

Clj-record will make its way into production in a couple of weeks.

It's been working flawlessly in high volume tests here.

We added an adapter on our medical message bus to capture historical
census data in messages. It records patient visits, employees dealing
with patients,  service requests,
diagnoses, rooms, ...
This is a must to deal with pandemics, it allows medical personnel to
track down who's been in contact with other parties and which physical
locations maybe contaminated.

The adapter (Clojure) populates the census database (MySql) using
clj-record.
A Rail GUI allows immediate access to the database and a report engine
(in progress) will allow management to pull out reports from it.
Users can go back in the past to find out how diseases have spread out
within the hospital.

We think that we could add some intelligent tracking here to identify
how a disease propagated given it's transmission pattern (by contact,
air, ...)

We got an emergency request from our pilot site to get this out since
winter is coming by and all these flue viruses are evolving pretty fast.
Hell of a summer here... so version 1.0 is now in acceptance test at the
pilot site.

Thank you for the good work, it's very useful :)))

Luc Préfontaine

Armageddon was yesterday, today we have a real problem...

--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2009-01-11 Thread John D. Hume

Hi Emeka,
Sorry for the slow response. I don't get that message with the latest
clojure, clojure-contrib, and clj-record. (load-file just returns
nil.)

What version of clojure are you running? Do you have the base
directory of clj-record on your classpath?

Also, that file just contains the library, so you probably want to
require it rather than load-file. Or if you want to run the tests,
(load-file "clj_record/test/main.clj")


On Thu, Jan 8, 2009 at 7:01 AM, Emeka  wrote:
>
> user=> (load-file "clj_record/core.clj")
> I got clj_record/util not in system path. Why is it so?

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2009-01-08 Thread Emeka
user=> (load-file "clj_record/core.clj")
I got clj_record/util not in system path. Why is it so?


Emeka

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2009-01-05 Thread Michael Reid

> I guess it comes down to what belongs in metadata. While errors are
> certainly data about other data, they don't feel to me like metadata a
> la :doc, :tag, :file, :line, and :test. They're the sort of thing I'd
> show in an application's UI as part of normal user interactions,
> rather than something used only behind the scenes, so they feel to me
> like first-class data.
>

I've found that reading Rich's description of what metadata is is a
good way to see more clearly in cases such as these, specifically this
passage I find helpful:

  "An important thing to understand about metadata is that it is not
considered to be part of the value of an object. As such, metadata
does not impact equality (or hash codes). Two objects that differ only
in metadata are equal."

So ask yourself, should the object with the errors hash in metadata be
equal (as defined by the = function) to the object without the same
error information?

If yes, then metadata seems like a good fit. Of course, if its
nonsensical to consider such a comparison then thinking about it this
way may not make things any more clear.

I'm not too involved with the code here, but one thing that seems
dangerous about storing this information in metadata here is that if
this is supposed to signify an error condition, then it is entirely
possible for code to use the returned value and never realize there
was an error if they didn't know to look at the metadata.

If you return a different object altogether then the caller of the
code will discover one way or another that the returned object isn't
what they expected.

... just some thoughts ...

/mike.

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2009-01-05 Thread John D. Hume

On Mon, Jan 5, 2009 at 1:29 AM, Brian Doyle  wrote:
> ...  Instead of
> just returning a hash of errors what about returning the record with the
> errors hash in
> the metadata?   That way you just have the data and the errors in one

That's an interesting idea. On the one hand it seems weird to me that
a function (other than (meta ...) might return a value that's equal to
its input but with new metadata hanging off it. On the other hand,
it's pretty convenient to have both the inputs and validation errors
together.

I guess it comes down to what belongs in metadata. While errors are
certainly data about other data, they don't feel to me like metadata a
la :doc, :tag, :file, :line, and :test. They're the sort of thing I'd
show in an application's UI as part of normal user interactions,
rather than something used only behind the scenes, so they feel to me
like first-class data.

-hume.

-- 
http://elhumidor.blogspot.com/

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2009-01-04 Thread Brian Doyle
John,

I was looking at the validates method and I had a thought I'd bounce off
you.  Instead of
just returning a hash of errors what about returning the record with the
errors hash in
the metadata?   That way you just have the data and the errors in one
"object" similar
to an ActiveRecord model.

On Sun, Jan 4, 2009 at 2:22 PM, Brian Doyle  wrote:

> Looks good.  I didn't know about the *file* var.
>
> On Sun, Jan 4, 2009 at 11:22 AM, John D. Hume wrote:
>
>>
>> Brian,
>> I incorporated your changes and then made changes to load and run all
>> clj_record/test/*-test.clj files. Thanks again.
>> -hume.
>>
>> >>
>>
>

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2009-01-04 Thread Brian Doyle
Looks good.  I didn't know about the *file* var.

On Sun, Jan 4, 2009 at 11:22 AM, John D. Hume wrote:

>
> Brian,
> I incorporated your changes and then made changes to load and run all
> clj_record/test/*-test.clj files. Thanks again.
> -hume.
>
> >
>

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2009-01-04 Thread John D. Hume

Brian,
I incorporated your changes and then made changes to load and run all
clj_record/test/*-test.clj files. Thanks again.
-hume.

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2009-01-03 Thread John D. Hume

Hi Brian,

On Sat, Jan 3, 2009 at 12:53 AM, Brian Doyle  wrote:
> I changed the end of the clj-record/test/main.clj script to this:
>
> main.clj >>>>
> (def files ["core-test" "validation-test" "associations-test"])
> (doseq [file files]
>(load file))
> (def base-ns (re-find #"^\w*.*\." (str *ns*)))
> (apply test-is/run-tests (map #(symbol (str base-ns %)) files))
> main.clj <<<<

I'm not sure if it was added later or if I just missed the fact that
you could pass a seq of ns strings to run-tests. All I'd seen was
passing a single ns, which led to way too much output if I called it
once per test ns, or running all tests, which was a little silly but
at least made sure I didn't miss anything. Thanks for pointing that
out.
-hume.

-- 
http://elhumidor.blogspot.com/

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2009-01-02 Thread Brian Doyle
John,

I was looking around at your tests just to get a feel for using the test-is
stuff in the contrib library.  I noticed that when I ran main.clj it would
run
not only the tests in clj-record, but all of the tests in the
clojure.contrib
as well.  I was curious so I attempted to figure out what was going on
and what to do to only run the tests in clj-record.test.*.

I changed the end of the clj-record/test/main.clj script to this:

main.clj >>>>
(def files ["core-test" "validation-test" "associations-test"])

(doseq [file files]
   (load file))

(def base-ns (re-find #"^\w*.*\." (str *ns*)))

(apply test-is/run-tests (map #(symbol (str base-ns %)) files))
main.clj <<<<

I also had to change the ns function in the associations-test.clj file
to match the name of the file.   The word 'associations' in the namespace
was just misspelled.

On Wed, Dec 31, 2008 at 9:39 AM, John D. Hume wrote:

>
> Hi Brian,
>
> On Tue, Dec 30, 2008 at 11:41 AM, Brian Doyle 
> wrote:
> > (ns com.example.user)
> >   (clj-record.core/init-model)
> >
> > but when I do that I get the error:
> >
> > java.lang.ClassNotFoundException: clj-record.core
> ...
> > (first (reverse (re-split #"\." (name (ns-name *ns*)
> >
> > and could be changed to:
> >
> > (last (re-split #"\." (name (ns-name *ns*
>
> Those changes have been incorporated, along with stuff in the README
> about validation.
>
> I'm confused as to how I ended up with (first (reverse ...)) since I
> remember looking at the doc for (last seq), but anyway, it's there
> now.
>
> -hume.
> --
> http://elhumidor.blogspot.com/
>
> >
>

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2008-12-31 Thread John D. Hume

Hi Brian,

On Tue, Dec 30, 2008 at 11:41 AM, Brian Doyle  wrote:
> (ns com.example.user)
>   (clj-record.core/init-model)
>
> but when I do that I get the error:
>
> java.lang.ClassNotFoundException: clj-record.core
...
> (first (reverse (re-split #"\." (name (ns-name *ns*)
>
> and could be changed to:
>
> (last (re-split #"\." (name (ns-name *ns*

Those changes have been incorporated, along with stuff in the README
about validation.

I'm confused as to how I ended up with (first (reverse ...)) since I
remember looking at the doc for (last seq), but anyway, it's there
now.

-hume.
-- 
http://elhumidor.blogspot.com/

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2008-12-30 Thread Brian Doyle
I see what you are doing with the validations and defining them in the
init-modelcall.
I think that's a good idea actually and like it better than my solution to
putting the
callbacks in the model namespace.

A couple of small things that I noticed when starting to play around with
clj-record.  In your
example you have:

(ns com.example.user)
  (clj-record.core/init-model)

but when I do that I get the error:

java.lang.ClassNotFoundException: clj-record.core

When I add a require it clears it up like:

(ns com.example.user
  (:require [clj-record.core :as cr.core]))
   (cr.core/init-model)

I know this is picky, but in your clj-record.core/init-model function you
have:

(first (reverse (re-split #"\." (name (ns-name *ns*)

and could be changed to:

(last (re-split #"\." (name (ns-name *ns*

I look forward to seeing clj-record progress.   Thanks John.

On Mon, Dec 29, 2008 at 10:20 PM, John D. Hume wrote:

>
> On Mon, Dec 29, 2008 at 7:15 PM, Brian Doyle 
> wrote:
> > I noticed that in the init-model macro you are creating a 'defn table []
> > ...' function in the
> > model namespace and was wondering why you didn't just make it a def
> instead,
> > since
> > it doesn't take any args?
>
> That didn't occur to me. I do like the idea of all the functionality
> being available directly on clj-record.core with model name as a first
> argument in addition to being defined in the model namespace, so I
> guess that's one reason. But the inference of table name from model
> name should only be the default, so maybe it would be better to just
> def it there and let clj-record.core look it up there if needed,
> somewhat as you recommended doing for callbacks...
>
> > I have an idea for you with the callbacks like, before-create,
> after-create,
> > etc.  In the
> > all-models-metadata in the core.clj you could store the namespace in the
> > hash
> > associated with the model-name on setup.   Then in the create function
> > defined in
> > the core.clj you could call the before-create function defined in the
> model
> > something
> > like:
> >
> > (let-if [bc ('before-create (ns-publics )] (bc
> > attributes#))
>
> That's interesting. It's basically the opposite of the way I did the
> validation stuff, where you pass in validation functions and those get
> stored away in metadata and aren't directly accessible. (Here
> "metadata" is not used in the clojure.org/metadata sense of the word.
> I've thought about using clojure metadata to store model info, but I
> don't know what symbol or collection I'd attach it to.) I think I
> prefer the validation approach, because those functions have a certain
> job to do and shouldn't be sitting there cluttering the model
> namespace. (On the other hand, it is awfully convenient to be able to
> test those functions directly.)
>
> Thanks again for looking. If you or anyone else has further comments,
> I'd like to hear them.
> git clone git://github.com/duelinmarkers/clj-record.git
>
> -hume.
>
> --
> http://elhumidor.blogspot.com/
>
> >
>

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2008-12-29 Thread John D. Hume

On Mon, Dec 29, 2008 at 7:15 PM, Brian Doyle  wrote:
> I noticed that in the init-model macro you are creating a 'defn table []
> ...' function in the
> model namespace and was wondering why you didn't just make it a def instead,
> since
> it doesn't take any args?

That didn't occur to me. I do like the idea of all the functionality
being available directly on clj-record.core with model name as a first
argument in addition to being defined in the model namespace, so I
guess that's one reason. But the inference of table name from model
name should only be the default, so maybe it would be better to just
def it there and let clj-record.core look it up there if needed,
somewhat as you recommended doing for callbacks...

> I have an idea for you with the callbacks like, before-create, after-create,
> etc.  In the
> all-models-metadata in the core.clj you could store the namespace in the
> hash
> associated with the model-name on setup.   Then in the create function
> defined in
> the core.clj you could call the before-create function defined in the model
> something
> like:
>
> (let-if [bc ('before-create (ns-publics )] (bc
> attributes#))

That's interesting. It's basically the opposite of the way I did the
validation stuff, where you pass in validation functions and those get
stored away in metadata and aren't directly accessible. (Here
"metadata" is not used in the clojure.org/metadata sense of the word.
I've thought about using clojure metadata to store model info, but I
don't know what symbol or collection I'd attach it to.) I think I
prefer the validation approach, because those functions have a certain
job to do and shouldn't be sitting there cluttering the model
namespace. (On the other hand, it is awfully convenient to be able to
test those functions directly.)

Thanks again for looking. If you or anyone else has further comments,
I'd like to hear them.
git clone git://github.com/duelinmarkers/clj-record.git

-hume.

-- 
http://elhumidor.blogspot.com/

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2008-12-29 Thread Brian Doyle
That seems to be working better now John.   I looked over most of the code
and it seems
like a good start.  I'm no expert when it comes to functional programming or
Clojure,
so I'm not sure how to critic the code exactly.   If I was doing the porting
I would prolly
do it in very OO way, since that's what I'm used to, and that would not be
correct.

I noticed that in the init-model macro you are creating a 'defn table []
...' function in the
model namespace and was wondering why you didn't just make it a def instead,
since
it doesn't take any args?

I have an idea for you with the callbacks like, before-create, after-create,
etc.  In the
all-models-metadata in the core.clj you could store the namespace in the
hash
associated with the model-name on setup.   Then in the create function
defined in
the core.clj you could call the before-create function defined in the model
something
like:

(let-if [bc ('before-create (ns-publics )] (bc
attributes#))

That was just an idea I had, but there could be a better way to do it that's
for sure!
Of course it's prolly a bit more complex than that since you the
before-create function
could alter the attributes#, but you get the idea of discovering and calling
the
appropriate callback function in the model namespace.

On Sun, Dec 28, 2008 at 9:49 PM, John D. Hume wrote:

>
> Ok, please pull the latest and try again.
> git clone git://github.com/duelinmarkers/clj-record.git
>
> The problem was due to something I've seen a couple other messages
> about: When running a file as a script, it starts out in the
> clojure.core namespace. I was doing (def db {...}) before any (ns ...)
> so the db var lived in clojure.core, which made it conveniently (but
> sloppily) visible everywhere. Loading from the REPL, however, it was
> landing in the user namespace. I've now put it in a config namespace
> and required config from the two places that need it.
>
> Thanks for looking.
> -hume.
>
> On Sun, Dec 28, 2008 at 11:27 PM, John D. Hume 
> wrote:
> > The db configuration isn't reasonable at the moment. You can run
> > clj_record/test/main.clj as a script but not load it from the REPL.
> > Let me see if I can get it to work both ways and push an update.
> >
> > On Sun, Dec 28, 2008 at 6:28 PM, Brian Doyle 
> wrote:
> >> Having used Rails myself I wanted to check this out and play with it.
> I'm
> >> having some
> >> trouble just loading the clj_record/core.clj file though:
> >>
> >> 1:1 user=> (load-file "clj_record/core.clj")
> >> java.lang.Exception: Unable to resolve symbol: db in this context
> >> (core.clj:19)
> >>
> >> I'm sure it's something I'm doing wrong but I do have derby.jar on my
> >> classpath.  Thanks.
>
> >
>

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2008-12-28 Thread John D. Hume

Ok, please pull the latest and try again.
git clone git://github.com/duelinmarkers/clj-record.git

The problem was due to something I've seen a couple other messages
about: When running a file as a script, it starts out in the
clojure.core namespace. I was doing (def db {...}) before any (ns ...)
so the db var lived in clojure.core, which made it conveniently (but
sloppily) visible everywhere. Loading from the REPL, however, it was
landing in the user namespace. I've now put it in a config namespace
and required config from the two places that need it.

Thanks for looking.
-hume.

On Sun, Dec 28, 2008 at 11:27 PM, John D. Hume  wrote:
> The db configuration isn't reasonable at the moment. You can run
> clj_record/test/main.clj as a script but not load it from the REPL.
> Let me see if I can get it to work both ways and push an update.
>
> On Sun, Dec 28, 2008 at 6:28 PM, Brian Doyle  wrote:
>> Having used Rails myself I wanted to check this out and play with it.   I'm
>> having some
>> trouble just loading the clj_record/core.clj file though:
>>
>> 1:1 user=> (load-file "clj_record/core.clj")
>> java.lang.Exception: Unable to resolve symbol: db in this context
>> (core.clj:19)
>>
>> I'm sure it's something I'm doing wrong but I do have derby.jar on my
>> classpath.  Thanks.

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2008-12-28 Thread John D. Hume

The db configuration isn't reasonable at the moment. You can run
clj_record/test/main.clj as a script but not load it from the REPL.
Let me see if I can get it to work both ways and push an update.

On Sun, Dec 28, 2008 at 6:28 PM, Brian Doyle  wrote:
> Having used Rails myself I wanted to check this out and play with it.   I'm
> having some
> trouble just loading the clj_record/core.clj file though:
>
> 1:1 user=> (load-file "clj_record/core.clj")
> java.lang.Exception: Unable to resolve symbol: db in this context
> (core.clj:19)
>
> I'm sure it's something I'm doing wrong but I do have derby.jar on my
> classpath.  Thanks.
>
>
> On Sat, Dec 27, 2008 at 1:48 PM, John D. Hume 
> wrote:
>>
>> Hi all,
>> As a learning exercise, I've started working on a sort of clojure
>> clone of ActiveRecord (from Rails). You can see it here:
>> http://github.com/duelinmarkers/clj-record/tree/master
>>
>> The model used in the tests is defined in files here:
>>
>> http://github.com/duelinmarkers/clj-record/tree/master/clj_record/test/model
>>
>> And the tests most worth reading are:
>>
>> http://github.com/duelinmarkers/clj-record/tree/master/clj_record/test/core-test.clj
>>
>> http://github.com/duelinmarkers/clj-record/tree/master/clj_record/test/associations-test.clj
>>
>> I'd be interested in any feedback about issues you see, idioms I could
>> be using that I'm not, suggestions on testing approach, or other
>> comments or questions.
>>
>> One style question I'm particularly interested in is what people think
>> the model setup should look like. Currently I've got it implemented to
>> allow a minimum of punctuation:
>>
>> (cljrec/init-model
>>  (has-many products))
>>
>> But is it bad form to use the fact that macros don't evaluate
>> arguments to allow all those naked symbols? For consistency with ns it
>> seems it would be preferable to make has-many a keyword:
>>
>> (cljrec/init-model
>>  (:has-many products))
>>
>> (There actually is a has-many method that gets invoked by init-model,
>> but that's an implementation detail.)
>>
>> My gut says the least confusing approach for a user would be this.
>>
>> (cljrec/init-model
>>  (:has-many :products))
>>
>> ... but something seems weird to me about both :has-many and :products
>> being keywords, where :has-many is a magic keyword and :products is a
>> name being introduced. (Note it doesn't define a var called 'products
>> but does create 'find-products and 'destroy-products functions.)
>>
>> Note that I'm using clojure.contrib.sql and not worrying about the
>> constantly opening and closing connections. Obviously I'd need some
>> way of wrapping a single db transaction around a bunch of expressions
>> to make this a generally useful library. But that's not the point
>> right now.
>>
>> Thanks.
>> -hume.
>> --
>> http://elhumidor.blogspot.com/
>>
>>
>
>
> >
>



-- 
http://elhumidor.blogspot.com/

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Re: Some code review for clj-record?

2008-12-28 Thread Brian Doyle
Having used Rails myself I wanted to check this out and play with it.   I'm
having some
trouble just loading the clj_record/core.clj file though:

1:1 user=> (load-file "clj_record/core.clj")
java.lang.Exception: Unable to resolve symbol: db in this context
(core.clj:19)

I'm sure it's something I'm doing wrong but I do have derby.jar on my
classpath.  Thanks.


On Sat, Dec 27, 2008 at 1:48 PM, John D. Hume wrote:

>
> Hi all,
> As a learning exercise, I've started working on a sort of clojure
> clone of ActiveRecord (from Rails). You can see it here:
> http://github.com/duelinmarkers/clj-record/tree/master
>
> The model used in the tests is defined in files here:
>
> http://github.com/duelinmarkers/clj-record/tree/master/clj_record/test/model
>
> And the tests most worth reading are:
>
> http://github.com/duelinmarkers/clj-record/tree/master/clj_record/test/core-test.clj
>
> http://github.com/duelinmarkers/clj-record/tree/master/clj_record/test/associations-test.clj
>
> I'd be interested in any feedback about issues you see, idioms I could
> be using that I'm not, suggestions on testing approach, or other
> comments or questions.
>
> One style question I'm particularly interested in is what people think
> the model setup should look like. Currently I've got it implemented to
> allow a minimum of punctuation:
>
> (cljrec/init-model
>  (has-many products))
>
> But is it bad form to use the fact that macros don't evaluate
> arguments to allow all those naked symbols? For consistency with ns it
> seems it would be preferable to make has-many a keyword:
>
> (cljrec/init-model
>  (:has-many products))
>
> (There actually is a has-many method that gets invoked by init-model,
> but that's an implementation detail.)
>
> My gut says the least confusing approach for a user would be this.
>
> (cljrec/init-model
>  (:has-many :products))
>
> ... but something seems weird to me about both :has-many and :products
> being keywords, where :has-many is a magic keyword and :products is a
> name being introduced. (Note it doesn't define a var called 'products
> but does create 'find-products and 'destroy-products functions.)
>
> Note that I'm using clojure.contrib.sql and not worrying about the
> constantly opening and closing connections. Obviously I'd need some
> way of wrapping a single db transaction around a bunch of expressions
> to make this a generally useful library. But that's not the point
> right now.
>
> Thanks.
> -hume.
> --
> http://elhumidor.blogspot.com/
>
> >
>

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---



Some code review for clj-record?

2008-12-27 Thread John D. Hume

Hi all,
As a learning exercise, I've started working on a sort of clojure
clone of ActiveRecord (from Rails). You can see it here:
http://github.com/duelinmarkers/clj-record/tree/master

The model used in the tests is defined in files here:
http://github.com/duelinmarkers/clj-record/tree/master/clj_record/test/model

And the tests most worth reading are:
http://github.com/duelinmarkers/clj-record/tree/master/clj_record/test/core-test.clj
http://github.com/duelinmarkers/clj-record/tree/master/clj_record/test/associations-test.clj

I'd be interested in any feedback about issues you see, idioms I could
be using that I'm not, suggestions on testing approach, or other
comments or questions.

One style question I'm particularly interested in is what people think
the model setup should look like. Currently I've got it implemented to
allow a minimum of punctuation:

(cljrec/init-model
  (has-many products))

But is it bad form to use the fact that macros don't evaluate
arguments to allow all those naked symbols? For consistency with ns it
seems it would be preferable to make has-many a keyword:

(cljrec/init-model
  (:has-many products))

(There actually is a has-many method that gets invoked by init-model,
but that's an implementation detail.)

My gut says the least confusing approach for a user would be this.

(cljrec/init-model
  (:has-many :products))

... but something seems weird to me about both :has-many and :products
being keywords, where :has-many is a magic keyword and :products is a
name being introduced. (Note it doesn't define a var called 'products
but does create 'find-products and 'destroy-products functions.)

Note that I'm using clojure.contrib.sql and not worrying about the
constantly opening and closing connections. Obviously I'd need some
way of wrapping a single db transaction around a bunch of expressions
to make this a generally useful library. But that's not the point
right now.

Thanks.
-hume.
-- 
http://elhumidor.blogspot.com/

--~--~-~--~~~---~--~~
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
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
-~--~~~~--~~--~--~---