import set_path # Importing this module will add the project's home directory to sys.path
Added 'D:\Docs\- MY CODE\Brain Annex\BA-Win7' to sys.path
import os
import sys
import getpass
from BrainAnnex.modules.neo_access.neo_access import NeoAccess
print("To create a database connection, enter the host IP, but leave out the port number: (EXAMPLES: bolt://1.2.3.4 OR neo4j://localhost )\n")
host = input("Enter host IP WITHOUT the port number. EXAMPLE: bolt://123.456.789.012")
host += ":7687" # EXAMPLE of host value: "bolt://123.456.789.012:7687"
password = getpass.getpass("Enter the database password:")
print(f"\n=> Will be using: host='{host}', username='neo4j', password=**********")
To create a database connection, enter the host IP, but leave out the port number: (EXAMPLES: bolt://1.2.3.4 OR neo4j://localhost )
=> Will be using: host='bolt://155.248.202.124:7687', username='neo4j', password=**********
db = NeoAccess(host=host,
credentials=("neo4j", password), debug=True)
~~~~~~~~~ Initializing NeoAccess object ~~~~~~~~~ Attempting to connect to Neo4j host 'bolt://155.248.202.124:7687', with username 'neo4j' Connection to host 'bolt://155.248.202.124:7687' established
print("Version of the Neo4j driver: ", db.version())
Version of the Neo4j driver: 4.3.9
db.empty_dbase() # WARNING: USE WITH CAUTION!!!
neo_car = db.create_node("Car", {'color': 'white', 'make': 'Toyota'})
neo_person = db.create_node("Person", {'name': 'Julian'})
In create_node(). Query:
CREATE (n :`Car` {`color`: $par_1, `make`: $par_2}) RETURN n
Data binding:
{'par_1': 'white', 'par_2': 'Toyota'}
In create_node(). Query:
CREATE (n :`Person` {`name`: $par_1}) RETURN n
Data binding:
{'par_1': 'Julian'}
neo_car
30
neo_person
0
number_added = db.add_links(neo_car, neo_person, rel_name="OWNED_BY")
number_added
In add_links()
match_from: {'node': '(from)', 'where': 'id(from) = 30', 'data_binding': {}, 'dummy_node_name': 'from'}
match_to: {'node': '(to)', 'where': 'id(to) = 0', 'data_binding': {}, 'dummy_node_name': 'to'}
In add_links(). Query:
MATCH (from), (to)
WHERE (id(from) = 30 AND id(to) = 0)
MERGE (from) -[:`OWNED_BY`]-> (to)
In update_query(). Attributes of ResultSummary object:
metadata -> {'query': '\n MATCH (from), (to)\n WHERE (id(from) = 30 AND id(to) = 0)\n MERGE (from) -[:`OWNED_BY`]-> (to) \n ', 'parameters': {}, 'server': <neo4j.api.ServerInfo object at 0x000000001A04C580>, 't_first': 5, 'fields': [], 'bookmark': 'FB:kcwQxosFA855RdybwjuMf2O2J8l5R5A=', 'stats': {'relationships-created': 1}, 'type': 'w', 't_last': 0, 'db': 'neo4j', 'notifications': [{'severity': 'WARNING', 'description': 'If a part of a query contains multiple disconnected patterns, this will build a cartesian product between all those parts. This may produce a large amount of data and slow down query processing. While occasionally intended, it may often be possible to reformulate the query that avoids the use of this cross product, perhaps by adding a relationship between the different parts or by using OPTIONAL MATCH (identifier is: (to))', 'code': 'Neo.ClientNotification.Statement.CartesianProductWarning', 'position': {'column': 1, 'offset': 13, 'line': 2}, 'title': 'This query builds a cartesian product between disconnected patterns.'}]}
server -> <neo4j.api.ServerInfo object at 0x000000001A04C580>
database -> neo4j
query ->
MATCH (from), (to)
WHERE (id(from) = 30 AND id(to) = 0)
MERGE (from) -[:`OWNED_BY`]-> (to)
parameters -> {}
query_type -> w
plan -> None
profile -> None
notifications -> [{'severity': 'WARNING', 'description': 'If a part of a query contains multiple disconnected patterns, this will build a cartesian product between all those parts. This may produce a large amount of data and slow down query processing. While occasionally intended, it may often be possible to reformulate the query that avoids the use of this cross product, perhaps by adding a relationship between the different parts or by using OPTIONAL MATCH (identifier is: (to))', 'code': 'Neo.ClientNotification.Statement.CartesianProductWarning', 'position': {'column': 1, 'offset': 13, 'line': 2}, 'title': 'This query builds a cartesian product between disconnected patterns.'}]
counters -> {'relationships_created': 1}
result_available_after -> 5
result_consumed_after -> 0
RESULT of update_query in add_links(): {'relationships_created': 1, 'returned_data': []}
1
match_from = db.match(internal_id=neo_car)
match_to = db.match(internal_id=neo_person)
match_from
{'internal_id': 30,
'labels': None,
'key_name': None,
'key_value': None,
'properties': None,
'clause': None,
'dummy_node_name': None}
match_to
{'internal_id': 0,
'labels': None,
'key_name': None,
'key_value': None,
'properties': None,
'clause': None,
'dummy_node_name': None}
# Retrieve the car nodes
db.get_nodes(neo_car)
In get_nodes()
match_structure: {'node': '(n)', 'where': 'id(n) = 30', 'data_binding': {}, 'dummy_node_name': 'n'}
In get_nodes(). Query:
MATCH (n) WHERE (id(n) = 30) RETURN n
[{'color': 'white', 'make': 'Toyota'}]
# Retrieve a single property of the car node (for situation when only 1 node is present)
db.get_nodes(neo_car, single_cell="color")
In get_nodes()
match_structure: {'node': '(n)', 'where': 'id(n) = 30', 'data_binding': {}, 'dummy_node_name': 'n'}
In get_nodes(). Query:
MATCH (n) WHERE (id(n) = 30) RETURN n
'white'
# How many owners does the car have?
db.count_links(neo_car, rel_name="OWNED_BY", rel_dir="OUT")
In count_links()
match_structure: {'node': '(n)', 'where': 'id(n) = 30', 'data_binding': {}, 'dummy_node_name': 'n'}
In count_links(). Query:
MATCH (n) - [:OWNED_BY] -> (neighbor )WHERE (id(n) = 30) RETURN count(neighbor) AS link_count
1
# Look up information about the car owner(s)
db.follow_links(neo_car, rel_name="OWNED_BY", rel_dir="OUT")
In follow_links()
match_structure: {'node': '(n)', 'where': 'id(n) = 30', 'data_binding': {}, 'dummy_node_name': 'n'}
In follow_links(). Query:
MATCH (n) - [:OWNED_BY] -> (neighbor )WHERE (id(n) = 30) RETURN neighbor
[{'name': 'Julian'}]