SequoiaDB
 All Classes Functions
Public Member Functions | Static Public Attributes | List of all members
pysequoiadb.client.client Class Reference
Inheritance diagram for pysequoiadb.client.client:

Public Member Functions

def __init__
 
def __del__
 
def __repr__
 
def __getitem__
 
def __getattr__
 
def connect_to_hosts
 
def connect
 
def disconnect
 
def create_user
 
def remove_user
 
def get_snapshot
 
def reset_snapshot
 
def get_list
 
def get_collection
 
def get_collection_space
 
def create_collection_space
 
def drop_collection_space
 
def list_collection_spaces
 
def list_collections
 
def list_replica_groups
 
def get_replica_group_by_name
 
def get_replica_group_by_id
 
def create_replica_group
 
def remove_replica_group
 
def create_replica_cata_group
 
def exec_update
 
def exec_sql
 
def transaction_begin
 
def transaction_commit
 
def transaction_rollback
 
def flush_configure
 
def create_procedure
 
def remove_procedure
 
def list_procedures
 
def eval_procedure
 
def backup_offline
 
def list_backup
 
def remove_backup
 
def list_task
 
def wait_task
 
def cancel_task
 
def set_session_attri
 
def close_all_cursors
 
def is_valid
 
def get_datacenter
 

Static Public Attributes

string HOST "localhost"
 
string SERVICE "11810"
 
string USER ""
 
string PSW ""
 

Detailed Description

SequoiaDB Client Driver

The client support interfaces to connect to SequoiaDB.
In order to connect to SequoiaDB, you need use the class first.
And you should make sure the instance of it released when you don't use it
any more.

All operation need deal with the error code returned first, if it has. 
Every error code is not SDB_OK(or 0), it means something error has appeared,
and user should deal with it according the meaning of error code printed.

@version: execute to get version
          >>> import pysequoiadb
          >>> print pysequoiadb.get_version()

@notice : The dict of built-in Python is hashed and non-ordered. so the
          element in dict may not the order we make it. we make a dict and
          print it like this:
          ...
          >>> a = {"avg_age":24, "major":"computer science"}
          >>> a
          >>> {'major': 'computer science', 'avg_age': 24}
          ...
          the elements order it is not we make it!!
          therefore, we use bson.SON to make the order-sensitive dict if the
          order is important such as operations in "$sort", "$group",
          "split_by_condition", "aggregate","create_collection"...
          In every scene which the order is important, please make it using
          bson.SON and list. It is a subclass of built-in dict
          and order-sensitive

Constructor & Destructor Documentation

def pysequoiadb.client.client.__init__ (   self,
  host = None,
  service = None,
  user = None,
  psw = None,
  ssl = False 
)
initialize when product a object.
 
   it will try to connect to SequoiaDB using host and port given,
   localhost and 11810 are the default value of host and port,
   user and password are "". 

Parameters:
   Name       Type      Info:
   host       str       The hostname or IP address of dbserver,
                        if None, "localhost" will be insteaded
   service    str/int   The service name or port number of dbserver,
                        if None, "11810" will be insteaded
   user       str       The user name to access to database,
                        if None, "" will be insteaded
   psw        str       The user password to access to database,
                        if None, "" will be insteaded
   ssl        bool      decide to use ssl or not, default is False.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.__del__ (   self)
release resource when del called.

Exceptions:
   pysequoiadb.error.SDBBaseError

Member Function Documentation

def pysequoiadb.client.client.__getattr__ (   self,
  name 
)
support client.cs to access to collection space.

   eg.
   cc = client()
   cs = cc.test # access to collection space named 'test'

   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, or None.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.__getitem__ (   self,
  name 
)
support [] to access to collection space.

   eg.
   cc = client()
   cs = cc['test'] # access to collection space named 'test'.

Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.backup_offline (   self,
  options = None 
)
Backup the whole database or specifed replica group.

