Ejemplo n.º 1
0
    def create_schema(self,
                      hash_key_name,
                      hash_key_proto_value,
                      range_key_name=None,
                      range_key_proto_value=None):
        """
        Create a Schema object used when creating a Table.

        :type hash_key_name: str
        :param hash_key_name: The name of the HashKey for the schema.

        :type hash_key_proto_value: int|long|float|str|unicode|Binary
        :param hash_key_proto_value: A sample or prototype of the type
            of value you want to use for the HashKey.  Alternatively,
            you can also just pass in the Python type (e.g. int, float, etc.).

        :type range_key_name: str
        :param range_key_name: The name of the RangeKey for the schema.
            This parameter is optional.

        :type range_key_proto_value: int|long|float|str|unicode|Binary
        :param range_key_proto_value: A sample or prototype of the type
            of value you want to use for the RangeKey.  Alternatively,
            you can also pass in the Python type (e.g. int, float, etc.)
            This parameter is optional.
        """
        hash_key = (hash_key_name, get_dynamodb_type(hash_key_proto_value))
        if range_key_name and range_key_proto_value is not None:
            range_key = (range_key_name,
                         get_dynamodb_type(range_key_proto_value))
        else:
            range_key = None
        return Schema.create(hash_key, range_key)
Ejemplo n.º 2
0
    def create_schema(self, hash_key_name, hash_key_proto_value,
                      range_key_name=None, range_key_proto_value=None):
        """
        Create a Schema object used when creating a Table.

        :type hash_key_name: str
        :param hash_key_name: The name of the HashKey for the schema.

        :type hash_key_proto_value: int|long|float|str|unicode|Binary
        :param hash_key_proto_value: A sample or prototype of the type
            of value you want to use for the HashKey.  Alternatively,
            you can also just pass in the Python type (e.g. int, float, etc.).

        :type range_key_name: str
        :param range_key_name: The name of the RangeKey for the schema.
            This parameter is optional.

        :type range_key_proto_value: int|long|float|str|unicode|Binary
        :param range_key_proto_value: A sample or prototype of the type
            of value you want to use for the RangeKey.  Alternatively,
            you can also pass in the Python type (e.g. int, float, etc.)
            This parameter is optional.
        """
        hash_key = (hash_key_name, get_dynamodb_type(hash_key_proto_value))
        if range_key_name and range_key_proto_value is not None:
            range_key = (range_key_name,
                         get_dynamodb_type(range_key_proto_value))
        else:
            range_key = None
        return Schema.create(hash_key, range_key)
Ejemplo n.º 3
0
	def _connect(self):
		args = dict(aws_access_key_id=self.db_user,
					aws_secret_access_key=self.db_passwd,
					is_secure=self.enable_ssl)
		try:
			region = [x for x in boto.dynamodb.regions() if x.endpoint == self.db_host][0]
			args['region'] = region
		except IndexError:
			pass
		self._dynamodb = boto.connect_dynamodb(**args)
		# Look up or create a new table for this item
		try:
			self._table = self._dynamodb.lookup(self.db_name)
		except boto.exception.DynamoDBResponseError:
			self._table = None
		if not self._table:
			from boto.dynamodb.schema import Schema
			self._table = self._dynamodb.create_table(
				name=self.db_name,
				schema=Schema.create(hash_key=('__id__', 'S')),
				read_units=1,
				write_units=1)
			while self._table.status == 'CREATING':
				time.sleep(1)
				self._table.refresh()
Ejemplo n.º 4
0
 def setUp(self):
     self.dynamodb = Layer2()
     self.schema = Schema.create(('foo', 'N'), ('bar', 'S'))
     self.table_name = 'testtable%s' % int(time.time())
Ejemplo n.º 5
0
 def _get_schema(self):
     from boto.dynamodb.schema import Schema
     return Schema.create(
         hash_key=('client_id', 'S'),
         range_key=('ts', 'N'))
Ejemplo n.º 6
0
 def setUp(self):
     self.dynamodb = Layer2()
     self.schema = Schema.create(('foo', 'N'), ('bar', 'S'))
     self.table_name = 'testtable%s' % int(time.time())