示例#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']
示例#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']
示例#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
示例#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
示例#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
示例#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)
示例#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
示例#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)
 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
示例#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)
示例#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