liveBook · Manning

ListBookmarksCommand

As explained in Practices of the Python Pro

A Bark command object that retrieves bookmark records from the database in a specified order.

ListBookmarksCommand is a business-logic command that retrieves saved bookmarks and makes their ordering explicit. It accepts an ordering column, stores it, passes it to the database query, and returns all rows. section 6.3.2

List bookmarks by date

class ListBookmarksCommand: def __init__(self, order_by='date_added'): self.order_by = order_by def execute(self): return db.select('bookmarks', order_by=self.order_by).fetchall() The default lists bookmarks by date added; callers can provide another column, such as title. section 6.3.2

Figure 6.7. The business logic layer determines when and how data is read from or written to the persistence layer.

The business logic layer decides when and how bookmark data is read from the persistence layer. section 6.3.2

How Practices of the Python Pro covers it

How deep it goes
Implements the constructor, ordering attribute, database selection, and fetchall result, without covering presentation rendering.
Examples
Demonstrates a Python command defaulting to date_added and returning selected bookmark rows with fetchall().
What it assumes
Assumes a bookmarks table and DatabaseManager.select, while demonstrating the command’s ordering and result-retrieval steps.
What you can do after
Build it from scratch to query bookmarks and return them in a chosen database-column order.
How it connects
Connects the business logic layer with DatabaseManager and the persistence layer.

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.