我想将> 1mn记录的MySQL数据库转换为图形数据库,因为它是重度链接的网络类型数据.Neo4J的免费版本有一些我认为可能会遇到的限制,因此我安装了OrientDB(Community 2.2.0)(在Ubuntu Server 16.04上)并使其正常运行.现在我需要从Python(3.5.1+)访问它,所以我正在尝试pyorient(1.5.2).(我尝试使用TinkerPop,因为我最终想要使用Gremlin,并且无法让gremlin控制台与OrientDB交谈.)
以下简单的Python代码,用于连接到OrientDB中的一个测试图:
import pyorient
username="user"
password="password"
client = pyorient.OrientDB("localhost", 2424)
session_id = client.connect( username, password )
print("SessionID=",session_id)
db_name="GratefulDeadConcerts"
if client.db_exists( db_name, pyorient.STORAGE_TYPE_MEMORY ):
print("Database",db_name,"exists")
client.db_open( db_name, username, password )
else:
print("Database",db_name,"doesn't exist")
Run Code Online (Sandbox Code Playgroud)
给出了一个奇怪的错误:
SessionID= 27
Database GratefulDeadConcerts exists
Traceback (most recent call last):
File "FirstTest.py", line 18, in <module>
client.db_open( db_name, username, password )
File "/home/tom/MyProgs/TestingPyOrient/env/lib/python3.5/site-packages/pyorient/orient.py", line 379, in db_open
.prepare((db_name, user, password, db_type, client_id)).send().fetch_response()
File "/home/tom/MyProgs/TestingPyOrient/env/lib/python3.5/site-packages/pyorient/messages/database.py", line 141, in fetch_response
info = OrientVersion(release)
File "/home/tom/MyProgs/TestingPyOrient/env/lib/python3.5/site-packages/pyorient/otypes.py", …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用pyorient
驱动程序创建类,但有时如果类存在,我有类存在消息.有没有办法检查OrientDB python驱动程序中是否存在类?以下是我创建类的示例代码的一部分......
@classmethod
def create(cls):
cls._cluster_id = OrientEngine.client.command("CREATE CLASS %s EXTENDS V" % cls.__name__)
return cls._cluster_id
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用Oriented DB提取记录pyorient
,这是我的查询:
query = "SELECT value FROM (SELECT expand(Elements) FROM dataset) WHERE type = 'XXX'"
records = client.command(query)
Run Code Online (Sandbox Code Playgroud)
一切都很好.当我尝试打印记录时,我得到的是:
record = records[0]
print type(record)
<class 'pyorient.otypes.OrientRecord'>
print record
{{'value': 'Name'},'version':0,'rid':'#-2:0'}
Run Code Online (Sandbox Code Playgroud)
因为我只需要提取' Name
' record
,我试过:
print record[0]
Run Code Online (Sandbox Code Playgroud)
得到了
TypeError: 'OrientRecord' object does not support indexing
Run Code Online (Sandbox Code Playgroud)
这是以下结果repr
:
print(repr(record))
<pyorient.otypes.OrientRecord object at 0x7fdcdb531ad0>
Run Code Online (Sandbox Code Playgroud)