From 8d7d9adef11ed13afab349118eda69218b3e2914 Mon Sep 17 00:00:00 2001 From: Phil Kunz Date: Wed, 4 Sep 2019 17:25:50 +0200 Subject: [PATCH] fix(core): update --- README.md | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index c71f7cf..0879956 100644 --- a/README.md +++ b/README.md @@ -93,27 +93,38 @@ MyObject.getInstance({ represents a individual document in a collection and thereby is ideally suited to extend the class you want to actually store. -**sStore** instances of classes to Db: +### CRUD operations +smartdata supports full CRUD operations + +**Store** or **Update** instances of classes to MongoDB: DbDoc extends your class with the following methods: -- `.save()` will save (or update) the object you call it on only. Any referenced non-savable objects will not get stored. -- `.saveDeep()` does the same like `.save()`. +- async `.save()` will save (or update) the object you call it on only. Any referenced non-savable objects will not get stored. +- async `.saveDeep()` does the same like `.save()`. In addition it will look for properties that reference an object that extends DbDoc as well and call .saveDeep() on them as well. Loops are prevented -**Get** a new class instance from a Doc in the DB: -DbDoc exposes a static method that allows you specify a filter to retrieve a cloned class of the one you used to that doc at some point later in time. Yes, let that sink in a minute :) +**Get** a new class instance from MongoDB: +DbDoc exposes a static method that allows you specify a filter to retrieve a cloned class of the one you used to that doc at some point later in time: + +* static async `.getInstance({ /* filter props here */ })` gets you an instance that has the data of the first matched document as properties. +* static async `getInstances({ /* filter props here */ })` get you an array instances (one instance for every matched document). + +**Delete** instances from MongoDb: +smartdata extends your class with a method to easily delete the doucment from DB: + +* async `.delete()`will delete the document from DB. + + -So you can just call `.getInstance({ /* filter props here */ })`. ## TypeScript How does TypeScript play into this? Since you define your classes in TypeScript and types flow through smartdata in a generic way you should get all the Intellisense and type checking you love when using smartdata. -smartdata itself also bundles typings. -So you don't need to install any additional types when importing smartdata. +smartdata itself also bundles typings. You don't need to install any additional types for smartdata. For further information read the linked docs at the top of this readme.