From: Roby Sadeli on
Hi lispers!

I have been tinkering with cl-elephant and I have a question:
How do I create unique key with elephant objects?

(defpclass book ()
((isbn :initarg :isbn
:accessor isbn
:index t)
(title :initarg :title
:accessor title
:index t)
(author :initarg :author
:accessor author
:index t)))

I know that there is oid (object id) for every object but what if I
want isbn to be unique? Do I have to check on my objects before
creating a new one?

Thanks for your help.
From: Alex Mizrahi on
RS> I know that there is oid (object id) for every object but what if I
RS> want isbn to be unique? Do I have to check on my objects before
RS> creating a new one?

Um, yes, I think you should do that check yourself. What to do in case of
non-unique keys is application-dependent, and so you need to implement a
reaction to it yourself anyway.

From: Roby Sadeli on
On Mar 13, 11:16 pm, "Alex Mizrahi" <udode...(a)users.sourceforge.net>
wrote:
>  RS> I know that there is oid (object id) for every object but what if I
>  RS> want isbn to be unique? Do I have to check on my objects before
>  RS> creating a new one?
>
> Um, yes, I think you should do that check yourself. What to do in case of
> non-unique keys is application-dependent, and so you need to implement a
> reaction to it yourself anyway.

Hi Alex. Thanks for your reply.
So I have to create a function (for example isbn-exists?) to check
whether a certain ISBN is already in the database, cl-elephant could
not do this automatically. I just find it strange to have to do this
manually.
From: Nicolas Neuss on
"Alex Mizrahi" <udodenko(a)users.sourceforge.net> writes:

> RS> I know that there is oid (object id) for every object but what if I
> RS> want isbn to be unique? Do I have to check on my objects before
> RS> creating a new one?
>
> Um, yes, I think you should do that check yourself. What to do in case of
> non-unique keys is application-dependent, and so you need to implement a
> reaction to it yourself anyway.

Throwing CFFI out of my asdf-registry in favor of UFFI, I succeeded in
making Elephant work, and very soon I also missed that feature
(especially since I am a used to CLSQL where one can enforce this with
":db-kind :key" in the slot definition).

As a remedy, I inserted such a test for uniqueness in the
initialize-instance method as follows:

(defmethod initialize-instance :before
((ml ele-mailing-list) &key name &allow-other-keys)
...
(assert (null (find-ele-ml name)) () "This list already exists"))

Having a ":db-kind :key" slot option would make such kind of tests
superfluous and indicate intent as early as possible, and this I would
like. OTOH, since CLOS itself does not have this feature, I do not
consider it a necessesity for Elephant.

Nicolas

From: Roby Sadeli on
On Mar 14, 4:10 am, Nicolas Neuss <lastn...(a)kit.edu> wrote:
> "Alex Mizrahi" <udode...(a)users.sourceforge.net> writes:
> > RS> I know that there is oid (object id) for every object but what if I
> > RS> want isbn to be unique? Do I have to check on my objects before
> > RS> creating a new one?
>
> > Um, yes, I think you should do that check yourself. What to do in case of
> > non-unique keys is application-dependent, and so you need to implement a
> > reaction to it yourself anyway.
>
> Throwing CFFI out of my asdf-registry in favor of UFFI, I succeeded in
> making Elephant work, and very soon I also missed that feature
> (especially since I am a used to CLSQL where one can enforce this with
> ":db-kind :key" in the slot definition).
>
> As a remedy, I inserted such a test for uniqueness in the
> initialize-instance method as follows:
>
> (defmethod initialize-instance :before
>     ((ml ele-mailing-list) &key name &allow-other-keys)
>   ...
>   (assert (null (find-ele-ml name)) () "This list already exists"))
>
> Having a ":db-kind :key" slot option would make such kind of tests
> superfluous and indicate intent as early as possible, and this I would
> like.  OTOH, since CLOS itself does not have this feature, I do not
> consider it a necessesity for Elephant.
>
> Nicolas

Hi Nicolas,

Thanks for giving me a hint about using initialize-instance :before to
check whether a key is in the database. That solves my question.
I am a newbie, and I learn by looking at simple example codes and I
just think cl-elephant example codes out there are a rare.

Cheers.
 |  Next  |  Last
Pages: 1 2
Prev: Configuration file setup and pathname usage
Next: wxcl