Skip to content

Commit f0e6950

Browse files
committed
Closing all db connections after executing command
1 parent 34d1dec commit f0e6950

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

backend/PyMatcha/utils/orm/_model.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ def save(self):
177177
with self.db.cursor() as c:
178178
c.execute(query, tuple(values))
179179
self.db.commit()
180+
c.close()
180181

181182
def update(self, _dict={}, **kwargs):
182183
"""
@@ -210,6 +211,7 @@ def delete(self):
210211
)
211212
self.db.commit()
212213
logging.debug("deleted {} from table {}".format(self.id, self.table_name))
214+
c.close()
213215
else:
214216
logging.fatal("{} Not in table {}".format(self.id, self.table_name))
215217
raise Exception("{} Not in table {}".format(self.id, self.table_name))
@@ -249,6 +251,7 @@ def get(cls, **kwargs):
249251
)
250252

251253
data = c.fetchone()
254+
c.close()
252255
if data:
253256
return cls(data)
254257
else:
@@ -293,8 +296,8 @@ def get_multi(cls, **kwargs) -> List:
293296
fields=", ".join(temp.fields.keys()), table=cls.table_name, where=where
294297
)
295298
)
296-
297299
data = c.fetchone()
300+
c.close()
298301
if data:
299302
return cls(data)
300303
else:
@@ -345,6 +348,7 @@ def get_multis(cls, **kwargs):
345348
)
346349

347350
data = c.fetchall()
351+
c.close()
348352
if data:
349353
ret_list = []
350354
for i in data:
@@ -360,6 +364,7 @@ def select_all(cls):
360364
with temp.db.cursor() as c:
361365
c.execute("""SELECT * FROM {}""".format(cls.table_name))
362366
data = c.fetchall()
367+
c.close()
363368
for item in data:
364369
yield cls(item)
365370

@@ -369,6 +374,7 @@ def drop_table(cls):
369374
with cls.db.cursor() as c:
370375
c.execute("""DROP TABLE {}""".format(cls.table_name))
371376
cls.db.commit()
377+
c.close()
372378

373379
def to_dict(self):
374380
ret_dict = dict()

0 commit comments

Comments
 (0)