forked from tadgh/ArgoRevisit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Query.py
36 lines (30 loc) · 935 Bytes
/
Query.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import time
import logging
__author__ = 'Gary'
logging.basicConfig(level=logging.INFO, format='%(asctime)s -> %(message)s')
log = logging.getLogger(__name__)
class Query(object):
def __init__(self, tag):
self.tag = tag
self.arguments = []
def prepare(self):
pass
def execute(self, object_count=None):
self.prepare()
start = time.time()
results = self.db_command()
count = 0
if results:
for item in results:
count += 1
end = time.time()
log.info(self.tag + " took " + "%.2f" % (end - start) + " seconds. Returned " + str(count) + " records.")
try:
results.close()
except:
pass
else:
print("Managed to close connection.")
return "%.2f" % (end - start)
def db_command(self):
raise NotImplementedError("You need to implement this!")