improve README

This commit is contained in:
Philipp Kunz 2016-11-18 00:59:57 +01:00
parent 90d9a25b3f
commit 0b8adea736
4 changed files with 15 additions and 8 deletions

View File

@ -63,8 +63,8 @@ So to get to get access to a specific collection you document
@Collection(myDb1) @Collection(myDb1)
class myObject extends smartdata.DbDoc<myObject> { // read the next block about DbDoc class myObject extends smartdata.DbDoc<myObject> { // read the next block about DbDoc
property1:string @smartdata.saveable property1: string // @smartdata.saveable marks the property for db save
property2:number property2: number // this one is not marked, so it won't be save upon calling this.save()
constructor(optionsArg:{ constructor(optionsArg:{
property1: string, property1: string,
property2: number property2: number

View File

@ -1,5 +1,5 @@
import { DbCollection } from './smartdata.classes.dbcollection'; import { DbCollection } from './smartdata.classes.dbcollection';
export declare type TDocCreation = 'db' | 'data' | 'mixed'; export declare type TDocCreation = 'db' | 'new' | 'mixed';
/** /**
* sva - saveable decorator to be used on class properties * sva - saveable decorator to be used on class properties
*/ */

View File

@ -23,7 +23,7 @@ describe('mongodb', function () {
this.timeout(30000) this.timeout(30000)
mongoChildProcess = shelljs.exec('mongod --dbpath=./test/data --port 27017', { async: true, silent: true }) mongoChildProcess = shelljs.exec('mongod --dbpath=./test/data --port 27017', { async: true, silent: true })
let doneCalled = false let doneCalled = false
mongoChildProcess.stdout.on('data', function (data) { mongoChildProcess.stdout.on('new', function (data) {
console.log(smartstring.indent.indentWithPrefix(data, '*** MongoDB Process *** : ')) console.log(smartstring.indent.indentWithPrefix(data, '*** MongoDB Process *** : '))
if (!doneCalled) { if (!doneCalled) {
if (/waiting for connections on port 27017/.test(data)) { if (/waiting for connections on port 27017/.test(data)) {

View File

@ -3,10 +3,10 @@ import * as plugins from './smartdata.plugins'
import { Db } from './smartdata.classes.db' import { Db } from './smartdata.classes.db'
import { DbCollection } from './smartdata.classes.dbcollection' import { DbCollection } from './smartdata.classes.dbcollection'
export type TDocCreation = 'db' | 'data' | 'mixed' export type TDocCreation = 'db' | 'new' | 'mixed'
/** /**
* sva - saveable decorator to be used on class properties * saveable - saveable decorator to be used on class properties
*/ */
export function saveable(target: DbDoc<any>, key: string) { export function saveable(target: DbDoc<any>, key: string) {
console.log('called sva') console.log('called sva')
@ -47,6 +47,13 @@ export class DbDoc<T> {
for (let propertyNameString of this.saveableProperties) { for (let propertyNameString of this.saveableProperties) {
saveableObject[propertyNameString] = this[propertyNameString] saveableObject[propertyNameString] = this[propertyNameString]
} }
switch (this.creationType) {
case 'db':
this.collection // TODO implement collection.update()
break
case 'new':
this.collection.insertOne(saveableObject)
}
} }
/** /**