python 操作gremlin

安装 我这用的是python3 ,但是python2跟这个差不多 我都试了

pip3 install gremlinpython

下面两种连接方式,看想用那种了,性能什么的都没测试

1.python代码请求

graph = Graph()
g = graph.traversal().withRemote(DriverRemoteConnection('ws://hosts:port/gremlin','g'))
g.addV('god').property('name', 'yuxj').property('age', 111).next()
a=g.V().has('name','yuxj').valueMap().toList()
print (a)

hosts:ip地址 port 端口号

2.提交sql

from gremlin_python.driver import client
client = client.Client('ws://192.168.1.15:8182/gremlin','g')
###
#sql添加边界得label
###
gsql="mgmt = graph.openManagement()\n"\
                 "create = mgmt.makeEdgeLabel('create').multiplicity(MULTI).make()\n" \
                 "mgmt.commit()\n"
client.submit(gsql)

sql就是gremlin的sql

3.自己用过的语句

###
#sql 查询添加的数据-id
###
# a=g.V().has("company_n","上海美都管理咨询有限公司第一分公司").valueMap().toList()
#g.V().has("company_n","上海美都管理咨询有限公司第一分公司").valueMap(True).toList()#查询所有数据
#g.V().has("company_n","上海美都管理咨询有限公司第一分公司").id() 

# print(a)

###
#获取所有点的id list
###
# bs=g.V().toList()
# print(bs)

###
#遍历所有数据
###
# for b in bs:
#     print(g.V(b).valueMap().toList())
    # q=g.V(b).values('company_n').toList()
    # if q:
    #     print (q)
    # else:
    #     q = g.V(b).values('name').toList()
    #     print(q)
# c=g.V().has('name','yuxj9').valueMap().toList()
# print(c)
# d=g.V().hasLabel("1").count().toList()
# print (d)
# client.close()

###
#sql 添加边界
###

#esql="g.V().has('name','marko').as('m').V().has('name','lop').as('l').addE('create').from('m')"
#client.submit(esql)

###
#where 查看label 为company 和representative得数据
###

# A=g.V().where(hasLabel('company').or_().hasLabel('representative')).valueMap(True).toList()
# print (A)

#g.V().has('chair_id', within('%s')).as_('A').V().has('repren_id', within('%s')).addE('法人').from_('A');
# from gremlin_python.process.traversal import T
# from gremlin_python.process.traversal import Order
# from gremlin_python.process.traversal import Cardinality
# from gremlin_python.process.traversal import Column
# from gremlin_python.process.traversal import Direction
# from gremlin_python.process.traversal import Operator
# from gremlin_python.process.traversal import P
# from gremlin_python.process.traversal import Pop
# from gremlin_python.process.traversal import Scope
# from gremlin_python.process.traversal import Barrier
# a=g.V().has("company_n",P.textContent("分公司")).valueMap()
# print (a)
####

####
##查看边界和个数
####
#g.E().group().by(label).by(count())

以后慢慢补

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值