Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create a unique property in python on google app engine?

In some database technologies, for a attribute in a record, you can guarantee uniqueness of that attribute within the entire database. An example of this might be a email_address attribute in a User record. By setting email_address to unique, you guarantee that a particular email address can only appear in one record in the entire database.

Is there any way in google app engine to have unique properties for a given model? As a example, could I have a User(db.Model) entity with a email property that is guaranteed unique across the entire datastore?

I found this resource here, which might prove helpful.

like image 967
Stephen Cagle Avatar asked Sep 14 '26 05:09

Stephen Cagle


1 Answers

The only help you get from GAE's datastore regarding "uniqueness" is via entities' keys -- but then, I see the URL you quote also noticed that and shows one way to exploit this fact. To get anywhere beyond keys, you need to perform your checks at application level (before you put an entity, or a change to a unique set of properties, you make a suitable query [[key-only for speed]] and check that it comes up empty), but that gets pretty costly (and hard to make transaction-safe).

like image 77
Alex Martelli Avatar answered Sep 15 '26 19:09

Alex Martelli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!