Advertisement
gray_beard

new_admin_1

Feb 2nd, 2023
697
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. @contextmanager
  2. def conn_context(db_path):
  3.     conn = sqlite3.connect(db_path)
  4.     conn.row_factory = sqlite3.Row
  5.     yield conn
  6.     conn.close()
  7.  
  8.  
  9. class PostgresSaver:
  10.     def __init__(self, pg_conn: _connection):
  11.         self.connection = pg_conn
  12.         self.cursor = pg_conn.cursor()
  13.  
  14.     def save_all_data(self, ...):
  15.         ...
  16.  
  17. class SQLiteExtractor:
  18.     def __init__(self, connection):
  19.         self.conn = connection
  20.         self.cur = self.conn.cursor()
  21.  
  22.     def extract_movies(self, ...):
  23.         ...
  24.  
  25. def load_from_sqlite(connection: sqlite3.Connection, pg_con: _connection):
  26.     postgres_saver = PostgresSaver(pg_con)
  27.     sqlite_extractor = SQLiteExtractor(connection)
  28.     ...
  29.  
  30. if __name__ == '__main__':
  31.  
  32.     with (conn_context('db.sqlite') as sqlite_conn,
  33.             psycopg2.connect(**dsl, cursor_factory=DictCursor) as pg_conn):
  34.         load_from_sqlite(sqlite_conn, pg_conn)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement