unique key/attribute/property in zodb

Very simple senario:

class User(Persistent):
  def __init__(self, username, email):
    self.username = username
    self.email = email

I want to store the User instances in zodb by its username while keeping email unique.

u1 = User(username="u1",email="u1@example.com")
zodb_container[u1.username] = u1

I use the username as key to store this object, so it will be unique. My question is how to keep the email attribute unique? Is there any elegant way to do this in an object database?

Answers


No.

ZODB is somewhat misnamed. It's not a "database" like Postgres or MySQL is a database that has constraints and a query language and all that stuff that people presume a database has. It's, instead, a persistent object store. There's nothing that ZODB does for you that Python's pickle module doesn't do for you except manage working sets that are larger than available memory, handle transactions, and allow you to share object representations between processes. It's in effect "superpickle".

So your answer wouldn't be any different than if you had asked the same question about pickle, really.


Need Your Help

how to search goosh.org from the command line?

bash shell command-line sh command-line-interface

I'd like to write a simple bash script to search goosh.org from the command line and open the results in a browser. (Or maybe you wouldn't even call this a bash script at all since all it does is m...

Anything wrong with adding the PUT,DELETE verbs to the .aspx extension in IIS?

asp.net ajax iis

I'm using PUT and DELETE more and more w/ my ajax work and wanted to see if it would be a "bad idea" to add these verbs to the .aspx application extension in IIS.