shubhajeet1207 / spyMonk-DB

A document database made with complete Python. While it is NoSQL based database, it's functions are specifically designed with SQL statements.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spyMonkDB

What is the spyMonkDB ?

Welcome! This project is a simple python3 library that uses .json files as a micro noSQL local database. While it is noSQL based database, it's functions are specifically designed with SQL statements in mind. spyMonkDB also enables you to write more complex and speed efficient queries.

Sample usage

from spyMonk.spyMonkDB import spyMonkDB, Query

db = spyMonkDB(connection="users.json", tablename="spyMonkDB")
User = Query(db)

print(db.length()) # int: number of columns

db.filter(User.name == "Shubhajeet")

print(db.all()) 
# List[Dict[str, Any]]: return columns where 
# that include -> {"name": "Shubhajeet"}

db.filter(User.age != 21)

print(db.all()) 
# List[Dict[str, Any]]: return table where 
# that don't include -> {"age": 21}

SQL equivalent restructuring filter

ALL

return result of query or whole table

db.filter(User.name == "Shubhajeet")
print(db.all()) 
# List[Dict[str, Any]]: return columns where 
# that include -> {"name": 21} and limit to 5 return columns

LIMIT

return number of rows up to a specified limit

db.filter(User.age == 21)
print(db.limit(5)) 
# List[Dict[str, Any]]: return columns where 
# that include -> {"age": 21} and limit to 5 return columns

ASC

Note: this is the natural order.

db.filter(User.name == "Shubhajeet")
print(db.asc()) 
# List[Dict[str, Any]]: return columns where 
# that include -> {"name": "Shubhajeet"} 

DESC

reverse of natural order

db.filter(User.name == "Shubhajeet")

print(db.desc()) 
# List[Dict[str, Any]]: return columns where 
# that include -> {"name": "Shubhajeet"} and desc order

SQL equivalent statements

SELECTALL

Equivalent to SELECT * FROM TABLENAME;
returns a result table

db.selectall()

SELECT

Equivalent to SELECT column1, ... FROM TABLENAME;
returns columns the include specified keys

db.select(["name"])

INSERT

Insert new column into database

db.insert({"name": "Shubhajeet", "age": 21,
        "money": None, "Python": True
        "Java": True})

UPDATE

UPDATE table_name SET column1='value1', ... WHERE column1='value1';
Update specific column(s)

db.update({"seal": True}, {"name": "Shubhajeet"})
# add {"seal": True} where {"name": "Shubhajeet"}

TRUNCATE

TRUNCATE TABLE TABLENAME;
This command is irreversible and deletes all data inside a table, but not the table itself.

db.truncate()

DELETE

Equivalent to DELETE FROM TABLENAME WHERE KEY='VALUE';
Drop all columns with same key and value

db.delete({"name": "Shubhajeet"})

Complex Queries

function release()

Return the whole table

Sample usage of release()

from spyMonk.spyMonkDB import spyMonkDB, Query

db = spyMonkDB(connection="users.json", tablename="spyMonkDB")
# No need for Query class

table = db.release() #return the whole database: List[Dict[str, Any]]
query = []

for col in table: 
    if col.get("age") != None and col.get("age") < 20:
        # get all Users that are 20+
        query.append(col)

print(query)

function push()

Delete current database and push given table into database.

Sample usage of push()

from spyMonk.spyMonkDB import spyMonkDB, Query

db = spyMonkDB(connection="users.json", tablename="spyMonkDB")
# No need for Query class

table = db.release() #return the whole database: List[Dict[str, Any]]
query_table = []

for col in table: 
    if col.get("age") != None and col.get("age") > 20:
        # get all Users that are 20+
        query_table.append(col)

db.push(query_table)

About

A document database made with complete Python. While it is NoSQL based database, it's functions are specifically designed with SQL statements.


Languages

Language:Python 100.0%