Parameters:
   Name      Type  Info:
   options   dict  Contains a series of backup configuration
                   infomations. Backup the whole cluster if None. 
                   The "options" contains 5 options as below. 
                   All the elements in options are optional. 
                   eg:
                   { "GroupName":["rgName1", "rgName2"], 
                     "Path":"/opt/sequoiadb/backup",
                     "Name":"backupName", "Description":description,
                     "EnsureInc":true, "OverWrite":true }
                   See Info as below.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
Info:
   GroupName   :  The replica groups which to be backuped.
   Path        :  The backup path, if not assign, use the backup path assigned in configuration file.
   Name        :  The name for the backup.
   Description :  The description for the backup.
   EnsureInc   :  Whether excute increment synchronization,
                  default to be false.
   OverWrite   :  Whether overwrite the old backup file,
                  default to be false.
def pysequoiadb.client.client.cancel_task (   self,
  task_id,
  is_async 
)
Cancel the specified task.

Parameters:
   Name         Type     Info:
   task_id      long     The task id to be canceled.
   is_async     bool     The operation "cancel task" is async or not,
                         "True" for async, "False" for sync.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.close_all_cursors (   self)
Close all the cursors in current thread, we can't use those cursors to 
get data again.

Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.connect (   self,
  host,
  service,
  kwargs 
)
connect to specified database

Parameters:
   Name        Type     Info:
   host        str      The host name or IP address of database server.
   service     int/str  The servicename of database server.
   **kwargs             Useful options are below:
   -  user     str      The user name to access to database.
   -  password str      The user password to access to database.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.connect_to_hosts (   self,
  hosts,
  kwargs 
)
try to connect a host in specified hosts

Parameters:
   Name        Type  Info:
   hosts       list  The list contains hosts.
                     eg.
                     [ {'host':'localhost',     'service':'11810'},
                       {'host':'192.168.10.30', 'service':'11810'},
                       {'host':'192.168.20.63', 'service':11810}, ]
   **kwargs          Useful options are below:
   -  user     str   The user name to access to database.
   -  password str   The user password to access to database.
   -  policy   str   The policy of select hosts. it must be string
                     of 'random' or 'one_by_one'.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.create_collection_space (   self,
  cs_name,
  options = 0 
)
Create collection space with specified pagesize.

Parameters:
   Name          Type     Info:
   cs_name       str      The name of collection space to be created.
   options       int/dict The options to create collection space.
    -PageSize    int      The page size of collection space. See Info
                         as below.
    -Domain      str      The domain of collection space to belongs
    -LobPageSize int      The page size when stored lob, see Info as below
Return values:
   collection space object created.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
Info:
   valid page size value:
               0  :  64k default page size
            4096  :  4k
            8192  :  8k
           16384  :  16k
           32768  :  32k
           65536  :  64k
   valid LOB page size value:
               0  :  256k default Lob page size
            4096  :  4k
            8192  :  8k
           16384  :  16k
           32768  :  32k
           65536  :  64k
          131072  :  128k
          262144  :  256k
          524288  :  512k
def pysequoiadb.client.client.create_procedure (   self,
  code 
)
Create a store procedures

Parameters:
   Name         Type     Info:
   code         str      The JS code of store procedures.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.create_replica_cata_group (   self,
  host,
  service,
  path,
  configure 
)
Create a catalog replica group.

Parameters:
   Name         Type     Info:
   host         str      The hostname for the catalog replica group.
   service      str      The servicename for the catalog replica group.
   path         str      The path for the catalog replica group.
   configure    dict     The configurations for the catalog replica group.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.create_replica_group (   self,
  group_name 
)
Create the specified replica group.

Parameters:
   Name        Type     Info:
   group_name  str      The name of replica group to be created.
Return values:
   the replicagroup object created.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.create_user (   self,
  name,
  psw 
)
Add an user in current database.

Parameters:
   Name         Type     Info:
   name         str      The name of user to be created.
   psw          str      The password of user to be created.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.disconnect (   self)
disconnect to current server.

Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.drop_collection_space (   self,
  cs_name 
)
Remove the specified collection space.

Parameters:
   Name         Type     Info:
   cs_name      str      The name of collection space to be dropped
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.eval_procedure (   self,
  name 
)
Eval a func.

