from sqlite3 import connect
from typing import Sequence

from ._DatabaseInfo import DatabaseInfo


class InMemorySqliteDatabaseCreator(object):
    def __init__(self, database_infos: Sequence[DatabaseInfo]):
        self.database_infos = database_infos

        self.conns = []

    def create_temporary_memory_databases(self):
        for db_info in self.database_infos:
            for conn_string in db_info.all_conn_strings:
                self.conns.append(connect(database=conn_string, uri=True))

    def destroy_temporary_memory_databases(self):
        for conn in self.conns:
            conn.close()
