@@ -51,23 +51,40 @@ def main():
5151 # Let's make sure it doesn't have any data
5252 print ("Should be empty: %s" % json .dumps (collection .data .query ()))
5353
54- # Let's add some data
54+ # Let's add some json data
5555 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" })
5758 collection .data .insert (json .dumps ({"somekey" : 3 , "otherkey" : "bar" }))
5859
5960 # Let's make sure it has the data we just entered
6061 print ("Should have our data: %s" % json .dumps (collection .data .query (), indent = 1 ))
6162
6263 # Let's run some queries
6364 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+
6477
6578 query = json .dumps ({"otherkey" : "foo" })
6679 print ("Should return item1 and item2: %s" % json .dumps (collection .data .query (query = query ), indent = 1 ))
6780
6881 query = json .dumps ({"otherkey" : "bar" })
6982 print ("Should return third item with auto-generated _key: %s" % json .dumps (collection .data .query (query = query ), indent = 1 ))
70-
83+
84+ # passing query data as dict
85+ query = {"somekey" : {"$gt" : 1 }}
86+ print ("Should return item2 and item3: %s" % json .dumps (collection .data .query (query = query ), indent = 1 ))
87+
7188 # Let's delete the collection
7289 collection .delete ()
7390
0 commit comments