From 8a94ce26ecedff7f7d292875d282740528e3564b Mon Sep 17 00:00:00 2001 From: Borja Penuelas Date: Tue, 11 Dec 2018 01:13:30 +0100 Subject: [PATCH] Update README.md --- README.md | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/README.md b/README.md index 7e5dab9..96e792d 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ True - And you still have access to document cache/update, find/count, all the methods of a dict variable and **validation** ```python ->>> validation_funcs = { 'username': lambda x: type(x)==str, 'status': lambda x: type(x)==str } +>>> validation_funcs = { 'username': lambda x: type(x)==str, 'status': lambda x: x in ('on', 'off') } >>> user_info = collection.Document({'username': 'user0'}, validators=validation_funcs) ... >>> user_info.pop('status') # 'status' was popped. As it is a required field, it will fail validation. @@ -40,13 +40,13 @@ ValueError: Validation failed. Not all the required fields are present. Missing: :raising_hand: How is it used? ------------------------------ -Simply put: **like you use a normal dictionary in Python**, with some additional features. You just need: +Simply put: **like you use a normal dictionary in Python**. You just need: * The field or fields and values used to select the specific document that you want. - Example: `unique_identifier = {'customer_type': 'premium', username': 'user0'}` +
Example: `unique_identifier = {'customer_type': 'premium', username': 'user0'}` * A connection to your database and the desired collection. This is made easy with: - `connection = dictiorm.Connection(**database_credentials)` - `collection = connection.Collection('collection_name')` +
`connection = dictiorm.Connection(**database_credentials)` +
`collection = connection.Collection('collection_name')` That's all you need to create a dictiORM object! It will behave like a **dictionary**, and data will be automagically mirrored with a database **document**! @@ -79,32 +79,40 @@ Check out [the examples](/example) for more. :bulb: Additional functionalities --------------------------------- -:ballot_box_with_check: `validators` **This is an really useful feature!** You can define a function that evaluates whether if the value of a field fulfills some requirements. If at any moment an invalid value was to be assigned, it would not pass the validation and that modification would never happen. Not in the local object, neither in the database. - Example: `validators = { 'username': lambda x: type(x) == str, 'amount': lambda x: x < 1000 }` - - +
-* `initial_values` Fill the doc with additional fields the moment you create it if those fields don't have a value already. +:ballot_box_with_check: `validators` **This is an really useful feature!** You can define a function that evaluates whether if the value of a field fulfills some requirements. If at any moment an invalid value was to be assigned, it would not pass the validation and that modification would never happen. Not in the local object, neither in the database. - Example: `initial_values = {'status': 'registered'}` +
+Example: `validators = { 'username': lambda x: type(x) == str, 'amount': lambda x: x < 1000 }` +
You can set validators for any number of fields that you want, and let the other fields be changed freely, or... -* `only_validated_fields` you can set this to `True`. This way this dictionary will only be allowed to contain the fields that you have set validators for, and only with values that pass your validation criteria. - +* `only_validated_fields` you can set this to `True` and this dictionary will only be allowed to contain the fields that you have set validators for, and only with values that pass your validation criteria. +
+
-* `always_access_db` By default, every modification is mirrored in the database. You can disable this and do it manually whenever you want using: +:arrows_clockwise: `always_access_db` By default, every modification is mirrored in the database. You can disable this and do it manually whenever you want using: - some_doc.update_memory() to read the database and apply changes to your local object. - some_doc.update_database() to upload local modifications to the database. +
+
+:zero: `initial_values` Fill the doc with additional fields the moment you create it if those fields don't have a value already. +
Example: `initial_values = {'status': 'registered'}` -* `some_doc.delete()` Remove the document from the database. Removal of the object in memory is performed automatically by Python's garbage collection. +
+
+:x: `some_doc.delete()` Remove the document from the database. Removal of the object in memory is performed automatically by Python's garbage collection. (Also available as `Group.delete_all()`) +
+
-:paperclip: `Group` You can get the all the documents that match some filter with a single command. - Example: `collection.Group({'status': 'active'})` To get all the documents with status active. +:paperclip: `Group` You can get the all the documents that match some filter inside a collection with a single command. +
Example: `collection.Group({'status': 'active'})` To get all the documents with status active.