OrientDB Python連接操作

Python的OrientDB驅動程式使用二進位協議。 PyOrient是git hub專案名稱,它用於將OrientDB與Python連接起來並運算元據。 它適用於OrientDB 1.7及更高版本。

以下命令用於安裝PyOrient

pip install pyorient

可以使用名為demo.py的腳本檔執行以下任務 -

  • 創建客戶端實例,也就是創建一個連接。
  • 創建名為DB_Demo的資料庫。
  • 打開名為DB_Demo的資料庫。
  • 創建類my_class
  • 創建屬性ID和名稱。
  • 將記錄插入類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

上一篇: OrientDB Java連接操作 下一篇:無