-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathupdate.py
More file actions
30 lines (26 loc) · 846 Bytes
/
update.py
File metadata and controls
30 lines (26 loc) · 846 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from pprint import pprint
from tinydb import TinyDB, where
with TinyDB("ten_countries.json") as countries_db:
countries_tb = countries_db.table(name="countries")
countries_tb.update(
{"population": 130_575_786},
where("location") == "Mexico",
)
countries_tb.update(
{"source": "National quarterly update"},
where("location") == "Mexico",
)
pprint(countries_tb.search(where("location") == "Mexico"))
countries_tb.update_multiple(
[
(
{"population": 130_575_786},
where("location") == "Mexico",
),
(
{"source": "National quarterly update"},
where("location") == "Mexico",
),
]
)
countries_tb.update({"source": "Official estimate"}, doc_ids=[7, 9])