mekasu0124

Untitled

May 5th, 2024
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.94 KB | None | 0 0
  1. import sqlite3 as sql
  2. from src.DreamersDiscoveries.infrastructure.services.result import Result, ResultT
  3.  
  4. class QueryDatabase:
  5.     def __init__(self, helpers):
  6.         self.file_path = helpers.build_database_path()
  7.  
  8.     def check_for_existing_users(self):
  9.         try:
  10.             with sql.connect(self.file_path) as mdb:
  11.                 cur = mdb.cursor()
  12.  
  13.                 try:
  14.                     found_users = cur.execute('SELECT * FROM users').fetchall()
  15.  
  16.                     try:
  17.                         return ResultT.ok(found_users)
  18.                     except Exception as e:
  19.                         return Result.fail("Could Not Return List Of Found Users\n\n", e.__traceback__())
  20.  
  21.                 except Exception as e:
  22.                     return Result.fail("Could Not Execute Query\n\n", e.__traceback__())
  23.  
  24.         except Exception as e:
  25.             return Result.fail("Could Not Connect To The Database\n\n", e.__traceback__())
Advertisement
Add Comment
Please, Sign In to add comment