Skip to content

Commit

Permalink
Create CreateQuery
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Jul 29, 2019
1 parent d8f5ab8 commit e3bf3b3
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ def get_all_results(self):
raise MissingRecordError(" No results found")


class CreateQuery(Query):

def __init__(self, table, row):
super().__init__(table)
self.row = row

def execute_query(self):
"""Determines if the row is a row object or dictionary then commits it to the table"""
if type(self.row) is not dict:
record = self.row
else:
record = self.table()
record.update_from_dict(self.row)
record.CREATE_TIME = datetime.datetime.now()
record.MOD_TIME = datetime.datetime.now()
record.CREATE_ID = "user"
record.MOD_ID = "user" # These will need changing
self.session.add(record)
self.commit_changes()


def insert_row_into_table(row):
"""
Insert the given row into its table
Expand Down

0 comments on commit e3bf3b3

Please sign in to comment.