"""This model defines our core SQLite database interface."""from__future__importannotationsimportsqlite3fromtypingimportAny
[docs]classDatabase:"""Wrapper around sqlite3.Connection with atomic transactions."""def__init__(self,connection:sqlite3.Connection)->None:connection.row_factory=sqlite3.Row
[docs]defclose(self)->None:"""Closes the SQL connection."""self.connection.close()
[docs]defexecute(self,sql:str,*args:Any)->sqlite3.Cursor:""" Creates a cursor and executes the given SQL statement. :param sql: SQL statement to execute. :param args: Parameters to substitute for placeholders in SQL statement. :returns: The created cursor. """withself.connection:returnself.connection.execute(sql,args)
[docs]defexecutescript(self,script:str)->None:""" Creates a cursor and executes the given SQL script. :param script: SQL script to execute. :returns: The created cursor. """withself.connection:self.connection.cursor().executescript(script)