Skip to content

Instantly share code, notes, and snippets.

@mplovepop
Created December 22, 2017 21:53
Show Gist options
  • Save mplovepop/f53e6b3bdb3d65f2fa15168d894d7c7b to your computer and use it in GitHub Desktop.
Save mplovepop/f53e6b3bdb3d65f2fa15168d894d7c7b to your computer and use it in GitHub Desktop.
Utility class to load a named SQL file and use as a query
class SqlFileQuery:
"""Utility class to load a named SQL file and use as a query."""
def __init__(self, filename):
self.filename = filename
@property
def dirpath(self):
return os.path.dirname(os.path.realpath(__file__))
@property
def filepath(self):
return os.path.join(self.dirpath, self.filename)
@property
def query(self):
with open(self.filepath, mode='r') as f:
return f.read()
def __repr__(self):
return '{}(filename={})'.format(type(self).__name__, repr(self.filename))
def __str__(self):
return self.query
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment