Skip to content

Instantly share code, notes, and snippets.

@JosianChevalier
Created November 11, 2024 21:37
Show Gist options
  • Save JosianChevalier/eb73a2268f43c868bab0e2d5768530c4 to your computer and use it in GitHub Desktop.
Save JosianChevalier/eb73a2268f43c868bab0e2d5768530c4 to your computer and use it in GitHub Desktop.
An in-memory implementation of persistence mechanism
interface ProductRepository {
save(product: Product): Promise<void>;
load(id: ProductId): Promise<Product | null>;
}
export default class InMemoryProductRepository implements ProductRepository {
private products = new Map<string, Product>();
async save(product: Product) {
this.products.set(product.id.toString(), product);
}
async load(id: ProductId): Promise<Product | null> {
return this.products.get(id.toString()) || null;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment