liveBook · Manning

CRUD

As explained in AI-Powered Developer: Build software with ChatGPT and Copilot

CRUD operations are the four basic data-management actions: create, read, update, and delete.

CRUD names the four basic data-management actions: create, read, update, and delete. A repository interface can make these operations explicit while allowing the underlying storage to change. section 4.3.3

A practical implementation starts with an in-memory list of assets. This supports an end-to-end test before replacing temporary storage with PostgreSQL, while keeping the business domain insulated behind repository ports. section 4.3.3

A generic repository typically exposes these operations:

Listing 4.26 Code for BaseRepository, our generic data access layer
from abc import ABC, abstractmethod
from typing import List, TypeVar, Generic
  
T = TypeVar('T')
  
class BaseRepository(ABC, Generic[T]):
    @abstractmethod
    def create(self, entity: T) -> None:
        pass
  
    @abstractmethod
    def read(self, entity_id: int) -> T:
        pass
  
    @abstractmethod
    def update(self, entity: T) -> None:
        pass
  
    @abstractmethod
    def delete(self, entity_id: int) -> None:
        pass
  
    @abstractmethod
    def get_entities(self) -> List[T]:
        pass

Shows a typed Python BaseRepository abstract class whose contract includes create, read, update, delete, and entity-listing methods. section 4.3.3

Assets with an in-memory repository

InMemoryAssetRepository stores Asset objects in a list, appends on create, searches by id on read, replaces matching objects on update, and filters matching objects out on delete. AssetManager delegates its asset operations to this repository. section 4.3.3

How AI-Powered Developer: Build software with ChatGPT and Copilot covers it

How deep it goes
Defines a generic interface and implements list-backed operations, then defers durable PostgreSQL persistence to a later step.
Examples
Demonstrates CRUD through BaseRepository, InMemoryAssetRepository, AssetManager, asset endpoints, and PostgreSQL users granted data access.
What you can do after
Build CRUD from scratch with a typed repository interface, test it in memory, and connect durable database storage afterward.
How it connects
Connects CRUD with the Repository pattern, generic typing, AssetManager, in-memory storage, and PostgreSQL persistence.

Also explained in

Compare how 11 books explain CRUD →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Developer: Build software with ChatGPT and Copilot. The section links point to the parts of the book it draws on.