Skip to content

Commit

Permalink
initialize distribution files
Browse files Browse the repository at this point in the history
  • Loading branch information
Grant Moore committed Feb 5, 2022
1 parent cd801e6 commit a22e3c1
Show file tree
Hide file tree
Showing 7 changed files with 740 additions and 34 deletions.
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion innoldb/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ def getLogger(name: str) -> logging.Logger:
logger = logging.getLogger(name)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
logger.setLevel(logging.INFO)
logger.setLevel(logging.NOTSET)
logger.addHandler(consoleHandler)
return logger
22 changes: 12 additions & 10 deletions innoldb/qldb.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def driver(ledger):
"""
return QldbDriver(ledger_name=ledger)

@staticmethod
def tables(ledger):
return QldbDriver(ledger_name=ledger).list_tables()

@staticmethod
def create_table(driver, table):
"""Static method for creating a table within a ledger
Expand Down Expand Up @@ -159,35 +163,33 @@ def _init_fixtures(self):
try:
Driver.create_table(self.driver, self.table)
except Exception as e:
log.warn(e)
log.debug(e)
try:
Driver.create_index(self.driver, self.table, self.index)
except Exception as e:
log.warn(e)
log.debug(e)

def _insert(self, document):
log.info("Inserting DOCUMENT(%s = %s)", self.index, document[self.index])
log.debug("Inserting DOCUMENT(%s = %s)", self.index, document[self.index])
return Driver.insert(self.driver, document, self.table)

def _update(self, document):
log.info("Updating DOCUMENT(%s = %s)", self.index, document[self.index])
log.debug("Updating DOCUMENT(%s = %s)", self.index, document[self.index])
return Driver.update(self.driver, document, self.table, self.index)

def exists(self, id):
log.info("Checking existence of DOCUMENT(%s = %s)", self.index, id)
log.debug("Checking existence of DOCUMENT(%s = %s)", self.index, id)
result = Driver.query_by_field(self.driver, self.index, id, self.table)
# for row in result:
# log.debug("Query returned with row %s", row)
if next(result, None):
return True
return False

def get(self, id):
log.info("Returning DOCUMENT(%s = %s)", self.index, id)
log.debug("Returning DOCUMENT(%s = %s)", self.index, id)
return loads(dumps(next(Driver.query_by_field(self.driver, self.index, id, self.table))))

def save(self, document):
log.info("Saving DOCUMENT(%s = %s)", self.index, document[self.index])
log.debug("Saving DOCUMENT(%s = %s)", self.index, document[self.index])
if self.exists(document[self.index]):
return self._update(document)
return self._insert(document)
Expand All @@ -213,4 +215,4 @@ def fields(self):
def save(self):
result = super().save(self.fields())
for row in result:
log.info('Transaction result: \n\t\t\t\t\t\t\t %s', loads(dumps(row)))
log.debug('Transaction result: \n\t\t\t\t\t\t\t %s', loads(dumps(row)))
41 changes: 18 additions & 23 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import argparse
import sys
import random
from innoldb.qldb import Document
Expand Down Expand Up @@ -27,39 +28,33 @@ def create():
def load(id):
return Document(name='innolab', id=id)

def update_speciality(document):
document.specialty = specialities[random.randint(0, len(specialities) - 1)]
document.save()

def update_prop(document, key, value):
setattr(document, key, value)
document.save()

if __name__=="__main__":
if len(sys.argv) > 1:
routines = sys.argv[1:]
parser = argparse.ArgumentParser()
parser.add_argument('--load', help="id of the document to load")
parser.add_argument('--update', help="KEY=VALUE")
parser.add_argument('--display', action='store_true', help="Print document to screen")

if routines[0] == 'load':
document = load('0434ade7-86bb-11ec-935a-34735aabbbc4')
log.info("Loaded DOCUMENT: \n\t\t\t\t\t\t\t %s", document.fields())
args = parser.parse_args()

if args.load:
document = load(args.load)
log.info("Loaded DOCUMENT(%s = %s)", document.index, document.fields()[document.index])

else:
document = create()
log.info("Created DOCUMENT: \n\t\t\t\t\t\t\t %s", document.fields())
log.info("Created DOCUMENT(%s = %s)", document.index, document.fields()[document.index])

if args.update:
key, value = args.update.split("=")
update_prop(document, key, value)

if args.display:
print(document.fields())

for routine in routines:
if routine == 'update_spec':
update_speciality(document)
elif routine == 'update_prop_1':
update_prop(document, 'favorite_movie', 'children of men')
elif routine == 'update_prop_2':
update_prop(document, 'favorite_movie', 'pulp fiction')
elif routine == 'update_prop_3':
update_prop(document, 'favorite_movie', 'lords of salem')
elif routine == 'update_prop_4':
update_prop(document, 'favorite_movie', 'the big lebowski')
elif routine == 'update_prop_5':
update_prop(document, 'favorite_movie', 'the evil dead')

# if __name__==:""
# from qldb.qldb import Driver
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
requires = ["setuptools", "wheel"]
build-backend = "setuptools.build_meta"
32 changes: 32 additions & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[metadata]
name = scrilla
version = file: version.txt
author = Makpar Innovation Lab
author_email = [email protected]
description = a ORM model for AWS QLDB
long_description = file: README.md
long_description_content_type = text/markdown
license = GNU GPL v3
license_file = LICENSE
platform = any
keywords = aws, qldb, quantum-ledger-database, orm
classifers=
Programming Language :: Python :: 3
License:: GNU GPL v3
Operating System :: OS Independent
project_urls =
Documentation = https://github.com/Makpar-Innovation-Laboratory/innolqb
Source = https://github.com/Makpar-Innovation-Laboratory/innolqb

[options]
python_requires = >= 3.8
package_dir=
=innolqb
packages=find:
install_requires =
amazon.ion >=0.9.1
pyqldb >=3.2.2
python-dotenv >=0.19.2

[options.packages.find]
where=innolqb
1 change: 1 addition & 0 deletions version.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1.0.0

0 comments on commit a22e3c1

Please sign in to comment.