Advertisement
BERKYT

Attempt ORM

Aug 21st, 2022
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.28 KB | None | 0 0
  1. class SQLite:
  2.     def __init__(self, ip, psw):
  3.         pass
  4.  
  5.     def connect(self):
  6.         print('Successful.')
  7.  
  8.  
  9. class DB_sql:
  10.     def __init__(self):
  11.         pass
  12.  
  13.     def connect(self, ip, psw):
  14.         try:
  15.             SQLite(ip, psw).connect()
  16.         except Exception as e:
  17.             print(e)
  18.  
  19.     def request(self, var):
  20.         print('Successful.')
  21.    
  22.     def close(self):
  23.         pass
  24.  
  25.  
  26. class Table:
  27.     def __init__(self, **kwargs):
  28.         self.db: DB_sql = DB_sql()
  29.         self.db.connect('lh', '123')
  30.  
  31.         for key, value in kwargs.items():
  32.             self.__setattr__(str(key), value)
  33.             self.db.request((str(key), value))
  34.  
  35.         self.db.close()
  36.  
  37.     def get_value(self, target):
  38.         self.db: DB_sql = DB_sql()
  39.         self.db.connect('lh', '123')
  40.  
  41.         attrs = dir(self)
  42.  
  43.         for value in attrs:
  44.             if target == value:
  45.                 try:
  46.                     self.db.request(f'GET {target} FROM {self.__class__.__name__}')
  47.                     print(target, self.__dict__[target])
  48.                 except Exception as e:
  49.                     print(e)
  50.                 finally:
  51.                     self.db.close()
  52.  
  53.  
  54. if __name__ == '__main__':
  55.     db = Table(x=1, y=2, z=3)      
  56.     db.get_value('x')
  57.    
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement