66![ Tests] ( https://github.com/mkrd/DictDataBase/actions/workflows/test.yml/badge.svg )
77![ Coverage] ( https://github.com/mkrd/DictDataBase/blob/main/assets/coverage.svg?raw=1 )
88
9- DictDataBase is a simple and fast database for handling json or compressed json as the underlying storage mechanism. Features:
10- - ** Multi threading and multi processing safe** . Multiple processes on the same machine can simultaneously read and write to dicts without losing data.
9+ DictDataBase is a simple and fast database for handling json or compressed json as the
10+ underlying storage mechanism. Features:
11+ - ** Multi threading and multi processing safe** . Multiple processes on the same machine
12+ can simultaneously read and write to dicts without losing data.
1113- ** ACID** compliant. Unlike TinyDB, it is suited for concurrent environments.
12- - ** No database server** required. Simply import DictDataBase in your project and use it.
13- - ** Compression** . Configure if the files should be stored as raw json or as json compressed with zlib.
14- - ** Fast** . A dict can be accessed partially without having to parse the entire file, making the read and writes very efficient.
14+ - ** No database server** required. Simply import DictDataBase in your project and use
15+ it.
16+ - ** Compression** . Configure if the files should be stored as raw json or as json
17+ compressed with zlib.
18+ - ** Fast** . A dict can be accessed partially without having to parse the entire file,
19+ making the read and writes very efficient.
1520- ** Tested** with 99%+ coverage.
1621
1722### Why use DictDataBase
1823- For example, have a webserver dispatch database reads and writes concurrently.
1924- If spinning up a database server is a bit too much for your application.
2025 - But you need [ ACID] ( https://en.wikipedia.org/wiki/ACID ) guarantees.
21- - You have a big database but only want to access single key-value pairs repeatedly. DictDataBase can do this efficiently and quickly.
22- - Your use case is suited for working with json data, or you have to work with a lot of json data.
26+ - You have a big database but only want to access single key-value pairs repeatedly.
27+ DictDataBase can do this efficiently and quickly.
28+ - Your use case is suited for working with json data, or you have to work with a lot of
29+ json data.
2330
2431### Why not DictDataBase
2532- If your storage is slow.
@@ -45,19 +52,21 @@ DDB.config.storage_directory = "./ddb_storage" # Default value
4552
4653### Compression
4754If you want to use compressed files, set use_compression to ` True ` .
48- This will make the db files significantly smaller and might improve performance if your disk is slow.
49- However, the files will not be human readable.
55+ This will make the db files significantly smaller and might improve performance if your
56+ disk is slow. However, the files will not be human readable.
5057``` python
5158DDB .config.use_compression = False # Default value
5259```
5360
5461### Indentation
55- Set the way how written json files should be indented. Behaves exactly like ` json.dumps(indent=...) ` .
56- It can be an ` int ` for the number of spaces, the tab character, or ` None ` if you don't want the files to be indented.
62+ Set the way how written json files should be indented. Behaves exactly like
63+ ` json.dumps(indent=...) ` . It can be an ` int ` for the number of spaces, the tab
64+ character, or ` None ` if you don't want the files to be indented.
5765``` python
5866DDB .config.indent = " \t " # Default value
5967```
60- Notice: If ` DDB.config.use_orjson = True ` , then the value can only be 2 (spaces) or 0/None for no indentation.
68+ Notice: If ` DDB.config.use_orjson = True ` , then the value can only be 2 (spaces) or
69+ 0/None for no indentation.
6170
6271### Use orjson
6372You can use the orjson encoder and decoder if you need to.
@@ -126,6 +135,11 @@ above_1 = DDB.at("numbers", where=lambda k, v: v > 1).read()
126135>> > above_1 == {" b" , 2 , " c" : 3 }
127136```
128137
138+ > Note: Doing a partial read like with ` DDB.at("users", key="Joe").read() ` will return
139+ > the value of the key at the outermost indentation level if the key appears in the
140+ > file multiple times.
141+
142+
129143Write dicts
130144----------------------------------------------------------------------------------------
131145
@@ -251,7 +265,8 @@ API Reference
251265### ` at(path) -> DDBMethodChooser: `
252266Select a file or folder to perform an operation on.
253267If you want to select a specific key in a file, use the ` key ` parameter,
254- e.g. ` DDB.at("file", key="subkey") ` .
268+ e.g. ` DDB.at("file", key="subkey") ` . If the key appears multiple times in the file,
269+ the value of the key at the outermost indentation level will be returned.
255270
256271If you want to select an entire folder, use the ` * ` wildcard,
257272eg. ` DDB.at("folder", "*") ` , or ` DDB.at("folder/*") ` . You can also use
0 commit comments