Пример #1
0
def connection():
    if hasattr(connection, 'db'):
        return connection.db

    url = DATABASE_URL
    u = urlparse(url)
    if u.netloc.find('@') > -1:
        credentials, host = u.netloc.split('@')
        user, password, = credentials.split(':')
        neo4j.authenticate(host, user, password)
        url = ''.join([u.scheme, '://', host, u.path, u.query])

    try:
        connection.db = neo4j.GraphDatabaseService(url)
    except SocketError as e:
        raise SocketError("Error connecting to {0} - {1}".format(url, e))

    if connection.db.neo4j_version >= (2, 0):
        raise Exception(
            "Support for neo4j 2.0 is in progress but not supported by this release."
        )
    if connection.db.neo4j_version < (1, 8):
        raise Exception("Versions of neo4j prior to 1.8 are unsupported.")

    return connection.db
Пример #2
0
    def new_session(self):
        try:
            self.session = neo4j.GraphDatabaseService(self.url)
        except SocketError as e:
            raise SocketError("Error connecting to {0} - {1}".format(self.url, e))

        if self.session.neo4j_version < (2, 0):
            raise Exception("Support for neo4j versions prior to 2.0 are "
                    + "supported by the 0.x.x series releases of neomodel")

        if hasattr(self, 'tx_session'):
            delattr(self, 'tx_session')