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.
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}
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
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
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"}
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
Equivalent to SELECT * FROM TABLENAME;
returns a result table
db.selectall()
Equivalent to SELECT column1, ... FROM TABLENAME;
returns columns the include specified keys
db.select(["name"])
Insert new column into database
db.insert({"name": "Shubhajeet", "age": 21,
"money": None, "Python": True
"Java": True})
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 TABLE TABLENAME;
This command is irreversible and deletes all data inside a table, but not the table itself.
db.truncate()
Equivalent to DELETE FROM TABLENAME WHERE KEY='VALUE';
Drop all columns with same key and value
db.delete({"name": "Shubhajeet"})
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)
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)