OrientDB - Python 接口



OrientDB 的 Python 驱动程序使用二进制协议。PyOrient 是该 Git Hub 项目的名称,它有助于将 OrientDB 与 Python 连接起来。它适用于 OrientDB 1.7 及更高版本。

以下命令用于安装 PyOrient。

pip install pyorient

您可以使用名为 demo.py 的脚本文件执行以下任务:

  • 创建客户端实例意味着创建连接。

  • 创建名为 DB_Demo 的数据库。

  • 打开名为 DB_Demo 的数据库。

  • 创建名为 my_class 的类。

  • 创建 id 和 name 属性。

  • 将记录插入 my_class 类中。

//create connection 
client = pyorient.OrientDB("localhost", 2424) 
session_id = client.connect( "admin", "admin" )
 
//create a databse 
client.db_create( db_name, pyorient.DB_TYPE_GRAPH, pyorient.STORAGE_TYPE_MEMORY ) 

//open databse 
client.db_open( DB_Demo, "admin", "admin" ) 

//create class 
cluster_id = client.command( "create class my_class extends V" ) 

//create property 
cluster_id = client.command( "create property my_class.id Integer" ) 
cluster_id = client.command( "create property my_class.name String" ) 

//insert record 
client.command("insert into my_class ( 'id','’name' ) values( 1201, 'satish')") 

使用以下命令执行上述脚本。

$ python demo.py
广告

© . All rights reserved.