def __getattr__(self, name): """support client.cs to access to collection. eg. cc = client() cs = cc.test cl = cs.test_cl # access to collection named 'test_cl' and we should pass '__members__' and '__methods__', becasue dir(cc) will invoke __getattr__("__members__") and __getattr__("__methods__"). if success, a collection object will be returned. Exceptions: pysequoiadb.error.SDBBaseError """ if '__members__' == name or '__methods__' == name: pass else: cl = collection() try: rc = sdb.cs_get_collection(self._cs, name, cl._cl) raise_if_error(rc, "Failed to get collection: %s" % name) except SDBBaseError: del cl raise return cl
def get_collection(self, cl_full_name): """Get the specified collection. Parameters: Name Type Info: cl_full_name str The full name of collection Return values: a collection object of query. Exceptions: pysequoiadb.error.SDBTypeError pysequoiadb.error.SDBBaseError """ if not isinstance(cl_full_name, basestring): raise SDBTypeError("full name of collection must be an instance of basestring") if '.' not in cl_full_name: raise SDBTypeError("Full name must included '.'") try: cl = collection() rc = sdb.sdb_get_collection(self._client, cl_full_name, cl._cl) pysequoiadb._raise_if_error("Failed to get collection", rc) except SDBBaseError: del cl cl = None raise return cl
def __getattr__(self, name): """support client.cs to access to collection. eg. cc = client() cs = cc.test cl = cs.test_cl # access to collection named 'test_cl' and we should pass '__members__' and '__methods__', becasue dir(cc) will invoke __getattr__("__members__") and __getattr__("__methods__"). if success, a collection object will be returned. Exceptions: pysequoiadb.error.SDBBaseError """ if '__members__' == name or '__methods__' == name: pass else: try: cl = collection() rc = sdb.cs_get_collection(self._cs, name, cl._cl) pysequoiadb._raise_if_error("Failed to get collection: %s" % name, rc) except SDBBaseError: del cl; cl = None raise return cl
def get_collection(self, cl_name): """Get the named collection. Parameters: Name Type Info: cl_name str The full name of the collection.. Return values: a collection object of query Exceptions: pysequoiadb.error.SDBTypeError pysequoiadb.error.SDBBaseError """ if not isinstance(cl_name, basestring): raise SDBTypeError("collection must be an instance of basestring") try: cl = collection() rc = sdb.cs_get_collection(self._cs, cl_name, cl._cl) pysequoiadb._raise_if_error("Failed to get collection: %s" % cl_name, rc) except SDBBaseError: del cl cl = None raise return cl
def create_collection(self, cl_name, options = None): """create a collection using name and options. Parameters: Name Type Info: cl_name str The collection name. options dict The options for creating collection, including "ShardingKey", "ReplSize", "IsMainCL" and "Compressed" informations, no options, if None. Return values: a collection object created Exceptions: pysequoiadb.error.SDBTypeError pysequoiadb.error.SDBBaseError """ if not isinstance(cl_name, basestring): raise SDBTypeError("collection must be an instance of basestring") bson_options = None if options is not None: if not isinstance(options, dict): raise SDBTypeError("options must be an instance of dict") bson_options = bson.BSON.encode(options) try: cl = collection() if bson_options is None: rc = sdb.cs_create_collection(self._cs, cl_name, cl._cl) else: rc = sdb.cs_create_collection_use_opt(self._cs, cl_name, bson_options, cl._cl) pysequoiadb._raise_if_error("Failed to create collection", rc) except SDBBaseError: del cl cl = None raise return cl
def get_collection(self, cl_name): """Get the named collection. Parameters: Name Type Info: cl_name str The short name of the collection. Return values: a collection object of query Exceptions: pysequoiadb.error.SDBBaseError """ if not isinstance(cl_name, str_type): raise SDBTypeError("collection must be an instance of str_type") cl = collection() try: rc = sdb.cs_get_collection(self._cs, cl_name, cl._cl) raise_if_error(rc, "Failed to get collection: %s" % cl_name) except SDBBaseError: del cl raise return cl