Skip to content

Commit

Permalink
Create abstract base query class
Browse files Browse the repository at this point in the history
  • Loading branch information
keiranjprice101 committed Jul 29, 2019
1 parent 27cfed0 commit b6b92b5
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions common/database_helpers.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import datetime
import logging
from abc import ABC, abstractmethod

from sqlalchemy import create_engine, asc, desc
from sqlalchemy.orm import sessionmaker
Expand All @@ -23,6 +24,28 @@ def get_icat_db_session():
return session


class Query(ABC):
@abstractmethod
def __init__(self, table):
self.session = get_icat_db_session()
self.table = table
self.base_query = self.session.query(table)
self.is_limited = False

@abstractmethod
def execute_query(self):
pass

def commit_changes(self):
"""
Commits all changes to the database and closes the session
"""
log.info(f" Commiting changes to {self.table}")
self.session.commit()
log.info(f" Closing DB session")
self.session.close()


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

0 comments on commit b6b92b5

Please sign in to comment.