网站的标题,企业建设电商网站,网站商城开发公司,青岛建设网站企业Python操作neo4j库py2neo使用之py2neo 删除及事务相关操作#xff08;三#xff09;
py2neo 删除
1、连接数据库
from py2neo import Graph
graph Graph(bolt://xx.xx.xx.xx:7687, auth(user, pwd), nameneo4j)2、删除节点
# 删除单个节点
node graph.node…Python操作neo4j库py2neo使用之py2neo 删除及事务相关操作三
py2neo 删除
1、连接数据库
from py2neo import Graph
graph Graph(bolt://xx.xx.xx.xx:7687, auth(user, pwd), nameneo4j)2、删除节点
# 删除单个节点
node graph.nodes.match(label公司nameXX公司).first()
graph.delete(node)# 删除多个节点
nodes graph.nodes.match(label公司nameXX公司).all()
for node in nodes:graph.delete(node)3、删除关系
relationship graph.relationships.match(r_type投资).first()
graph.delete(relationship)relationships graph.relationships.match(r_type投资).all()
for relationship in relationships:graph.delete(relationship)4、 删除所有的数据和节点
graph.delete_all()5、删除数据库
from py2neo.database import SystemGraph
system SystemGraph(bolt://xx.xx.xx.xx:7687, auth(user, pwd))
system.run(fdrop database {graph_name})py2neo 事务
from py2neo import Graph, Node, Relationship
from py2neo.database import Transaction
graph Graph(bolt://xx.xx.xx.xx:7687, auth(user, pwd), nameneo4j)# 创建事务
tn:Transaction self.graph.begin()
# 创建节点
node1 Node(label公司, name百度)
node2 Node(label公司, name爱奇艺)
tn.create(node1)
tn.create(node2)
tn.graph.commit()# 创建关系
relationship Relationship(node1,投资,node2**{金额:100000})
tn.create(relationship)# 提交
tn.graph.commit()# 合并节点
tn.merge()# 删除节点、关系
tn.delete()# 回滚
tn.graph.rollback()py2neo 其他操作
1、执行原生cyther语句
from py2neo import Graph
graph Graph(bolt://100.100.20.55:7687, auth(user, pwd), nameneo4j)# 获取label为公司名称为XX公司的节点
graph.run(Match (n:公司) where n.nameXX公司 return n)