コード例 #1
0
    def create(self, attributes, key_map=None, transform_map=None):
        """Create a new record.

        Args:
            attributes: dict of attributes and their values.
            key_map: dict that maps keys in attributes to attribute dot-paths
            transform_map: dict that maps keys in attributes to transform functions

        Returns:
            dict containing id and uuid of new record
        """
        if key_map:
            attributes = to_capture_record(attributes, key_map, transform_map)

        kwargs = {
            'type_name': self.schema_name,
            'attributes': attributes,
        }
        r = self.app.apicall('entity.create', **kwargs)
        self._id_attribute = 'uuid'
        self._id_value = r['uuid']

        return {
            'id': r['id'],
            'uuid': r['uuid'],
        }
コード例 #2
0
    def update(self,
               attributes,
               attribute_path=None,
               key_map=None,
               transform_map=None):
        """Update record.

        Args:
            attributes: dict of attributes and their values.
            attribute_path: path to a subset of record attributes to update
            key_map: dict that maps keys in attributes to attribute dot-paths
            transform_map: dict that maps keys in attributes to transform functions
        """
        if key_map:
            attributes = to_capture_record(attributes, key_map, transform_map)

        kwargs = {
            'type_name': self.schema_name,
            'key_attribute': self.id_attribute,
            # must be a "JSON" string
            'key_value': '"{}"'.format(self.id_value),
            'attributes': attributes,
        }
        if attribute_path is not None:
            kwargs['attribute_name'] = attribute_path
        self.app.apicall('entity.update', **kwargs)
コード例 #3
0
    def replace(self,
                attributes,
                attribute_path=None,
                key_map=None,
                transform_map=None):
        """Replace record.
        Warning: attributes not specified will be set to null,
            plurals not specified will be deleted.

        Args:
            attributes: dict of attributes and their values.
            attribute_path: path to a subset of record attributes to replace
            key_map: dict that maps keys in attributes to attribute dot-paths
            transform_map: dict that maps keys in attributes to transform functions
        """
        if key_map:
            attributes = to_capture_record(attributes, key_map, transform_map)

        kwargs = {
            'type_name': self.schema_name,
            'key_attribute': self.id_attribute,
            # must be a "JSON" string
            'key_value': '"{}"'.format(self.id_value),
            'attributes': attributes,
        }
        if attribute_path is not None:
            kwargs['attribute_name'] = attribute_path
        self.app.apicall('entity.replace', **kwargs)
コード例 #4
0
    def create(self, attributes, key_map=None, transform_map=None):
        """Create a new record.

        Args:
            attributes: dict of attributes and their values.
            key_map: dict that maps keys in attributes to attribute dot-paths
            transform_map: dict that maps keys in attributes to transform functions

        Returns:
            dict containing id and uuid of new record
        """
        if key_map:
            attributes = to_capture_record(attributes, key_map, transform_map)

        kwargs = {
            'type_name': self.schema_name,
            'attributes': attributes,
        }
        r = self.app.apicall('entity.create', **kwargs)
        self._id_attribute = 'uuid'
        self._id_value = r['uuid']

        return {
            'id': r['id'],
            'uuid': r['uuid'],
        }
コード例 #5
0
    def update(self, attributes, attribute_path=None, key_map=None, transform_map=None):
        """Update record.

        Args:
            attributes: dict of attributes and their values.
            attribute_path: path to a subset of record attributes to update
            key_map: dict that maps keys in attributes to attribute dot-paths
            transform_map: dict that maps keys in attributes to transform functions
        """
        if key_map:
            attributes = to_capture_record(attributes, key_map, transform_map)

        kwargs = {
            'type_name': self.schema_name,
            'key_attribute': self.id_attribute,
            # must be a "JSON" string
            'key_value': '"{}"'.format(self.id_value),
            'attributes': attributes,
        }
        if attribute_path is not None:
            kwargs['attribute_name'] = attribute_path
        self.app.apicall('entity.update', **kwargs)
コード例 #6
0
    def replace(self, attributes, attribute_path=None, key_map=None, transform_map=None):
        """Replace record.
        Warning: attributes not specified will be set to null,
            plurals not specified will be deleted.

        Args:
            attributes: dict of attributes and their values.
            attribute_path: path to a subset of record attributes to replace
            key_map: dict that maps keys in attributes to attribute dot-paths
            transform_map: dict that maps keys in attributes to transform functions
        """
        if key_map:
            attributes = to_capture_record(attributes, key_map, transform_map)

        kwargs = {
            'type_name': self.schema_name,
            'key_attribute': self.id_attribute,
            # must be a "JSON" string
            'key_value': '"{}"'.format(self.id_value),
            'attributes': attributes,
        }
        if attribute_path is not None:
            kwargs['attribute_name'] = attribute_path
        self.app.apicall('entity.replace', **kwargs)