sql_lite.py 590 B

1234567891011121314151617181920212223242526
  1. import sqlite3
  2. from typing import Optional
  3. connection: Optional[sqlite3.Connection] = None
  4. def init_global_db_connection(db_path='./local.db'):
  5. global connection
  6. connection = sqlite3.connect(db_path)
  7. print("SQLite connection is established.")
  8. def get_global_db_connection():
  9. return connection
  10. def close_global_db_connection():
  11. global connection
  12. if connection is not None:
  13. connection.close()
  14. connection = None
  15. print("SQLite connection is closed.")
  16. def init_new_db_connection(db_path='./local.db'):
  17. return sqlite3.connect(db_path)