Beispiel #1
0
    def properties(self):
        """Return the properties of this collection.

        :returns: the collection's id, status, key_options etc.
        :rtype: dict
        :raises: CollectionGetError
        """
        res = self.api.get(
            "/_api/collection/{}/properties".format(self.name)
        )
        if res.status_code not in HTTP_OK:
            raise CollectionGetError(res)
        return {
            "id": res.obj["id"],
            "name": res.obj["name"],
            "is_edge": res.obj["type"] == 3,
            "status": COLLECTION_STATUSES.get(
                res.obj["status"],
                "corrupted ({})".format(res.obj["status"])
            ),
            "do_compact": res.obj["doCompact"],
            "is_system": res.obj["isSystem"],
            "is_volatile": res.obj["isVolatile"],
            "journal_size": res.obj["journalSize"],
            "wait_for_sync": res.obj["waitForSync"],
            "key_options": uncamelify(res.obj["keyOptions"])
        }
Beispiel #2
0
    def properties(self):
        """Return the properties of this collection.

        :returns: the collection's id, status, key_options etc.
        :rtype: dict
        :raises: CollectionGetError
        """
        res = self.api.get("/_api/collection/{}/properties".format(self.name))
        if res.status_code not in HTTP_OK:
            raise CollectionGetError(res)
        return {
            "id":
            res.body["id"],
            "name":
            res.body["name"],
            "is_edge":
            res.body["type"] == 3,
            "status":
            COLLECTION_STATUSES.get(
                res.body["status"],
                "corrupted ({})".format(res.body["status"])),
            "do_compact":
            res.body["doCompact"],
            "is_system":
            res.body["isSystem"],
            "is_volatile":
            res.body["isVolatile"],
            "journal_size":
            res.body["journalSize"],
            "wait_for_sync":
            res.body["waitForSync"],
            "key_options":
            uncamelify(res.body["keyOptions"])
        }
Beispiel #3
0
    def explain_query(self,
                      query,
                      all_plans=False,
                      max_plans=None,
                      optimizer_rules=None):
        """Explain the AQL query.

        This method does not execute the query, but only inspect it and
        return meta information about it.

        If ``all_plans`` is set to True, all possible execution plans are
        returned. Otherwise only the optimal plan is returned.

        For more information on optimizer_rules, please refer to:
        https://docs.arangodb.com/HttpAqlQuery/README.html

        :param query: the AQL query to explain
        :type query: str
        :param all_plans: whether or not to return all execution plans
        :type all_plans: bool
        :param max_plans: maximum number of plans the optimizer generates
        :type max_plans: None or int
        :param optimizer_rules: list of optimizer rules
        :type optimizer_rules: list
        :returns: the query plan or list of plans (if all_plans is True)
        :rtype: dict or list
        :raises: AQLQueryExplainError
        """
        options = {"allPlans": all_plans}
        if max_plans is not None:
            options["maxNumberOfPlans"] = max_plans
        if optimizer_rules is not None:
            options["optimizer"] = {"rules": optimizer_rules}
        res = self.api.post("/_api/explain",
                            data={
                                "query": query,
                                "options": options
                            })
        if res.status_code not in HTTP_OK:
            raise AQLQueryExplainError(res)
        if "plan" in res.obj:
            return uncamelify(res.obj["plan"])
        else:
            return uncamelify(res.obj["plans"])
Beispiel #4
0
    def properties(self):
        """Return all properties of this database.

        :returns: the database properties
        :rtype: dict
        :raises: DatabasePropertyError
        """
        res = self.api.get("/_api/database/current")
        if res.status_code not in HTTP_OK:
            raise DatabasePropertyError(res)
        return uncamelify(res.obj["result"])
Beispiel #5
0
    def statistics(self):
        """Return the statistics of this collection.

        :returns: the statistics of this collection
        :rtype: dict
        :raises: CollectionGetError
        """
        res = self.api.get("/_api/collection/{}/figures".format(self.name))
        if res.status_code not in HTTP_OK:
            raise CollectionGetError(res)
        return uncamelify(res.body["figures"])
