In these example we are using this basic setup:
class Product {
constructor(
public displayName: string,
public price: number,
public isAvailable: boolean,
) {}
}
const registry: Registry<Product> = new Registry<Product>();
const uuidTestProduct: string = registry.insert(new Product('TestProduct', 9.99, true));
const uuidTestProduct2: string = registry.insert(new Product('TestProduct2', 9.99, false));
const testProduct: Product = registry.findOne({ uuid: uuid });
console.log(testProduct.displayName); // <-- Should return "TestProduct"
const testProduct: Product = registry.findOne({ where: { displayName: 'TestProduct' } });
console.log(testProduct.displayName); // <-- Should return "TestProduct"
const products: Product[] = registry.find({ where: { price: 9.99 } });
console.log(products); // <-- Should return an array with all 2 products
console.log(products[1].displayName); // <-- Should return "TestProduct2"
const products: Product[] = registry.find();
console.log(products); // <-- Should return an array with all 2 products
const uuid: string = registry.findUuid({ where: { displayName: 'TestProduct2' } });
console.log(uuidTestProduct2 === uuid); // <-- Should return true
You can either use the "where" option or the "uuid" option to specify which entry should be deleted
const response: boolean = registry.delete({ where: { displayName: 'TestProduct2' } });
console.log(response); // <-- Should return true