Class: DBClass

base.DBClass()

This class provides a central point of reckonning for database interfaces. All modules that preform actions on behalf of the contractual modules have access to the application database interface. This class provides interfaes for different type of databases.

the idea of the different types of DBs

  1. The key value DB is an LRU in memory cache which has disk backup. Different kinds of data structures can be put there -- if a value is out of cache, it can be retrieved from disk. Used in song-search db. Stores files as the value. -- Also, it retrieves files from disk at startup and stores them into the in memory table. (A shim for something like -- Redis might be used.)
  2. The session_key_value_db -- this is for taking in and validating sessions in particular. It might be useful for other -- data collection purposes. This is in-memory records, specifically within an LRU. There is no disk backup. But, -- there is redundancy on secondary machines which will hold sessions for longer periods of time and age them out -- gracefully unless they are accessed.
  3. the pdb - a persistence database is a database that promises to maintain a record with some permanence. It is fronted by -- a key value db with ephemeral properties. But, it can be assumed that the records will be written early in the life of -- a data object. Aging out of the LRU quickly can be expected. And, the data location can be expected to be on a seconday -- machine. (User records -- for customer stats, etc. may be stored here)
  4. the sdb - a static data base. The static db is expected to be fairly similar to a persistence DB, except that it offers the -- guarantee that the data items are stored on a disk local to the process which accesses the code. (This is mostly used to -- create a set of static assets for serving to web sessions. Ideally, the sort of caching available to nginx or other -- web servers might be served by this sort of store.) It is expected that the store will be loaded when the database service -- starts for the general case. (The general case handles as much logic a it can. Dashboard and profile assets can be loaded. -- these are sitewide pages or page frameworks which might be loaded with user specific data.)

Note: both the persistence DB and the static DB will default to using the DB provided by default_persistent_db if these are not configured or passed into the constructor.

NOTE: all the base classes in /lib return the class and do not return an instance. Explore the applications and the reader will find that the descendant modules export instances. The classes provided by copious-transitions must be extended by an application.

Constructor

new DBClass()

Source:

Methods

(async) cache_stored(key, body) → {object}

Parameters:
Name Type Description
key string
body object
Source:
Returns:
Type
object

(async) del_key_value(token)

delete from the key value DB

Parameters:
Name Type Description
token string
Source:

(async) del_session_key_value(key)

Remove the key from the hash table and free up space.

Parameters:
Name Type Description
key string
Source:

(async) del_static_store(whokey)

Parameters:
Name Type Description
whokey string
Source:

disconnect() → {boolean}

This method is made available for applications that will clean up database connections on shutdown or at various other times.

Source:
Returns:
  • the extending class must implement this method
Type
boolean

drop(collection, data)

This is a method for wrapping drop usually associated with a DB for dropping a table. The collection is some object (perhaps a string) identifying the object to be dropped.

Parameters:
Name Type Description
collection object

A table that will be dropped

data object

any data that might be used by a method dropping a DB table.

Source:

exists(collection, data) → {boolean}

A method for checling the existence of some object in a DB table.

Parameters:
Name Type Description
collection object

A table that will containing the item to be found

data object

any data that might be used by a method for searching for an entry

Source:
Returns:
Type
boolean

fetch(key) → {object}

This may be an implementation of get for one of the DB types. But, it may have other properties. This is left as an abstract entry point for an application to define.

Parameters:
Name Type Description
key string
Source:
Returns:
Type
object

(async) fetch_fields(fields_key) → {object}

This method is for fecthing the description of fields that may occur in client forms. This method is called by the method used to configure the validator.

Parameters:
Name Type Description
fields_key string
Source:
Returns:
Type
object

(async) get_key_value(key) → {any}

return the value mapped by the key in the DB. retun null if the value is not present.

Parameters:
Name Type Description
key string

key mapping to the object

Source:
Returns:
Type
any

(async) get_session_key_value(key) → {any}

Get the value from the hash table. The value mapped by the key is often a JSON object. If so, it should be parsed before it is returned.

Parameters:
Name Type Description
key string
Source:
Returns:

The value mapped by the key

Type
any

initialize(conf)

Calls the initialization methods for all the connection based databases interfaces. This includes the key_value_db, the persistent db (pdb), and the static db (sdb). The static_sync interval is read from the configuration.

Parameters:
Name Type Description
conf object
Source:

last_step_initalization()

The method last_step_initalization exists in order to give make a call available to the initialization process in the user_service_class module. This method is called at the start of run.s

Source:

(async) put_static_store(whokey, text, mime_type, extension) → {boolean}

put the object in the static db, which attempts to keep a copy of the asset close to the processor on its own local disks...

wrap the object in a carrier, in which the object is serialized with its mime-type for future transport..

Parameters:
Name Type Description
whokey string
text string
mime_type string
extension string
Source:
Returns:
Type
boolean

remove(collection, data)

Parameters:
Name Type Description
collection object

A table that will containing the item to be removed

data object

any data that might be used by a method removing an entry

Source:

set_hasher(hashfn)

If the hasher is not set during construction, then the application may use this method to set the has function for use by the db.

Parameters:
Name Type Description
hashfn *
Source:

(async) set_key_value(key, value)

Insert or update in the key value DB

Parameters:
Name Type Description
key string
value object
Source:

(async) set_session_key_value(key, value) → {string}

The session storage. Most likely the session storage will be implemented as a shared hash table. Some implementations may user share memory storage. And, some may use DHT (distributed hash tables).

Parameters:
Name Type Description
key string
value object
Source:
Returns:
  • the hash key for the value.
Type
string

(async) static_store(asset) → {object}

Get an object from static store

Parameters:
Name Type Description
asset string
Source:
Returns:

-- the stored object

Type
object

static_synchronizer(sync_function)

Parameters:
Name Type Description
sync_function function
Source:

store(collection, data)

A wrapper for putting data into a table

Parameters:
Name Type Description
collection object

A table that will eventually contain the item

data object

any data that might be used by a method for inserting an entry or the data to be stored

Source:

(async) store_cache(key, data, back_ref)

Parameters:
Name Type Description
key string
data object
back_ref string
Source:

(async) update_cache(key, data, back_ref)

Parameters:
Name Type Description
key string
data object
back_ref string
Source: