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. HawkDB also enables you to write more complex and speed efficient queries. (Shown in Complex User Queries).
HawkDB was chosen as the final name for the project but the early name was PyDB
Check out Disclaimer
This is a proof of concept. I developed this project to challenge myself learn about the internals of databases, software design and object oriented programming.
from Hawk import Pydb, Query
db = Pydb(connection="Users.json", tablename="Users")
User = Query(db)
print(db.length()) # int: number of columns
db.filter(User.name == "Yusuf")
print(db.all())
# List[Dict[str, Any]]: return columns where
# that include -> {"name": "Yusuf"}
db.filter(User.age != 16)
print(db.all())
# List[Dict[str, Any]]: return table where
# that don't include -> {"age": 16}
return result of query or whole table
db.filter(User.name == "Yusuf")
print(db.all())
# List[Dict[str, Any]]: return columns where
# that include -> {"name": 16} and limit to 5 return columns
return number of rows up to a specified limit
db.filter(User.age == 16)
print(db.limit(5))
# List[Dict[str, Any]]: return columns where
# that include -> {"age": 16} and limit to 5 return columns
Note: this is the natural order.
db.filter(User.name == "Yusuf")
print(db.asc())
# List[Dict[str, Any]]: return columns where
# that include -> {"name": "Yusuf"}
reverse of natural order
db.filter(User.name == "Yusuf")
print(db.desc())
# List[Dict[str, Any]]: return columns where
# that include -> {"name": "Yusuf"} and desc order
is a hotel you think this is a joke but i am serious this is an actual method
db.trivago()
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": "Yusuf", "age": 16,
"money": None, "Python": True
"Java": False})
UPDATE table_name SET column1='value1', ... WHERE column1='value1';
Update specific column(s)
db.update({"seal": True}, {"name": "Yusuf"})
# add {"seal": True} where {"name": "Yusuf"}
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": "Yusuf"})
through the use of these functions you will have the ability to do anything with the database:
Return the whole table
Sample usage of release()
from pydb import Pydb, Query
db = Pydb(connection="Users.json", tablename="Users")
# 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 pydb import Pydb, Query
db = Pydb(connection="Users.json", tablename="Users")
# 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)