-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactoring: create base class for db. create db for ipfs
- Loading branch information
1 parent
3cfc5b2
commit 76a2479
Showing
6 changed files
with
87 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
|
||
from .database import DataBase | ||
|
||
class DatalogDB: | ||
def __init__(self, path_to_db_file: str) -> None: | ||
self.db_class = DataBase(path_to_db_file, "datalog") | ||
|
||
def create_table(self) -> None: | ||
self.db_class.create_table("id integer PRIMARY KEY, status text, hash text, time real, payload blob") | ||
|
||
def add_data(self, status, hash, time, payload) -> None: | ||
print("adding data to db") | ||
self.db_class.insert_data("status, hash, time, payload", (status, hash, time, payload)) | ||
|
||
def update_status(self, status, hash) -> None: | ||
self.db_class.update("SET status = ? WHERE hash = ?", (status, hash)) | ||
|
||
def checker(self, current_time) -> list: | ||
time = current_time - 86400 # 24hrs | ||
hashes = self.db_class.get_data("hash", "WHERE time < ? AND status='not sent'", (time,)) | ||
self.db_class.delete_data("WHERE status='sent'") | ||
return hashes | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
from .database import DataBase | ||
|
||
|
||
class IPFSDB: | ||
def __init__(self, path_to_db_file: str) -> None: | ||
self.db_class = DataBase(path_to_db_file, "ipfs") | ||
|
||
def create_table(self) -> None: | ||
self.db_class.create_table("id integer PRIMARY KEY, status text, hash text") | ||
|
||
def add_hash(self, hash: str) -> None: | ||
status = "pinned" | ||
self.db_class.insert_data("status, hash", (status, hash)) |