Browse Source

Added storage schema creation and storage initialization logic

master
Illia Chub 1 year ago
parent
commit
725fde29c9
  1. 1
      .gitignore
  2. 73
      main.py
  3. BIN
      selfprivacy-storage.db-journal

1
.gitignore vendored

@ -0,0 +1 @@
selfprivacy-storage.db

73
main.py

@ -1,28 +1,95 @@
from flask import Flask
from flask import Flask, request
from flask_restful import Resource, Api, reqparse
import pyodbc
def main():
global databaseConnectionDescriptor
global databaseSelector
databaseSelector.execute("SELECT Initialized FROM system")
for row in databaseSelector:
print(row)
if not row[0] == True:
InitializeStorage(databaseSelector)
app = Flask(__name__)
storage = Api(app)
if __name__ == '__main__':
app.run(port=5051, debug=False)
@app.route("/storage/query", methods=["GET"])
def query():
ExecuteArbitraryQuery(databaseSelector, request.args.get("query"))
@app.route("/storage/write", methods=["PUT"])
def write():
InsertRowIntoTable(databaseSelector,
request.headers.get("X-Table"),
request.headers.get("X-Rows"),
request.headers.get("X-Values")
)
def ExecuteArbitraryQuery(databaseSelector, query: str):
databaseSelector.execute(query)
databaseConnectionDescriptor.commit()
def InsertRowIntoTable(databaseSelector, table: str, rows: str, values: str):
databaseSelector.execute(
"INSERT INTO " + table + "(" + rows + ")" +
"VALUES" + "(" + values + ")"
"VALUES" + "(" + values + ");"
)
databaseConnectionDescriptor = pyodbc.connect('DRIVER={Devart ODBC Driver for SQLite};Direct=True;Database=selfprivacy-storage;String Types= Unicode')
def InitializeStorage(databasseSelector):
databaseSelector.execute(
'''
CREATE TABLE principal (
Owner TINYTEXT,
Data LONGTEXT,
Hash LONGTEXT,
Writeable BOOLEAN
);
'''
)
databaseSelector.execute(
'''
CREATE TABLE IF NOT EXISTS system (
Initialized BOOLEAN
);
'''
)
databaseSelector.execute(
'''
INSERT INTO system (Initialized)
VALUES (True);
'''
)
print("[INFO] Storage initialized!")
databaseConnectionDescriptor.commit()
databaseConnectionDescriptor = pyodbc.connect('DRIVER={Devart ODBC Driver for SQLite};Direct=True;Database=selfprivacy-storage.db;String Types= Unicode')
databaseSelector = databaseConnectionDescriptor.cursor()
main()

BIN
selfprivacy-storage.db-journal

Binary file not shown.
Loading…
Cancel
Save