Example #1
0
 def _update_graph_cache(self):
     """Invalidate the graph cache."""
     real_graphs = set(self.graphs)
     cached_graphs = set(self._graph_cache)
     for graph_name in cached_graphs - real_graphs:
         del self._graph_cache[graph_name]
     for graph_name in real_graphs - cached_graphs:
         self._graph_cache[graph_name] = Graph(name=graph_name,
                                               api=self.api)
Example #2
0
    def graph(self, name):
        """Return the graph object.

        :param name: the name of the graph
        :type name: str | unicode
        :returns: the requested graph object
        :rtype: arango.graph.Graph
        """
        return Graph(self._conn, name)
Example #3
0
    def graph(self, name):
        """Return the graph object tailored for batch execution.

        API requests via the returned object are placed in an in-memory queue
        and committed as a whole in a single HTTP call to the ArangoDB server.

        :param name: the name of the graph
        :type name: str
        :returns: the graph object
        :rtype: arango.graph.Graph
        """
        return Graph(self, name)
Example #4
0
    def graph(self, name):
        """Return a graph object tailored for asynchronous execution.

        API requests via the returned graph object are placed in a server-side
        in-memory task queue and executed asynchronously in a fire-and-forget
        style.

        :param name: the name of the graph
        :type name: str | unicode
        :returns: the graph object
        :rtype: arango.graph.Graph
        """
        return Graph(self, name)
Example #5
0
    def create_graph(self,
                     name,
                     edge_definitions=None,
                     orphan_collections=None):
        """Create a new graph in the database.

        An edge definition should look like this:

        .. code-block:: python

            {
                'name': 'edge_collection_name',
                'from_collections': ['from_vertex_collection_name'],
                'to_collections': ['to_vertex_collection_name']
            }

        :param name: name of the new graph
        :type name: str | unicode
        :param edge_definitions: list of edge definitions
        :type edge_definitions: list
        :param orphan_collections: names of additional vertex collections
        :type orphan_collections: list
        :returns: the graph object
        :rtype: arango.graph.Graph
        :raises arango.exceptions.GraphCreateError: if the graph cannot be
            created in the database
        """
        data = {'name': name}
        if edge_definitions is not None:
            data['edgeDefinitions'] = [{
                'collection': definition['name'],
                'from': definition['from_collections'],
                'to': definition['to_collections']
            } for definition in edge_definitions]
        if orphan_collections is not None:
            data['orphanCollections'] = orphan_collections

        res = self._conn.post('/_api/gharial', data=data)
        if res.status_code not in HTTP_OK:
            raise GraphCreateError(res)
        return Graph(self._conn, name)
Example #6
0
    def create_graph(self,
                     name,
                     edge_definitions=None,
                     orphan_collections=None,
                     smart=None,
                     smart_field=None,
                     shard_count=None):
        """Create a new graph in the database.

        An edge definition should look like this:

        .. code-block:: python

            {
                'name': 'edge_collection_name',
                'from_collections': ['from_vertex_collection_name'],
                'to_collections': ['to_vertex_collection_name']
            }

        :param name: The name of the new graph.
        :type name: str | unicode
        :param edge_definitions: The list of edge definitions.
        :type edge_definitions: list
        :param orphan_collections: The names of additional vertex collections.
        :type orphan_collections: list
        :param smart: Whether or not the graph is smart. Set this to ``True``
            to enable sharding (see parameter **smart_field** below). This
            parameter only has an effect for the enterprise version of ArangoDB.
        :type smart: bool
        :param smart_field: The document field used to shard the vertices of
            the graph. To use this option, parameter **smart** must be set to
            ``True`` and every vertex in the graph must contain the smart field.
        :type smart_field: str | unicode
        :param shard_count: The number of shards used for every collection in
            the graph. To use this option, parameter **smart** must be set to
            ``True`` and every vertex in the graph must contain the smart field.
            This number cannot be modified later once set.
        :type shard_count: int
        :returns: the graph object
        :rtype: arango.graph.Graph
        :raises arango.exceptions.GraphCreateError: if the graph cannot be
            created in the database
        """
        data = {'name': name}
        if edge_definitions is not None:
            data['edgeDefinitions'] = [{
                'collection': definition['name'],
                'from': definition['from_collections'],
                'to': definition['to_collections']
            } for definition in edge_definitions]
        if orphan_collections is not None:
            data['orphanCollections'] = orphan_collections
        if smart is not None:  # pragma: no cover
            data['isSmart'] = smart
        if smart_field is not None:  # pragma: no cover
            data['smartGraphAttribute'] = smart_field
        if shard_count is not None:  # pragma: no cover
            data['numberOfShards'] = shard_count

        res = self._conn.post('/_api/gharial', data=data)
        if res.status_code not in HTTP_OK:
            raise GraphCreateError(res)
        return Graph(self._conn, name)