siglatools.databases package#

Submodules#

siglatools.databases.constants module#

class siglatools.databases.constants.CompositeVariableField[source]#

Bases: object

index = 'index'#
sigla_answers = 'sigla_answers'#
variable = 'variable'#
variables = 'variables'#
class siglatools.databases.constants.DatabaseCollection[source]#

Bases: object

amendments = 'amendments'#
body_of_law = 'body_of_law'#
institutions = 'institutions'#
rights = 'rights'#
variables = 'variables'#
class siglatools.databases.constants.DatabaseField[source]#

Bases: object

collection = 'collection'#
primary_keys = 'primary_keys'#
class siglatools.databases.constants.Environment[source]#

Bases: object

production = 'production'#
staging = 'staging'#
class siglatools.databases.constants.InstitutionField[source]#

Bases: object

category = 'category'#
country = 'country'#
name = 'name'#
sheet_id = 'sheet_id'#
spreadsheet_id = 'spreadsheet_id'#
sub_category = 'sub_category'#
class siglatools.databases.constants.SiglaAnswerField[source]#

Bases: object

answer = 'answer'#
name = 'name'#
class siglatools.databases.constants.VariableField[source]#

Bases: object

heading = 'heading'#
institution = 'institution'#
name = 'name'#
orig_text = 'orig_text'#
sigla_answer = 'sigla_answer'#
source = 'source'#
type = 'type'#
variable_index = 'variable_index'#
class siglatools.databases.constants.VariableType[source]#

Bases: object

aggregate = 'aggregate'#
composite = 'composite'#
standard = 'standard'#

siglatools.databases.exceptions module#

exception siglatools.databases.exceptions.UnableToFindDocument(info: ErrorInfo)[source]#

Bases: BaseError

siglatools.databases.mongodb_database module#

class siglatools.databases.mongodb_database.MongoDBDatabase(db_connection_url: str)[source]#

Bases: object

clean_up()[source]#

Delete all documents from the database.

close_connection()[source]#

Cleanup client resources and disconnect from MongoDB.

delete_many(collection: str, doc_ids: List[ObjectId])[source]#

Delete documents from the database.

Parameters:
  • collection (str) – The db collection to delete document from.

  • doc_ids (List[ObjectId]) – The list of document ids to delete.

find(collection: str, filters: Dict[str, Any], sort: Optional[List[Tuple[str, str]]] = None) List[Dict[str, Any]][source]#

Query the database for documents.

Parameters:
  • collection (str) – The db collection to query for documents.

  • filters (Dict[str, Any]) – A prototype document that all results must match.

  • sort (Optional[List[Tuple[str, str]]]) – A list of (key, direction) pairs specifying the sort order for this query.

Returns:

docs – The list of matched documents.

Return type:

List[Dict[str, Any]]

load(formatted_sheet_data: FormattedSheetData)[source]#

Load the formatted sheet data into the database.

Parameters:

formatted_sheet_data (FormattedSheetData) – The formatted sheet data. Please see the class FormattedSheetData to view its attributes.

Module contents#