optimize local db
This commit is contained in:
+20
-2
@@ -1,9 +1,14 @@
|
||||
from builtins import list
|
||||
|
||||
import sqlalchemy
|
||||
from sqlalchemy import MetaData, Column, String, Integer, DateTime, Table
|
||||
from sqlalchemy.orm import Session
|
||||
from sqlalchemy_utils import database_exists, create_database
|
||||
|
||||
from pojo.captcha_error_contact_pojo import ContactInErrorPojo
|
||||
import definitions
|
||||
import params
|
||||
from pojo.ReserveResultPojo import ReserveResultPojo
|
||||
from pojo.captcha_error_contact_pojo import ContactInErrorPojo, ERROR_TYPE_CAPTCHA
|
||||
|
||||
|
||||
class LocalDbManager:
|
||||
@@ -12,7 +17,7 @@ class LocalDbManager:
|
||||
self.session = Session(self.init_db(path))
|
||||
|
||||
def init_db(self, path: str):
|
||||
uri_for_db = "sqlite:///{}/{}.db".format(path, "appointment")
|
||||
uri_for_db = "sqlite:///{}/{}.db?check_same_thread=false".format(path, "appointment")
|
||||
print(uri_for_db)
|
||||
# 2.-Turn on database engine
|
||||
db_engine = sqlalchemy.create_engine(uri_for_db) # ensure this is the correct path for the sqlite file.
|
||||
@@ -43,3 +48,16 @@ class LocalDbManager:
|
||||
def insert_or_update(self, instance: ContactInErrorPojo):
|
||||
self.session.merge(instance)
|
||||
self.session.commit()
|
||||
|
||||
def get_all_captcha_error_contacts(self) -> list:
|
||||
return self.session.query(ContactInErrorPojo).filter(ContactInErrorPojo.error_type == ERROR_TYPE_CAPTCHA).all()
|
||||
|
||||
def handle_success(self, reservePojo: ReserveResultPojo):
|
||||
# delete the contact from table
|
||||
self.session.query(ContactInErrorPojo).filter(ContactInErrorPojo.mail == reservePojo.email).delete()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
list = params.local_db_manager.get_all_captcha_error_contacts()
|
||||
for item in list:
|
||||
print(item.mail)
|
||||
|
||||
Reference in New Issue
Block a user