Skip to content
This repository has been archived by the owner on Aug 2, 2020. It is now read-only.

Latest commit

 

History

History
19 lines (16 loc) · 3.09 KB

data.md

File metadata and controls

19 lines (16 loc) · 3.09 KB

Back to Index

Data Controller

LIMP depends on MongoDB as the database engine of choice. This become the de facto option for LIMP the more the features of MongoDB got updated and improved towards modern apps designs. LIMP handles all necessary functions of MongoDB database bound to LIMP apps using Data Controller object which is locates at https://github.com/masaar/limp/data.py and uses Motor "Asynchronous Python driver for MongoDB". The Data Controller has the following methods:

  1. create_conn: This method requests for a new connection to be initialised.
  2. read: This methods takes env, collection, attrs, extns, modules, query, skip_process as args and attempts to process LIMP query and generate MongoDB-acceptable query and make the call. The method also process the results of MongoDB query for further uniformity with LIMP.
  3. watch: This is read method with watch mode. The method itself is an async Python generator that uses MongoDB native Change Streams feature to watch a collection, docs, or single doc for changes and yields the processed results back to BaseModule then to BaseMethod
  4. create: This method takes env, collection, attrs, modules, doc and creates a MongoDB doc with contents from doc.
  5. update: This method takes env, collection, attrs, modules, docs, doc and use MongoDB update call to update list of docs with contents from doc.
  6. delete: This method takes env, collection, attrs, modules, docs, strategy and use MongoDB update or delete calls to flag docs as deleted, or actually delete them. Learn more about Delete Strategies in API reference for Call.
  7. drop: This method takes env, collection and uses MongoDB drop call to drop the collection from the database.

Additionally, it has set of methods for internal use which are:

  1. _compile_query: Top-tier entry point for processing LIMP query into MongoDB query. This methods strips the special query attrs from LIMP query, prepares reference lists for use across the loop generated by _compile_query_step.
  2. _compile_query_step: This method get called from _compile_query after processing special query attrs and preparing the reference lists. This method iterates over LIMP query object and process every part of it for MongoDB-acceptable aggregate query.
  3. _process_results_doc: This method takes in native Python dict as MongoDB doc and processes it using LIMP Attrs Types, as well as wrap it as DictObj object.

⚠ Warning about Using Data Controller

Data Controller is meant to be used internally only. It's considered a security issue for LIMP modules to access Data Controller directly, as at this level there are no privileges to stop users from accessing data they are not supposed to. The explanation of Data Controller in this article is meant as reference only for what this part of LIMP is doing.