Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
bmpenuelas committed Dec 11, 2018
1 parent c40d0b7 commit 8a94ce2
Showing 1 changed file with 25 additions and 17 deletions.
42 changes: 25 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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'}`
<br>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')`
<br>`connection = dictiorm.Connection(**database_credentials)`
<br>`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**!
Expand Down Expand Up @@ -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 }`


<br>

* `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'}`
<br>

Example: `validators = { 'username': lambda x: type(x) == str, 'amount': lambda x: x < 1000 }`

<br>

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.

<br>
<br>

* `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.

<br>
<br>

:zero: `initial_values` Fill the doc with additional fields the moment you create it if those fields don't have a value already.
<br>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.
<br>
<br>

: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()`)

<br>
<br>

: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.
<br>Example: `collection.Group({'status': 'active'})` To get all the documents with status active.

0 comments on commit 8a94ce2

Please sign in to comment.