This module offers an ORM-like layer on top of SimpleDB.
Returns the appropriate Manager class for a given Model class. It does this by looking in the boto config for a section like this:
[DB]
db_type = SimpleDB
db_user = <aws access key id>
db_passwd = <aws secret access key>
db_name = my_domain
[DB_TestBasic]
db_type = SimpleDB
db_user = <another aws access key id>
db_passwd = <another aws secret access key>
db_name = basic_domain
db_port = 1111
The values in the DB section are “generic values” that will be used if nothing more specific is found. You can also create a section for a specific Model class that gives the db info for that class. In the example above, TestBasic is a Model subclass.
Note
This module requires psycopg2 to be installed in the Python path.
Responsible for converting base Python types to format compatible with underlying database. For SimpleDB, that means everything needs to be converted to a string when stored in SimpleDB and from a string when retrieved.
To convert a value, pass it to the encode or decode method. The encode method will take a Python native value and convert to DB format. The decode method will take a DB format value and convert it to Python native format. To find the appropriate method to call, the generic encode/decode methods will look for the type-specific method by searching for a method called”encode_<type name>” or “decode_<type name>”.
Handles both Dates and DateTime objects
Decode a single element for a map
Decoding a string is really nothing, just return the value as-is
converts strings in the form of HH:MM:SS.mmmmmm (created by datetime.time.isoformat()) to datetime.time objects.
Timzone-aware strings (“HH:MM:SS.mmmmmm+HH:MM”) won’t be handled right now and will raise TimeDecodeError.
Convert ASCII, Latin-1 or UTF-8 to pure Unicode
Get the number of results that would be returned in this query
Responsible for converting base Python types to format compatible with underlying database. For SimpleDB, that means everything needs to be converted to a string when stored in SimpleDB and from a string when retrieved.
To convert a value, pass it to the encode or decode method. The encode method will take a Python native value and convert to DB format. The decode method will take a DB format value and convert it to Python native format. To find the appropriate method to call, the generic encode/decode methods will look for the type-specific method by searching for a method called “encode_<type name>” or “decode_<type name>”.
Pull out the properties from this document Returns the class, the properties in a hash, and the id if provided as a tuple :return: (cls, props, id)
Marshal the object and do a PUT
Same as unmarshalling an object, except it returns from “get_props_from_doc”
Delete just these attributes, not the whole object.
Parameters: | attrs (list) – Attributes to save, as a list of string names |
---|---|
Returns: | self |
Return type: | boto.sdb.db.model.Model |
Find a subclass with a given name
Save this object as it is, with an optional expected value
Parameters: | expected_value (tuple or list) – Optional tuple of Attribute, and Value that must be the same in order to save this object. If this condition is not met, an SDBResponseError will be raised with a Confict status code. |
---|---|
Returns: | This object |
Return type: | boto.sdb.db.model.Model |
Save just these few attributes, not the whole object
Parameters: | attrs (dict) – Attributes to save, key->value dict |
---|---|
Returns: | self |
Return type: | boto.sdb.db.model.Model |
Save this object as it is, with an optional expected value
Parameters: | expected_value (tuple or list) – Optional tuple of Attribute, and Value that must be the same in order to save this object. If this condition is not met, an SDBResponseError will be raised with a Confict status code. |
---|---|
Returns: | This object |
Return type: | boto.sdb.db.model.Model |
Save just these few attributes, not the whole object
Parameters: | attrs (dict) – Attributes to save, key->value dict |
---|---|
Returns: | self |
Return type: | boto.sdb.db.model.Model |
Metaclass for all Models
This class handles both the datetime.datetime object And the datetime.date objects. It can return either one, depending on the value stored in the database
Hashed property whose original value can not be retrieved, but still can be compared.
Works by storing a hash of the original value instead of the original value. Once that’s done all that can be retrieved is the hash.
The comparison
obj.password == ‘foo’
generates a hash of ‘foo’ and compares it to the stored hash.
Underlying data type for hashing, storing, and comparing is boto.utils.Password. The default hash function is defined there ( currently sha512 in most cases, md5 where sha512 is not available )
It’s unlikely you’ll ever need to use a different hash function, but if you do, you can control the behavior in one of two ways:
Specifying hashfunc in PasswordProperty constructor
import hashlib
- class MyModel(model):
password = PasswordProperty(hashfunc=hashlib.sha224)
Subclassing Password and PasswordProperty
- class SHA224Password(Password):
hashfunc=hashlib.sha224
- class SHA224PasswordProperty(PasswordProperty):
data_type=MyPassword type_name=”MyPassword”
- class MyModel(Model):
password = SHA224PasswordProperty()
Not currently fully supported, but we can use this to allow them to set a limit in a chainable method