Git Product home page Git Product logo

micropydatabase's Introduction

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()

micropydatabase's People

Contributors

lixas avatar peyman avatar sungkhum avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

micropydatabase's Issues

attribute does not exist

In the examples given

db_table.find_by_column_value("name", "bob"))

causes an error

AttributeError: 'Table' object has no attribute 'find_by_column_value'

I don't have the python skills to fix or suggest a fix - Can you please help resolve this?

My use case is to have a table of serial numbers and to return a description based on a search on the name column

Query with 1 result is out of sequence

When I query a table with just 1 result I get the following:

{'r': 1, 'd': {'time': '23/01/27_11:32:12', 'data': '1', 'temperature': 20.95853}}

If I add another row then the results are as expected:
{'time': '23/01/27_11:32:12', 'data': '1', 'temperature': 20.95853} {'time': '23/01/27_11:36:37', 'data': '1', 'temperature': 21.89482}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.