Beispiel #6
0
    def properties(self):
        """Return all properties of this database.

        :returns: the database properties
        :rtype: dict
        :raises: DatabasePropertyError
        """
        res = self.api.get("/_api/database/current")
        if res.status_code not in HTTP_OK:
            raise DatabasePropertyError(res)
        return uncamelify(res.obj["result"])
Beispiel #7
0
    def properties(self):
        """Return the properties of this graph.

        :returns: the properties of this graph
        :rtype: dict
        :raises: GraphPropertiesError
        """
        res = self.api.get("/_api/gharial/{}".format(self.name))
        if res.status_code not in HTTP_OK:
            raise GraphPropertyError(res)
        return uncamelify(res.obj["graph"])
Beispiel #8
0
    def figures(self):
        """Return the statistics of this collection.

        :returns: the statistics of this collection
        :rtype: dict
        :raises: CollectionGetError
        """
        res = self.api.get(
            "/_api/collection/{}/figures".format(self.name)
        )
        if res.status_code not in HTTP_OK:
            raise CollectionGetError(res)
        return uncamelify(res.obj["figures"])
Beispiel #9
0
    def properties(self):
        """Return the properties of this graph.

        :returns: the properties of this graph
        :rtype: dict
        :raises: GraphPropertiesError
        """
        res = self._api.get(
            "/_api/gharial/{}".format(self.name)
        )
        if res.status_code != 200:
            raise GraphPropertiesError(res)
        return uncamelify(res.obj["graph"])
Beispiel #10
0
    def explain_query(self, query, all_plans=False, max_plans=None,
                      optimizer_rules=None):
        """Explain the AQL query.

        This method does not execute the query, but only inspect it and
        return meta information about it.

        If ``all_plans`` is set to True, all possible execution plans are
        returned. Otherwise only the optimal plan is returned.

        For more information on optimizer_rules, please refer to:
        https://docs.arangodb.com/HttpAqlQuery/README.html

        :param query: the AQL query to explain
        :type query: str
        :param all_plans: whether or not to return all execution plans
        :type all_plans: bool
        :param max_plans: maximum number of plans the optimizer generates
        :type max_plans: None or int
        :param optimizer_rules: list of optimizer rules
        :type optimizer_rules: list
        :returns: the query plan or list of plans (if all_plans is True)
        :rtype: dict or list
        :raises: AQLQueryExplainError
        """
        options = {"allPlans": all_plans}
        if max_plans is not None:
            options["maxNumberOfPlans"] = max_plans
        if optimizer_rules is not None:
            options["optimizer"] = {"rules": optimizer_rules}
        res = self.api.post(
            "/_api/explain", data={"query": query, "options": options}
        )
        if res.status_code not in HTTP_OK:
            raise AQLQueryExplainError(res)
        if "plan" in res.obj:
            return uncamelify(res.obj["plan"])
        else:
            return uncamelify(res.obj["plans"])
Beispiel #11
0
    def indexes(self):
        """Return the details on the indexes of this collection.

        :returns: the index details
        :rtype: dict
        :raises: IndexListError
        """
        res = self.api.get("/_api/index?collection={}".format(self.name))
        if res.status_code not in HTTP_OK:
            raise IndexListError(res)

        indexes = {}
        for index_id, details in res.body["identifiers"].items():
            del details["id"]
            indexes[index_id.split("/", 1)[1]] = uncamelify(details)
        return indexes
Beispiel #12
0
    def indexes(self):
        """Return the details on the indexes of this collection.

        :returns: the index details
        :rtype: dict
        :raises: IndexListError
        """
        res = self.api.get(
            "/_api/index?collection={}".format(self.name)
        )
        if res.status_code not in HTTP_OK:
            raise IndexListError(res)

        indexes = {}
        for index_id, details in res.obj["identifiers"].items():
            del details["id"]
            indexes[index_id.split("/", 1)[1]] = uncamelify(details)
        return indexes