For this small object model, we can implement the entire access layer in a single class. This class will include methods to perform CRUD operations on each of our persistent classes.
This example won't painstakingly include all of the methods for a complete access layer. We'll show you the important ones. We'll break this down into several sections to deal with Blogs, Posts, and iterators. Here's the first part of our access layer:
# An access layer to map back and forth between Python objects and SQL rows.class Access: get_last_id = """ SELECT last_insert_rowid() """ def open(self, path: Path) -> None: self.database = sqlite3.connect(path) self.database.row_factory = sqlite3.Row def get_blog(self, id: ...