forked from sungkhum/MicroPyDatabase
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsandbox.py
More file actions
36 lines (28 loc) · 1.15 KB
/
sandbox.py
File metadata and controls
36 lines (28 loc) · 1.15 KB
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
31
32
"""
Sandbox for MicroPyDatabase
A low-memory json-based databse for MicroPython.
Data is stored in a folder structure in json for easy inspection.
This file contains sample usage.
"""
#Database examples:
db_object = Database.create("mydb2")
db_object = Database.open("mydb")
#Table examples:
db_table = db_object.create_table("mytable", ["name", "password"])
db_table = db_object.open_table("mytable")
db_table.truncate()
#Insert examples:
db_table.insert({"name": "nate", "password": "coolpassword"})
db_table.insert([{"name": "whothere", "password": "ohyeah"}, {"name": "whothere", "password": "ohyeah"}, {"name": "whothere", "password": "ohyeah"}])
#Low-level operations using internal row_id:
db_table.find_row(5)
db_table.update_row(300, {'name': 'bob'})
db_table.delete_row(445)
db_table.find_by_column_value("name", "bob")
f = db_table.scan()
f.__next__()
#High-level operations using queries:
db_table.find({"name": "blah", "password": "something"})
db_table.query({"name": "blah", "password": "something"})
db_table.update({"name": "blah8", "password": "yeah8"}, {"name": "blah9", "password": "yeah9"})
db_table.delete({"name": "blah9", "password": "yeah9"})