[Grok-dev] ZODB and storing, retrieving, deleting, use of ID
Kevin Teague
kevin at bud.ca
Fri Oct 10 23:15:19 EDT 2008
When doing autogeneration of primary keys in a relational database,
there is usually a separate Sequence object which tracks the value of
the next id to use, when a new record is inserted the Sequence object
is updated by one. It's possible to implement this directly in Grok,
but Laurences suggestions of randomised keys for efficiency may be
preferable.
Note that there is a subtle difference between a database id and a key
name (available as the __name__ attribute on a Grok model object) when
storing data in the ZODB using Grok. A database id is a unique
identifier that is user-friendly for inclusion in SQL statements. A
name is used a unique identifier that is user-friendly for inclusion
in a URL.
When composing a URL in Grok, names are not allowed to start with the
+ or @ characters, not contain the / character (you can store objects
in the ZODB with key names that don't obey these rules, but then when
you want to publish that key name using the normal Grok behaviour you
will have to do some form of messy "fuggling" to get it to work).
Names are often made more human-readable, although what "more human-
readable" is may depend on the type of app you are writing, but in a
CMS, a URL such as:
http://example.com/using-name-choosers.html
Is more human-readable than:
http://example.com/4876598465876497.html
I just put a note about using the INameChooser interface in this
recent article:
http://grok.zope.org/documentation/how-to/uploading-file/view
However, a full discussion on implementing INameChoosers to implement
your desired naming policies (randomized, length based, human-readable-
style.html, etc.) and potentially some packages which have useful
NameChoosers) doesn't exist, but would be good to have ...
More information about the Grok-dev
mailing list