#NEWLINE# def __db_exists__( self , tx ) : #NEWLINE# #INDENT# node_ids = set ( ) #NEWLINE# relationship_ids = set ( ) #NEWLINE# for ( i , node ) in enumerate ( self . nodes ( ) ) : #NEWLINE# #INDENT# remote_node = remote ( node ) #NEWLINE# if remote_node : #NEWLINE# #INDENT# node_ids . add ( remote_node . _id ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# for ( i , relationship ) in enumerate ( self . relationships ( ) ) : #NEWLINE# #INDENT# remote_relationship = remote ( relationship ) #NEWLINE# if remote_relationship : #NEWLINE# #INDENT# relationship_ids . add ( remote_relationship . _id ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return False #NEWLINE# #UNINDENT# #UNINDENT# statement = 'OPTIONAL MATCH (a) WHERE id(a) IN {x} OPTIONAL MATCH ()-[r]->() WHERE id(r) IN {y} RETURN count(DISTINCT a) + count(DISTINCT r)' #NEWLINE# parameters = { #NEWLINE# #INDENT# 'x' : list ( node_ids ) , #NEWLINE# 'y' : list ( relationship_ids ) , #NEWLINE# #UNINDENT# } #NEWLINE# return ( tx . evaluate ( statement , parameters ) == ( len ( node_ids ) + len ( relationship_ids ) ) )