[cl-dwim-devel] Adding the concept of a natural key to perec

Kambiz Darabi darabi at m-creations.com
Tue Jun 25 17:17:21 UTC 2013


Hi,

I have the need to specify one or more natural keys [1] for a persistent
class. Attached is a patch which should illustrate what I would like to
achieve. The natural key is defined by slot names and is eventually
exported to the DB as a unique index.

I haven't yet decided whether one natural key per pclass is
sufficient. If I stick with multiple keys, then I would probably add a
name to them, such as

(def persistent-class person ()
  ((name ..)
   (dob ...)
   (social-security-number ...)
   (some-number ...))
  (:natural-key 'ssn (social-security-number))
  (:natural-key 'name-some-number (name some-number)))


It would also be convenient to create some find-person-by-ssn or
find-person-by-name-some-number functions.

What is definitely flakey in this patch is the fact that the slot is
first used to keep the names of the slots as symbols, and later in
export-to-rdbms, after finalisation of the class, the slot value is
replaced by a list of the slots. Any hint on how to improve this is
appreciated.

Can you please review the patch and give some feedback?

Thanks


Kambiz

[1] http://en.wikipedia.org/wiki/Natural_key

-------------- next part --------------
A non-text attachment was scrubbed...
Name: 0001-Extended-option-natural-key-for-defpclass.patch
Type: text/x-diff
Size: 6546 bytes
Desc: not available
URL: <https://mailman.common-lisp.net/pipermail/cl-dwim-devel/attachments/20130625/a69a9fe2/attachment.patch>


More information about the cl-dwim-devel mailing list