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 supportDbInterface
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.
-
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.
-