Parameters:
   Name         Type     Info:
   name         str      The name of store procedure.
Return values:
   cursor object of current eval.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.exec_sql (   self,
  sql 
)
Executing SQL command.

Parameters:
   Name         Type     Info:
   sql          str      The SQL command.
Return values:
   a cursor object of matching documents.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.exec_update (   self,
  sql 
)
Executing SQL command for updating.

Parameters:
   Name         Type     Info:
   sql          str      The SQL command.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.flush_configure (   self,
  options 
)
Flush the options to configure file.
Parameters:
   Name      Type  Info:
   options   dict  The configure infomation, pass {"Global":true} or
                   {"Global":false} In cluster environment, passing
                   {"Global":true} will flush data's and catalog's 
                   configuration file, while passing {"Global":false} will 
                   flush coord's configuration file. In stand-alone
                   environment, both them have the same behaviour.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.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
def pysequoiadb.client.client.get_collection_space (   self,
  cs_name 
)
Get the specified collection space.

Parameters:
   Name         Type     Info:
   cs_name      str      The name of collection space.
Return values:
   a collection space object of query.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.get_datacenter (   self)
get data center

Return values:
   an object of data center 
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.get_list (   self,
  list_type,
  kwargs 
)
Get the informations of specified type.

Parameters:
   Name        Type     Info:
   list_type   int      Type of list option, see Info as below.
   **kwargs             Useful options are below
   - condition dict     The matching rule, match all the documents
                        if None.
   - selector  dict     The selective rule, return the whole
                        documents if None.
   - order_by  dict     The ordered rule, never sort if None.
Return values:
   a cursor object of query
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
Info:
   list type:
    0          : Get all contexts list
    1          : Get contexts list for the current session
    2          : Get all sessions list
    3          : Get the current session
    4          : Get all collections list
    5          : Get all collecion spaces' list
    6          : Get storage units list
    7          : Get replicaGroup list ( only applicable in sharding env )
    8          : Get store procedure list
    9          : Get domains list
    10         : Get tasks list
    11         : Get collection space list in domain
    12         : Get collection list in domain
def pysequoiadb.client.client.get_replica_group_by_id (   self,
  id 
)
Get the specified replica group of specified group id.

Parameters:
   Name       Type     Info:
   id         str      The id of replica group.
Return values:
   the replicagroup object of query.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.get_replica_group_by_name (   self,
  group_name 
)
Get the specified replica group of specified group name.

Parameters:
   Name         Type     Info:
   group_name   str      The name of replica group.
Return values:
   the replicagroup object of query.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.get_snapshot (   self,
  snap_type,
  kwargs 
)
Get the snapshots of specified type.

Parameters:
   Name           Type  Info:
   snap_typr      str   The type of snapshot, see Info as below
   **kwargs             Useful options are below
   - condition    dict  The matching rule, match all the documents
                        if not provided.
   - selector     dict  The selective rule, return the whole
                        document if not provided.
   - order_by     dict  The ordered rule, result set is unordered
                        if not provided.
Return values:
   a cursor object of query
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
Info:
  snapshot type:
      0     : Get all contexts' snapshot
      1     : Get the current context's snapshot
      2     : Get all sessions' snapshot
      3     : Get the current session's snapshot
      4     : Get the collections' snapshot
      5     : Get the collection spaces' snapshot
      6     : Get database's snapshot
      7     : Get system's snapshot
      8     : Get catalog's snapshot
def pysequoiadb.client.client.is_valid (   self)
Judge whether the connection is valid.

Return values:
   bool 
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.list_backup (   self,
  options,
  kwargs 
)
List the backups.

Parameters:
   Name        Type     Info:
   options     dict     Contains configuration infomations for remove
                         backups, list all the backups in the
                         default backup path if None. 
                         The "options" contains 3 options as below. 
                         All the elements in options are optional. 
                         eg:
                         { "GroupName":["rgame1", "rgName2"], 
                           "Path":"/opt/sequoiadb/backup",
                           "Name":"backupName" }
                         See Info as below.
   **kwargs             Useful option arw below
   - condition dict     The matching rule, return all the documents
                        if None.
   - selector  dict     The selective rule, return the whole document
                        if None.
   - order_by  dict     The ordered rule, never sort if None.
