Skip to content

Commit 3d81299

Browse files
committed
docs: update Database.find()
1 parent bbffbd7 commit 3d81299

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Supports to find by key and value with `Condition` that is generated from `Key`.
13+
1014
Thanks for getting this release out! please stay tuned :)
1115

1216
## [0.2.3] - 2023-01-18

docs/source/examples/database/basic.rst

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,13 +111,30 @@ Multiple items
111111
Find
112112
^^^^
113113

114+
You can find objects with passing lambda function to handle each items. For example:
115+
114116
.. code-block:: python
115117
116118
>>> db.find(lambda x: x['type'].endswith('e'))
117119
['2g4kaFAiDBPchz66HNPsZa', 'dpKsCc7evmV7Mxq8ikgY89', 'fewugXnJHosmaXeqbXrLtD']
118120
>>> db.get(['2g4kaFAiDBPchz66HNPsZa', 'dpKsCc7evmV7Mxq8ikgY89', 'fewugXnJHosmaXeqbXrLtD'])
119121
[{'id': 1001, 'type': 'Chocolate'}, {'id': 1002, 'type': 'Orange'}, {'id': 1003, 'type': 'Apple'}]
120122
123+
Also we provide flexible wrappers for `==`, `!=`, `<`, `<=`, `>`, `>=` to comparison operators.
124+
125+
.. code-block:: python
126+
127+
>>> from json_as_db import Key
128+
>>> db = Database()
129+
>>> db.add([{'product': 'Chocolate', 'amount': 10}, {'product': 'Orange', 'amount': 1}, {'product': 'Apple', 'amount': 3}])
130+
['oTTno3xwizirjM6skVrZsi', 'Gw9pwyeV6cXJbHkT3sSUaW', 'LVw4smsL9WRgtRo5bTSnuX']
131+
>>> db.find(Key('type') == 'Chocolate')
132+
['oTTno3xwizirjM6skVrZsi']
133+
>>> db.find(Key('product') > 'Apple')
134+
['oTTno3xwizirjM6skVrZsi', 'Gw9pwyeV6cXJbHkT3sSUaW']
135+
>>> db.find(Key('amount') <= 3)
136+
['Gw9pwyeV6cXJbHkT3sSUaW', 'LVw4smsL9WRgtRo5bTSnuX']
137+
121138
122139
Commit & Rollback
123140
^^^^^^^^^^^^^^^^^

0 commit comments

Comments
 (0)