Esempio n. 1
0
def save_entity(connection, model, data):
    domain_name = domain_for_model(model)
    manager = connection.create_manager(domain_name)
    attrs = {
        '__type__': domain_name,
    }
    attrs.update(data)
    if not attrs.has_key('_id'):
        # New item. Generate an ID.
        attrs['_id'] = uuid.uuid4().int
    domain = Domain(name=domain_name, connection=manager.sdb)
    domain.put_attributes(attrs['_id'], attrs, replace=True)
    return attrs['_id']
Esempio n. 2
0
def save_entity(connection, model, data):
    domain_name = domain_for_model(model)
    manager = connection.create_manager(domain_name)
    attrs = {
        '__type__': domain_name,
    }
    attrs.update(data)
    if not attrs.has_key('_id'):
        # New item. Generate an ID.
        attrs['_id'] = uuid.uuid4().int
    domain = Domain(name=domain_name, connection=manager.sdb)
    domain.put_attributes(attrs['_id'], attrs, replace=True)
    return attrs['_id']
Esempio n. 3
0
 def get_item(self, item_name):
     """Uses `consistent_read` by default."""
     # Domain is an old-style class, can't use super().
     for consistent_read in (False, True):
         item = Domain.get_item(self, item_name, consistent_read)
         if item:
             return item
Esempio n. 4
0
 def get_item(self, item_name):
     """Uses `consistent_read` by default."""
     # Domain is an old-style class, can't use super().
     for consistent_read in (False, True):
         item = Domain.get_item(self, item_name, consistent_read)
         if item:
             return item
Esempio n. 5
0
 def __new__(self, id, **params):
     domain_name = domain_for_model(self.model_class)
     domain = Domain(name=domain_name, connection=manager.sdb)
     item = Item(domain, id)
     params['_id'] = id
     item.update(params)
     return item
Esempio n. 6
0
 def select(self,
            query='',
            next_token=None,
            consistent_read=True,
            max_items=None):
     """Uses `consistent_read` by default."""
     query = """SELECT * FROM `%s` %s""" % (self.name, query)
     return Domain.select(self, query, next_token, consistent_read,
                          max_items)
Esempio n. 7
0
    def get_domain(self, domain_name, validate=True):
        """
        Retrieves a :py:class:`boto.sdb.domain.Domain` object whose name
        matches ``domain_name``.

        :param str domain_name: The name of the domain to retrieve
        :keyword bool validate: When ``True``, check to see if the domain
            actually exists. If ``False``, blindly return a
            :py:class:`Domain <boto.sdb.domain.Domain>` object with the
            specified name set.

        :raises:
            :py:class:`boto.exception.SDBResponseError` if ``validate`` is
            ``True`` and no match could be found.

        :rtype: :py:class:`boto.sdb.domain.Domain`
        :return: The requested domain
        """
        domain = Domain(self, domain_name)
        if validate:
            self.select(domain, """select * from `%s` limit 1""" % domain_name)
        return domain
Esempio n. 8
0
 def select(self, query='', next_token=None,
            consistent_read=True, max_items=None):
     """Uses `consistent_read` by default."""
     query = """SELECT * FROM `%s` %s""" % (self.name, query)
     return Domain.select(self, query, next_token,
                          consistent_read, max_items)
Esempio n. 9
0
 def get_domain(self, domain_name, validate=True):
     domain = Domain(self, domain_name)
     if validate:
         self.select(domain, """select * from `%s` limit 1""" % domain_name)
     return domain
Esempio n. 10
0
 def delete(self):
     items = dict([(e['_id'], None) for e in self.fetch_infinite(0)])
     domain = Domain(name=domain_for_model(self.model),
                     connection=self.manager.sdb)
     return domain.batch_delete_attributes(items)
Esempio n. 11
0
 def get_domain(self, domain_name, validate=True):
     domain = Domain(self, domain_name)
     if validate:
         self.query(domain, '', max_items=1)
     return domain