File tree Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Expand file tree Collapse file tree 1 file changed +35
-0
lines changed Original file line number Diff line number Diff line change
1
+ import uuid
2
+ from jsonbox import JsonBox
3
+
4
+ # generate unique box id
5
+ MY_BOX_ID = str (uuid .uuid4 ()).replace ("-" , "_" )
6
+
7
+ # create instance
8
+ jb = JsonBox ()
9
+
10
+ data = [{"name" : "David" , "age" : "25" }, {"name" : "Alice" , "age" : "19" }]
11
+
12
+ # write data
13
+ result = jb .write (data , MY_BOX_ID )
14
+
15
+ # get record id of written data
16
+ record_ids = jb .get_record_id (result )
17
+
18
+ # read record
19
+ print (jb .read (MY_BOX_ID , record_ids [0 ]))
20
+
21
+ # read all records in box
22
+ print (jb .read (MY_BOX_ID ))
23
+
24
+ # read all records in box with sort
25
+ print (jb .read (MY_BOX_ID , sort_by = "age" ))
26
+
27
+ # update data
28
+ data = {"name" : "Bob" , "age" : "25" }
29
+ jb .update (data , MY_BOX_ID , record_ids [0 ])
30
+
31
+ # read updated data
32
+ print (jb .read (MY_BOX_ID , record_ids [0 ]))
33
+
34
+ # delete records
35
+ jb .delete (MY_BOX_ID , record_ids )
You can’t perform that action at this time.
0 commit comments