Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sungkhum/MicroPyDatabase
A low-memory json-based database for MicroPython
https://github.com/sungkhum/MicroPyDatabase
Last synced: about 2 months ago
JSON representation
A low-memory json-based database for MicroPython
- Host: GitHub
- URL: https://github.com/sungkhum/MicroPyDatabase
- Owner: sungkhum
- License: mit
- Created: 2019-08-19T04:54:09.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-03-11T01:08:37.000Z (almost 2 years ago)
- Last Synced: 2024-08-04T00:07:27.169Z (5 months ago)
- Language: Python
- Size: 106 KB
- Stars: 16
- Watchers: 2
- Forks: 10
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: changelog.md
- License: LICENSE
Awesome Lists containing this project
- awesome-micropython - MicroPyDatabase - A low-memory JSON-based database for MicroPython. (Libraries / Storage)
README
# MicroPyDatabase
A low-memory json-based database for MicroPython.
Data is stored in a folder structure in json for easy inspection.Install prerequisites:
`micropython -m upip install micropython-os`
`micropython -m upip install micropython-os.path`or
```
>>> import upip
>>> upip.install("micropython-os”)
>>> upip.install("micropython-os.path”)
```Usage instructions :
```
import micropydatabase
```
Create a new database:
```
db_object = micropydatabase.Database.create("mydb")
```
Open an existing database:
```
db_object = micropydatabase.Database.open("mydb")
```
Create a new table (specifying column names [and types if you need it]):
*(Table column definition supported types are **str**, **int** and **bool**. Default is **str**.)*
```
db_object = micropydatabase.Database.open("mydb")
db_object.create_table("mytable", ["name", "password"])
db_object.create_table("mytable", {
"name":str,
"age":int,
"isMember":bool
})
```
Insert data into table:
```
db_object = micropydatabase.Database.open("mydb")
db_table = db_object.open_table("mytable")
db_table.insert({"name": "lucy", "password": "coolpassword"}) # as dict
db_table.insert(["Rose", "MySecret"]) # as list
```
Multi-insert data into table:
```
db_object = micropydatabase.Database.open("mydb")
db_table = db_object.open_table("mytable")
db_table.insert([
{"name": "john", "password": "apassword"},
{"name": "john", "password": "apassword"},
{"name": "bob", "password": "thispassword"},
{"name": "sally", "password": "anotherpassword"}
])
```
Find (returns first result):
```
db_object = micropydatabase.Database.open("mydb")
db_table = db_object.open_table("mytable")
db_table.find({"name": "john", "password": "apassword"})
```
Query (returns all results):
```
db_object = micropydatabase.Database.open("mydb")
db_table = db_object.open_table("mytable")
db_table.query({"name": "john", "password": "apassword"})
```
Update Row (search query, updated row data):
```
db_object = micropydatabase.Database.open("mydb")
db_table = db_object.open_table("mytable")
db_table.update(
{"name": "bob", "password": "thispassword"}, #find what
{"name": "george", "password": "somethingelse"} # change with
)
```
Delete Row:
```
db_object = micropydatabase.Database.open("mydb")
db_table = db_object.open_table("mytable")
db_table.delete({"name": "george", "password": "somethingelse"})
```
Scan (iterate through each row in table):
```
db_object = micropydatabase.Database.open("mydb")
db_table = db_object.open_table("mytable")
f = db_table.scan()
f.__next__()
```
Scan with Query (iterate through rows that match query):
```
db_object = micropydatabase.Database.open("mydb")
db_table = db_object.open_table("mytable")
f = db_table.scan({"name": "john", "password": "apassword"})
f.__next__()
```
Truncate Table (delete all table contents):
```
db_object = micropydatabase.Database.open("mydb")
db_table = db_object.open_table("mytable")
db_table.truncate()
```Vaccum Table (reorganize all content):
```
db_object = micropydatabase.Database.open("mydb")
db_table = db_object.open_table("mytable")
db_table.vaccum()
```