Ejemplo n.º 1
0
    def db(self, name='_system', username='******', password='', verify=False):
        """Connect to an ArangoDB database and return the database API wrapper.

        :param name: Database name.
        :type name: str | unicode
        :param username: Username for basic authentication.
        :type username: str | unicode
        :param password: Password for basic authentication.
        :type password: str | unicode
        :param verify: Verify the connection by sending a test request.
        :type verify: bool
        :return: Standard database API wrapper.
        :rtype: arango.database.StandardDatabase
        :raise arango.exceptions.ServerConnectionError: If **verify** was set
            to True and the connection fails.
        """
        connection = Connection(hosts=self._hosts,
                                host_resolver=self._host_resolver,
                                sessions=self._sessions,
                                db_name=name,
                                username=username,
                                password=password,
                                http_client=self._http,
                                serializer=self._serializer,
                                deserializer=self._deserializer)
        if verify:
            try:
                connection.ping()
            except ServerConnectionError as err:
                raise err
            except Exception as err:
                raise ServerConnectionError('bad connection: {}'.format(err))

        return StandardDatabase(connection)