@@ -51,16 +51,29 @@ def main():
51
51
# Let's make sure it doesn't have any data
52
52
print ("Should be empty: %s" % json .dumps (collection .data .query ()))
53
53
54
- # Let's add some data
54
+ # Let's add some json data
55
55
collection .data .insert (json .dumps ({"_key" : "item1" , "somekey" : 1 , "otherkey" : "foo" }))
56
- collection .data .insert (json .dumps ({"_key" : "item2" , "somekey" : 2 , "otherkey" : "foo" }))
56
+ #Let's add data as a dictionary object
57
+ collection .data .insert ({"_key" : "item2" , "somekey" : 2 , "otherkey" : "foo" })
57
58
collection .data .insert (json .dumps ({"somekey" : 3 , "otherkey" : "bar" }))
58
59
59
60
# Let's make sure it has the data we just entered
60
61
print ("Should have our data: %s" % json .dumps (collection .data .query (), indent = 1 ))
61
62
62
63
# Let's run some queries
63
64
print ("Should return item1: %s" % json .dumps (collection .data .query_by_id ("item1" ), indent = 1 ))
65
+
66
+ #Let's update some data
67
+ data = collection .data .query_by_id ("item2" )
68
+ data ['otherkey' ] = "bar"
69
+ #Passing data using 'json.dumps'
70
+ collection .data .update ("item2" , json .dumps (data ))
71
+ print ("Should return item2 with updated data: %s" % json .dumps (collection .data .query_by_id ("item2" ), indent = 1 ))
72
+ data ['otherkey' ] = "foo"
73
+ # Passing data as a dictionary instance
74
+ collection .data .update ("item2" , data )
75
+ print ("Should return item2 with updated data: %s" % json .dumps (collection .data .query_by_id ("item2" ), indent = 1 ))
76
+
64
77
65
78
query = json .dumps ({"otherkey" : "foo" })
66
79
print ("Should return item1 and item2: %s" % json .dumps (collection .data .query (query = query ), indent = 1 ))
0 commit comments