fix(core): update
This commit is contained in:
		
							
								
								
									
										22
									
								
								readme.md
									
									
									
									
									
								
							
							
						
						
									
										22
									
								
								readme.md
									
									
									
									
									
								
							| @@ -49,6 +49,7 @@ How RethinkDB's terms map to the ones of smartdata: | |||||||
| represents a Database. Naturally it has .connect() etc. methods on it. | represents a Database. Naturally it has .connect() etc. methods on it. | ||||||
|  |  | ||||||
| ```typescript | ```typescript | ||||||
|  | // Assuming toplevel await | ||||||
| import * as smartdata from 'smartdata'; | import * as smartdata from 'smartdata'; | ||||||
|  |  | ||||||
| const smartdataDb = new smartdata.SmartdataDb({ | const smartdataDb = new smartdata.SmartdataDb({ | ||||||
| @@ -57,7 +58,7 @@ const smartdataDb = new smartdata.SmartdataDb({ | |||||||
|   mongoDbPass: 'mypassword', |   mongoDbPass: 'mypassword', | ||||||
| }); | }); | ||||||
|  |  | ||||||
| smartdataDb.connect(); | await smartdataDb.connect(); | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
| ### class DbCollection | ### class DbCollection | ||||||
| @@ -68,10 +69,11 @@ A collection is defined by the object class (that is extending smartdata.dbdoc) | |||||||
| So to get to get access to a specific collection you document | So to get to get access to a specific collection you document | ||||||
|  |  | ||||||
| ```typescript | ```typescript | ||||||
|  | // Assuming toplevel await | ||||||
| // continues from the block before... | // continues from the block before... | ||||||
|  |  | ||||||
| @smartdata.Collection(smartdataDb) | @smartdata.Collection(smartdataDb) | ||||||
| class MyObject extends smartdata.DbDoc<MyObject> { | class MyObject extends smartdata.DbDoc<MyObject /* ,[an optional interface to implement] */> { | ||||||
|   // read the next block about DbDoc |   // read the next block about DbDoc | ||||||
|   @smartdata.svDb() |   @smartdata.svDb() | ||||||
|   property1: string; // @smartdata.svDb() marks the property for db save |   property1: string; // @smartdata.svDb() marks the property for db save | ||||||
| @@ -87,14 +89,22 @@ class MyObject extends smartdata.DbDoc<MyObject> { | |||||||
|  |  | ||||||
| const localObject = new MyObject({ | const localObject = new MyObject({ | ||||||
|   property1: 'hi', |   property1: 'hi', | ||||||
|   property2: 2, |   property2: { | ||||||
|  |     deep: 3 | ||||||
|  |   }, | ||||||
| }); | }); | ||||||
| localObject.save(); // saves the object to the database | await localObject.save(); // saves the object to the database | ||||||
|  |  | ||||||
| // start retrieving instances | // start retrieving instances | ||||||
|  |  | ||||||
| MyObject.getInstance<MyObject>({ | // .getInstance is staticly inheritied, yet fully typed static function to get instances with fully typed filters | ||||||
|   property: 'hi', | const myInstance = await MyObject.getInstance({ | ||||||
|  |   property1: 'hi', | ||||||
|  |   property2: { | ||||||
|  |     deep: { | ||||||
|  |       $gt: 2 | ||||||
|  |     } as any | ||||||
|  |   } | ||||||
| }); // outputs a new instance of MyObject with the values from db assigned | }); // outputs a new instance of MyObject with the values from db assigned | ||||||
| ``` | ``` | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user