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.