import sqlite3
from typing import Optional

connection: Optional[sqlite3.Connection] = None


def init_global_db_connection(db_path='./local.db'):
    global connection
    connection = sqlite3.connect(db_path)
    print("SQLite connection is established.")


def get_global_db_connection():
    return connection


def close_global_db_connection():
    global connection
    if connection is not None:
        connection.close()
        connection = None
        print("SQLite connection is closed.")


def init_new_db_connection(db_path='./local.db'):
    return sqlite3.connect(db_path)
