PysonDB
- Install
- Example Code
- Command Line Operations
- Adding Data
- Get data
- Search data
- Update Data
- Delete Data
Update Data
- Update command also check for Schemma.
- Schemma violating data will be rejected.
- Methods:
- updateById(ID,query)
- There is a unique ID assigned for each json data.
- update(query,what_to_update)
- update({“name”:”pysondb”},{“name”:”pyson”}).
- Updates the all value of key “pysondb” to pyson
- updateArray(query, prop, value, max_capacity=optional)
- Appends to an already existing array in the data
- updateById(ID,query)
JSON file:file.json
{"data": [{"name": "PysonDB", "type": "DB", "score": "10", "id": 5161221802},
{"name": "Pyson-CLI", "type": "CLI", "score": "10", "id": 2242313690},
{"name": "Tiny", "type": "DB", "score": "9", "id": 6991190264},
{"name": "QWERTY", "type": "DB", "score": "5", "id": 9416036202}]}
updateById(ID,what_to_update)
- ID=Integer
>> from pysondb import db
>> a=db.getDb("file.json")
>> a.updateById("9416036202",{"name":"Qwerty12"})
>> a.getBy({"name":"Qwerty12"})
>> #In the file.json the data is updated.
>> #We can verify it below.
>> [{"name": "Qwerty12", "type": "DB", "score": "5", "id": 9416036202}]
update(query,what_to_update)
- query,what_to_update are both JSON data.
>> from pysondb import db
>> a=db.getDb("file.json")
>> a.update({"name":"Pyson-CLI"},{"name":"PysonCLI"})
>> a.getBy({"name":"PysonCLI"})
>> # In the file.json the data is updated for all data where name=Pyson-CLI
>> # We can verify it below.
>> [{"name": "PysonCLI", "type": "CLI", "score": "10", "id": 2242313690}]
updateArray(query, prop_to_update, value_to_append, max_array_capacity=float('inf'))
- max_array_capacity is optional. If len(array) >= max_array_capacity, the first element gets popped
>> from pysondb import db
>> a=db.getDb("file.json")
>> a.getBy({"name":"ArrayEntry"})
>> [{"name":"ArrayEntry", "epic_array":[0,1,2]}]
>> a.updateArray({"name":"ArrayEntry"},"epic_array",3)
>> a.getBy({"name":"ArrayEntry"})
>> # In the file.json the data is updated for all data where name=Pyson-CLI
>> # We can verify it below.
>> [{"name": "ArrayEntry", "epic_array":[0,1,2,3]}]
>> a.updateArray({"name":"ArrayEntry"}, "epic_array", 4, 4)
>> a.getBy({"name":"ArrayEntry"})
>> [{"name": "ArrayEntry", "epic_array":[1,2,3,4]}