2022-07-15 12:40 UTC

MemoizeDB

NAME
    MemoizeDB

CLASSES
    builtins.Exception(builtins.BaseException)
        MDBError
    builtins.object
        MemoizeDB
    
    class MDBError(builtins.Exception)
     |  MDBError(conn, msg, error=None)
     |  
     |  Exception raised by fatal MemoizeDB errors.
     |  
     |  conn: The database connection.
     |  
     |  msg: The error message.
     |  
     |  error: The associated error, usually a sqlite3 Exception.
     |  
     |  Method resolution order:
     |      MDBError
     |      builtins.Exception
     |      builtins.BaseException
     |      builtins.object
     |  
     |  Methods defined here:
     |  
     |  __init__(self, conn, msg, error=None)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |  
     |  __str__(self)
     |      Return str(self).
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Static methods inherited from builtins.Exception:
     |  
     |  __new__(*args, **kwargs) from builtins.type
     |      Create and return a new object.  See help(type) for accurate signature.
     |  
     |  ----------------------------------------------------------------------
     |  Methods inherited from builtins.BaseException:
     |  
     |  __delattr__(self, name, /)
     |      Implement delattr(self, name).
     |  
     |  __getattribute__(self, name, /)
     |      Return getattr(self, name).
     |  
     |  __reduce__(...)
     |      Helper for pickle.
     |  
     |  __repr__(self, /)
     |      Return repr(self).
     |  
     |  __setattr__(self, name, value, /)
     |      Implement setattr(self, name, value).
     |  
     |  __setstate__(...)
     |  
     |  with_traceback(...)
     |      Exception.with_traceback(tb) --
     |      set self.__traceback__ to tb and return self.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors inherited from builtins.BaseException:
     |  
     |  __cause__
     |      exception cause
     |  
     |  __context__
     |      exception context
     |  
     |  __dict__
     |  
     |  __suppress_context__
     |  
     |  __traceback__
     |  
     |  args
    
    class MemoizeDB(builtins.object)
     |  MemoizeDB(conn, glue, null_ttl=None)
     |  
     |  Store results in a DB for future requests.
     |  
     |  Results are stored in a database for future requests to increase speed and
     |  reduce calls to remote services. Results may be kept permanently or purged
     |  after a given interval.
     |  
     |  Methods defined here:
     |  
     |  __init__(self, conn, glue, null_ttl=None)
     |      conn:
     |        An sqlite3 database connection. The connection should be created with the
     |        parameters "detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES",
     |        and "isolation_level=None", e.g.
     |      
     |            conn = sqlite3.connect(
     |              path,
     |              detect_types=sqlite3.PARSE_DECLTYPES|sqlite3.PARSE_COLNAMES,
     |              isolation_level=None
     |            )
     |      
     |        This may be extended in the future to support all connections implementing
     |        Python's DB-API.
     |      
     |      glue:
     |        A dictionary of tuples that provide the glue for retrieving the data and
     |        storing it in the database:
     |      
     |          { <table name> : (<retrieval function>, <type tuple>, <time to live>) }
     |      
     |        <table name>:
     |          The name of the database table, e.g. 'foo').
     |      
     |        <retrieval function>:
     |          The function to initially retrieve the requested data, e.g. It must
     |          accept an iterable of keys as its only argument and return an iterable
     |          over pairs of keys and row data. The row data must itself be an iterable
     |          that corresponds to the table data fields, or None if no data could be
     |          retrieved. Example:
     |      
     |              def retrieve_ex1(keys):
     |                for key in keys:
     |                  try:
     |                    single_value = do_something(key)
     |                  except Whatever:
     |                    yield key, None
     |                  else:
     |                    # Return a tuple
     |                    yield key, (single_value,)
     |      
     |              def retrieve_ex2(keys):
     |                for key in keys:
     |                  try:
     |                    some_iterable = do_something(key)
     |                  except Whatever:
     |                    yield key, None
     |                  else:
     |                    yield key, some_iterable
     |      
     |        <type tuple>:
     |          The database field names and types to use when storing the tuple
     |          retrieved by <retrieval function>. These will be directly used to form
     |          the SQL string, so make sure that they are sanitized before passing
     |          them. Example:
     |      
     |              (('foo', 'TEXT'), ('bar', 'TEXT'))
     |      
     |        <time to live>:
     |          The interval, in seconds, after which to purge the database entry. If
     |          None, then database entries in that table do not expire. Setting this to
     |          a very low value defeats the purpose of using this module.
     |      
     |      null_ttl:
     |        A time which, if given, will limit the lifetime of empty entries. This is
     |        useful when the data source may temporarily return empty values. The empty
     |        value will be cached temporarily to avoid multiple queries in a short
     |        interval, but will not be stored as long as other data (e.g. permanently).
     |  
     |  db_clean(self, wipe=False)
     |      Clean up the database.
     |      
     |      This will drop tables that no longer match the glue. It will also purge all
     |      outdated entries.
     |  
     |  db_create(self, table)
     |      Create a database table.
     |  
     |  db_delete(self, table, key)
     |      Delete a row matching the given key from the database.
     |  
     |  db_delete_many(self, table, keys)
     |      Delete rows matching the given keys from the database.
     |  
     |  db_initialize(self)
     |      (Re-)initialize the database by creating missing tables and cleaning old
     |      entries.
     |  
     |  db_insert(self, table, key, values)
     |      Insert a row for the given key into the database table.
     |  
     |  db_select(self, table, key, cols=None)
     |      Select the values associated with the key in the database table.
     |      
     |      Return the associated row.
     |  
     |  db_select_many(self, table, keys, cols=None)
     |      Select the values associated with the keys in the database table.
     |      
     |      Return the associated rows. The rows are returned in order. If no row was
     |      found, None will be returned for that key.
     |  
     |  get(self, table, key)
     |      Get the values associated with the given key.
     |  
     |  get_cached_data(self, table, key)
     |      If the key is cached and still valid, return the values, otherwise None
     |  
     |  get_cached_data_many(self, table, keys, list_keys=False, cols=None)
     |      The same as get_cached_data for each key, in order. If list_keys is True
     |      then the key itself is returned instead of the values. This can be used to
     |      check which cached queries are still valid.
     |  
     |  get_many(self, table, keys)
     |      Iterate over the values corresponding to the given keys.
     |  
     |  get_nth_field(self, table, key, n=0)
     |      Retrieve the nth item of the returned tuple. This is useful when the
     |      retrieval function only returns a single value.
     |  
     |  get_nth_field_many(self, table, keys, n=0)
     |      Variant of get_nth_field for multiple keys.
     |  
     |  get_one(self, table, key, n=0)
     |      Deprecated function. Use get_nth_field instead.
     |  
     |  raise_mdb_error(self, *args, **kwargs)
     |      Raise a MDBError.
     |  
     |  where_clause(self, keys)
     |      Return a WHERE clause for the given keys.
     |  
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |  
     |  __dict__
     |      dictionary for instance variables (if defined)
     |  
     |  __weakref__
     |      list of weak references to the object (if defined)
     |  
     |  ----------------------------------------------------------------------
     |  Data and other attributes defined here:
     |  
     |  KEY_COLUMN = ('_key', 'TEXT')
     |  
     |  TIMESTAMP_COLUMN = ('_created', 'timestamp')

FUNCTIONS
    sqlite_no_such_table_error(e)
        Return True if the error is the sqlite3.OperationError "no such table".
    
    stabilize(xs)
        Ensure that the given iterable is stable for iteration, i.e. that it is not
        a generator (single iteration) and that each iteration traverses the elements
        in the same order.

DATA
    SQLITE_MAX_EXPR_DEPTH = 999
Contact
echo xyne.archlinux.org | sed 's/\./@/'
Validation
XHTML 1.0 Strict CSS level 3 Atom 1.0