Return values:
   a cursor object of backup list
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
Info:
   GroupName   :  Assign the backups of specifed replica groups to be list.
   Path        :  Assign the backups in specifed path to be list,
                  if not assign, use the backup path asigned in the
                  configuration file.
   Name        :  Assign the backups with specifed name to be list.
def pysequoiadb.client.client.list_collection_spaces (   self)
List all collection space of current database, include temporary
   collection space.

Return values:
   a cursor object of collection spaces.
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.list_collections (   self)
List all collections in current database.

Return values:
   a cursor object of collection.
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.list_procedures (   self,
  condition 
)
List store procedures.

Parameters:
   Name         Type     Info:
   condition    dict     The condition of list.
Return values:
   an cursor object of result
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.list_replica_groups (   self)
List all replica groups of current database.

Return values:
   a cursor object of replication groups.
Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.list_task (   self,
  kwargs 
)
List the tasks.

Parameters:
   Name           Type     Info:
   **kwargs                Useful options are below
   - condition    dict     The matching rule, return all the documents
                           if None.
   - selector     dict     The selective rule, return the whole
                           document if None.
   - order_by     dict     The ordered rule, never sort if None.
                           bson.SON may need if it is order-sensitive.
                           eg.
                           bson.SON([("name",-1), ("age":1)]) it will
                           be ordered descending by 'name' first, and
                           be ordered ascending by 'age'
   - hint         dict     The hint, automatically match the optimal
                           hint if None.
Return values:
   a cursor object of task list
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.remove_backup (   self,
  options 
)
Remove the backups

Parameters:
   Name      Type  Info:
   options   dict  Contains configuration infomations for remove
                   backups, remove all the backups in the default
                   backup path if null. The "options" contains 3
                   options as below. All the elements in options are
                   optional.
                   eg:
                   { "GroupName":["rgName1", "rgName2"],
                     "Path":"/opt/sequoiadb/backup",
                     "Name":"backupName" }
                   See Info as below.
Return values:
   an cursor object of result
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
Info:
   GroupName   : Assign the backups of specifed replica groups to be
                 remove.
   Path        : Assign the backups in specifed path to be remove, if not
                 assign, use the backup path asigned in the configuration
                 file.
   Name        : Assign the backups with specifed name to be remove.
def pysequoiadb.client.client.remove_procedure (   self,
  name 
)
Remove a store procedures.
     
Parameters:
   Name         Type     Info:
   name         str      The name of store procedure.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.remove_replica_group (   self,
  group_name 
)
Remove the specified replica group.

Parameters:
   Name         Type     Info:
   group_name   str      The name of replica group to be removed
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.remove_user (   self,
  name,
  psw 
)
Remove the spacified user from current database.

Parameters:
   Name     Type     Info:
   name     str      The name of user to be removed.
   psw      str      The password of user to be removed.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.reset_snapshot (   self,
  condition = None 
)
Reset the snapshot.

Parameters:
   Name         Type     Info:
   condition    dict     The matching rule, usually specifies the
                         node in sharding environment, in standalone
                         mode, this option is ignored.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.set_session_attri (   self,
  options = None 
)
Set the attributes of the session.

Parameters:
   Name         Type     Info:
   options      dict     The configuration options for session.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.transaction_begin (   self)
Transaction begin.

Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.transaction_commit (   self)
Transaction commit.

Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.transaction_rollback (   self)
Transaction rollback

Exceptions:
   pysequoiadb.error.SDBBaseError
def pysequoiadb.client.client.wait_task (   self,
  task_ids,
  num 
)
Wait the tasks to finish.

Parameters:
   Name         Type     Info:
   task_ids     list     The list of task id.
   num          int      The number of task id.
Exceptions:
   pysequoiadb.error.SDBTypeError
   pysequoiadb.error.SDBBaseError

The documentation for this class was generated from the following file: