Domanda

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?

È stato utile?

Soluzione

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.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top