コード例 #1
0
ファイル: test_ejdb.py プロジェクト: kamijawa/pi_server
def test_mongo(collection_name):
    # client, db = None, None
    # host, port = 'localhost', 27017
    # client = MongoClient(host, port)
    # db = client['groundcontrol']
    # collection = db[collection_name]
    # l = list(collection.find({}))
    # o = convert_mongo_id(l[0])

    ejdb = pyejdb.EJDB("zoo.dat", pyejdb.DEFAULT_OPEN_MODE)
    # ejdb.save("test_collection", o)
    print(ejdb.dbmeta())
    with ejdb.find("test_collection", {}) as cur:
        print("found %s parrots" % len(cur))
        for p in cur:
            print('------------------')
            d2 = parse_bytes(serialize_to_bytes(p))
            print(d2)
            d2 = convert_mongo_id(d2)
            print(d2['_id'])

            # print(json.dumps(convert_mongo_id(d2), ensure_ascii=False, indent=4))
            # print(by.decode(encoding='utf-8'))
            # for k in p:
            #     print('{0}='.format(k), p[k])
                # print("%s likes toys!" % p["name"])

    ejdb.close()
コード例 #2
0
ファイル: __init__.py プロジェクト: Softmotions/ejdb-python
 def load(self, cname, oid):
     """ Loads `dict` documents identified by `oid` from `cname` collection.
     Sample:
     >>> ejdb.load('mycoll', '511c72ae7922641d00000000');
     :Parameters:
         - `cname` Collection name
         - `oid` Document object id (`_id` property)
     :Returns:
         A document `dict` identified by `oid` or `None` if it is not found
     """
     check_oid(oid)
     docbytes = self.__ejdb.load(cname, oid)
     if docbytes is None:
         return None
     return bson.parse_bytes(docbytes)
コード例 #3
0
 def load(self, cname: str, oid: str):
     """ Loads `dict` documents identified by `oid` from `cname` collection.
     Sample:
     >>> ejdb.load('mycoll', '511c72ae7922641d00000000');
     :Parameters:
         - `cname` Collection name
         - `oid` Document object id (`_id` property)
     :Returns:
         A document `dict` identified by `oid` or `None` if it is not found
     """
     check_oid(oid)
     docbytes = self.__ejdb.load(cname, oid)
     if docbytes is None:
         return None
     return bson.parse_bytes(docbytes)
コード例 #4
0
ファイル: __init__.py プロジェクト: Softmotions/ejdb-python
    def command(self, cmd):
        """ Executes ejdb database command.

          Supported commands:

           1) Exports database collections data. See ejdbexport() method.

             "export" : {
                   "path" : string,                    //Exports database collections data
                   "cnames" : [string array]|null,     //List of collection names to export
                   "mode" : int|null                   //Values: null|`JBJSONEXPORT` See ejdb.h#ejdbexport() method
             }

             Command response:
                {
                   "log" : string,        //Diagnostic log about executing this command
                   "error" : string|null, //ejdb error message
                   "errorCode" : int|0,   //ejdb error code
                }

           2) Imports previously exported collections data into ejdb.

             "import" : {
                   "path" : string                     //The directory path in which data resides
                   "cnames" : [string array]|null,     //List of collection names to import
                   "mode" : int|null                //Values: null| JBIMPORTUPDATE`|`JBIMPORTREPLACE` See ejdb.h#ejdbimport() method
              }

              Command response:
                {
                   "log" : string,        //Diagnostic log about executing this command
                   "error" : string|null, //ejdb error message
                   "errorCode" : int|0,   //ejdb error code
                }

         :Parameters:
            - `cmd`  Command object dictionary

         :Returns:
            Command response object dictionary
        """
        bret = self.__ejdb.command(bson.serialize_to_bytes(cmd))
        if bret is not None:
            return bson.parse_bytes(bret)
        return None
コード例 #5
0
ファイル: __init__.py プロジェクト: vikalp/ejdb-python
    def command(self, cmd):
        """ Executes ejdb database command.

          Supported commands:

           1) Exports database collections data. See ejdbexport() method.

             "export" : {
                   "path" : string,                    //Exports database collections data
                   "cnames" : [string array]|null,     //List of collection names to export
                   "mode" : int|null                   //Values: null|`JBJSONEXPORT` See ejdb.h#ejdbexport() method
             }

             Command response:
                {
                   "log" : string,        //Diagnostic log about executing this command
                   "error" : string|null, //ejdb error message
                   "errorCode" : int|0,   //ejdb error code
                }

           2) Imports previously exported collections data into ejdb.

             "import" : {
                   "path" : string                     //The directory path in which data resides
                   "cnames" : [string array]|null,     //List of collection names to import
                   "mode" : int|null                //Values: null| JBIMPORTUPDATE`|`JBIMPORTREPLACE` See ejdb.h#ejdbimport() method
              }

              Command response:
                {
                   "log" : string,        //Diagnostic log about executing this command
                   "error" : string|null, //ejdb error message
                   "errorCode" : int|0,   //ejdb error code
                }

         :Parameters:
            - `cmd`  Command object dictionary

         :Returns:
            Command response object dictionary
        """
        bret = self.__ejdb.command(bson.serialize_to_bytes(cmd))
        if bret is not None:
            return bson.parse_bytes(bret)
        return None
コード例 #6
0
 def get(self, idx):
     """Return JSON document at the specified position `idx`
     """
     bsdata = self.__cursor.get(idx)
     return bson.parse_bytes(bsdata) if bsdata is not None else None
コード例 #7
0
ファイル: __init__.py プロジェクト: JoakimSoderberg/ejdb
 def get(self, idx):
     """Return JSON document at the specified position `idx`
     """
     bsdata = self.__cursor.get(idx)
     return bson.parse_bytes(bsdata) if bsdata is not None else None