update README.md
This commit is contained in:
		
							
								
								
									
										46
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										46
									
								
								README.md
									
									
									
									
									
								
							| @@ -12,8 +12,52 @@ How MongoDB terms map to smartdata classes | ||||
|  | ||||
| MongoDB term | smartdata class | ||||
| --- | --- | ||||
| Database | smartdata.DbConnection | ||||
| Database | smartdata.Db | ||||
| Collection | smartdata.DbCollection | ||||
| Document | smartdata.DbDoc | ||||
|  | ||||
| ### class Db | ||||
| represents a Database. Naturally it has .connect() etc. methods on it. | ||||
| Since it is a class you can have multiple DBs defined. | ||||
| ```TypeScript | ||||
| import * as smartdata from 'smartdata' | ||||
|  | ||||
| let myDb1 = new smartdata.Db('someConnectionUrl') | ||||
| let myDb2 = new smartdata.Db('someConnectionUrl') | ||||
|  | ||||
| myDb1.connect() | ||||
| myDb2.connect() | ||||
| ``` | ||||
|  | ||||
| ### class Collection | ||||
| represents a collection of objects. | ||||
| A collection is defined by the object class (that is extending smartdata.dbdoc) it respresents | ||||
|  | ||||
| So to get to get access to a specific collection you document | ||||
| ``` | ||||
| class myObject extends DbDoc { | ||||
|     property1:string | ||||
|     property2:number | ||||
|     constructor(optionsArg:{ | ||||
|         queryArg?:any, | ||||
|         dataArg?:{ | ||||
|             property1:string, | ||||
|             property2:string | ||||
|         } | ||||
|     }) { | ||||
|         super(this,optionsArg) | ||||
|     } | ||||
| }  | ||||
| let myCollection = myDb1.getCollection(myObject) | ||||
| ```  | ||||
|  | ||||
| > Alert: You NEVER instantiate a collection. | ||||
| This is done for you!!! | ||||
|  | ||||
| ### class DbDoc | ||||
| represents a individual document in a collection. | ||||
|  | ||||
|  | ||||
|  | ||||
|  | ||||
| [](https://push.rocks) | ||||
|   | ||||
| @@ -1,4 +1,4 @@ | ||||
| import * as plugins from './smartdata.plugins' | ||||
|  | ||||
| export * from './smartdata.classes.dbcollection' | ||||
| export * from './smartdata.classes.dbconnection' | ||||
| export * from './smartdata.classes.db' | ||||
|   | ||||
| @@ -1,11 +1,11 @@ | ||||
| import * as plugins from './smartdata.plugins' | ||||
| 
 | ||||
| export type TDbConnectionStatus = 'disconnected' | 'connected' | 'failed' | ||||
| export type TConnectionStatus = 'disconnected' | 'connected' | 'failed' | ||||
| 
 | ||||
| export class DbConnection { | ||||
| export class Db { | ||||
|     dbUrl: string | ||||
|     db: plugins.mongodb.Db | ||||
|     status: TDbConnectionStatus | ||||
|     status: TConnectionStatus | ||||
| 
 | ||||
|     constructor(dbUrl: string) { | ||||
|         this.dbUrl = dbUrl | ||||
| @@ -1,10 +1,10 @@ | ||||
| import * as plugins from './smartdata.plugins' | ||||
| import { DbConnection } from './smartdata.classes.dbconnection' | ||||
| import { Db } from './smartdata.classes.db' | ||||
|  | ||||
| export class DbCollection<T> { | ||||
|     collection: plugins.mongodb.Collection | ||||
|     constructor(nameArg: string, dbConnectionArg: DbConnection) { | ||||
|         this.collection = dbConnectionArg.db.collection(nameArg) | ||||
|     constructor(nameArg: string, dbArg: Db) { | ||||
|         this.collection = dbArg.db.collection(nameArg) | ||||
|     } | ||||
|  | ||||
|     /** | ||||
|   | ||||
		Reference in New Issue
	
	Block a user