pyorientdb的学习笔记:
pyorient 是用 socket(tcp) 连接 OrientDB Server.
其中使用了 select 做高并发
https://github.com/mogui/pyorient/blob/master/pyorient/orient.py
def write(self, buff):
# This is a trick to detect server disconnection
# or broken line issues because of
""":see: https://docs.python.org/2/howto/sockets.html#when-sockets-die """
try:
_, ready_to_write, in_error = select.select(
[], [self._socket], [self._socket], 1)
except select.error as e:
self.connected = False
self._socket.close()
raise e
if not in_error and ready_to_write:
self._socket.sendall(buff)
return len(buff)
else:
self.connected = False
self._socket.close()
raise PyOrientConnectionException("Socket error", [])
# DATABASE COMMANDS
def gremlin(self, *args):
return self.get_message("CommandMessage") \
.prepare(( QUERY_GREMLIN, ) + args).send().fetch_response()
def command(self, *args):
return self.get_message("CommandMessage") \
.prepare(( QUERY_CMD, ) + args).send().fetch_response()
def batch(self, *args):
return self.get_message("CommandMessage") \
.prepare(( QUERY_SCRIPT, ) + args).send().fetch_response()
def query(self, *args):
return self.get_message("CommandMessage") \
.prepare(( QUERY_SYNC, ) + args).send().fetch_response()
def query_async(self, *args):
return self.get_message("CommandMessage") \
.prepare(( QUERY_ASYNC, ) + args).send().fetch_response()
def db_create(self, name, type=DB_TYPE_DOCUMENT, storage=STORAGE_TYPE_PLOCAL):
'''Creates a database in the remote OrientDB server instance.
:param name: the name of the database to create. Example: "MyDatabase".
:param type: the type of the database to create. Can be either document or graph. [default: DB_TYPE_DOCUMENT]
:param storage: specifies the storage type of the database to create. It can be one of the supported types [default: STORAGE_TYPE_PLOCAL]:
- STORAGE_TYPE_PLOCAL - persistent database
- STORAGE_TYPE_MEMORY - volatile database
:return: None
Usage::
>>> from pyorient import OrientDB
>>> client = OrientDB("localhost", 2424)
>>> client.connect('root', 'root')
>>> client.db_create('test')
'''
self.get_message("DbCreateMessage") \
.prepare((name, type, storage)).send().fetch_response()
return None
http://orientdb.com/docs/last/PyOrient.html
https://github.com/mogui/pyorient
简介:
自己...