liveBook · Manning

CreateBookmarksTableCommand

As explained in Practices of the Python Pro

A Bark command object whose execution creates the bookmarks table in the database.

CreateBookmarksTableCommand is a command object whose execute method initializes the bookmarks table through DatabaseManager. It keeps table-creation work in the business logic layer while relying only on the persistence interface it needs. section 6.3.2

Its small implementation defines the bookmarks table with:

Creating the table

db = DatabaseManager('bookmarks.db') class CreateBookmarksTableCommand: def execute(self): db.create_table('bookmarks', { 'id': 'integer primary key autoincrement', 'title': 'text not null', 'url': 'text not null', 'notes': 'text', 'date_added': 'text not null', }) section 6.3.2

The design illustrates separation of concerns: the command requests table creation without implementing persistence details. However, its database-specific name and startup wiring can make it span business, persistence, and presentation layers, creating tighter coupling. section 6.3.2 section 10.3

Figure 10.6. Separating concerns into a multitier architecture

Use the multitier architecture figure to relate the command to business, persistence, and presentation responsibilities. section 10.3

How Practices of the Python Pro covers it

How deep it goes
Defines the execute method and complete table schema, then examines cross-layer coupling without detailing its cleanup.
Examples
Uses a Python command that creates a SQLite bookmarks table with identifier, bookmark data, notes, and timestamp columns.
What it assumes
Assumes familiarity with DatabaseManager.create_table and introduces command responsibilities within layered application design.
What you can do after
Build it from scratch by defining a command that delegates table creation to DatabaseManager.
How it connects
Connects the business logic layer, persistence layer, DatabaseManager, separation of concerns, and loose coupling.

This explainer was generated by Manning's knowledge graph from the text of Practices of the Python Pro. The section links point to the parts of the book it draws on.