Adding yet more index maintenance

Clearly, the index maintenance aspect of a shelf can grow. With our simple data model, we could easily add more top-level indexes for tags, dates, and titles of Posts. Here's another access layer implementation that defines two indices for Blogs. One index simply lists the keys for Blog entries. The other index provides keys based on the Blog title. We'll assume the titles are not unique. We'll present this access layer in three parts. Here's the Create part of the CRUD processing:

class Access4( Access2 ): def new( self, *args, **kw ): super().new( *args, **kw ) self.database['_DB:Blog']= list() self.database['_DB:Blog_Title']= defaultdict(list) def add_blog( self, blog ): self.max['Blog'] += 1 key= "Blog:{id}".format(id=self.max['Blog']) ...

Get Mastering Object-oriented Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.