sanskrit_data.db

This package aims to achieve database neutrality - we abstract database-client operations and database operations using interfaces so as to enable one to easily switch the database one uses.

class sanskrit_data.db.ClientInterface[source]

Bases: object

A common interface to a database server or system.

Accessing databases through implementations of this interface enables one to switch databases more easily down the line.

delete_database(db_name)[source]

Delete a database, with which one can instantiate a suitable DbInterface subclass.

Parameters:db_name (str) – Name of the database which needs to be deleted.
get_database(db_name)[source]

Create or get a database, with which one can instantiate a suitable DbInterface subclass.

While it is better to use get_database_interface() generally, we expose this in order to support DbInterface subclasses which may be defined outside this module. :param str db_name: Name of the database which needs to be accessed (The database is created if it does not already exist). :returns DbInterface db: A database interface implementation for accessing this database.

get_database_interface(db_name)[source]

Create or get a suitable DbInterface subclass.

Parameters:db_name (str) – Name of the database which needs to be accessed (The database is created if it does not already exist).
Returns DbInterface db:
 A database interface implementation for accessing this database.
class sanskrit_data.db.DbInterface[source]

Bases: object

A common interface to a database.

Accessing databases through implementations of this interface enables one to switch databases more easily down the line.

add_index(keys_json, index_name)[source]

Index the database using certain fields.

Parameters:keys_json – A document that contains the field and value pairs where the field is the index key and the value describes the type of index for that field. For an ascending index on a field, specify a value of 1; for descending index, specify a value of -1.
delete_doc(doc_id)[source]
Parameters:doc_id
Returns:Not used.
find(find_filter)[source]

Find matching objects from the database.

Should be a generator and return an iterator: ie it should use the yield keyword.

Parameters:find_filter (dict) – A mango or mongo query.
Returns:Returns None if nothing is found. Else a python dict representing a JSON object.
find_by_id(id)[source]
Parameters:id
Returns:Returns None if nothing is found. Else a python dict representing a JSON object.
find_one(find_filter)[source]

Fine one matching object from the database.

Parameters:find_filter – A mango or mongo query.
Returns:Returns None if nothing is found. Else a python dict representing a JSON object.
update_doc(doc)[source]

Update or insert a json object, represented as a dict.

Parameters:doc (dict) – _id parameter determines the key. One will be created if it does not exist. This argument could be modified.
Returns:updated dict with _id set.
update_index(name, fields, upsert=False)[source]

Create or update (if upsert=True) an index over certain fields, with a given name.

Package diagram

Open the below image in a new tab and zoom in for clarity.

_images/packages_sanskrit_data_db.png

Class diagram

Open the below image in a new tab and zoom in for clarity.

_images/classes_sanskrit_data_db.png