diff --git a/README.md b/README.md index 389b382..9946f88 100644 --- a/README.md +++ b/README.md @@ -63,11 +63,11 @@ So to get to get access to a specific collection you document @Collection(myDb1) class myObject extends smartdata.DbDoc { // read the next block about DbDoc - property1:string - property2:number + @smartdata.saveable property1: string // @smartdata.saveable marks the property for db save + property2: number // this one is not marked, so it won't be save upon calling this.save() constructor(optionsArg:{ - property1:string, - property2:number + property1: string, + property2: number }) { super() } diff --git a/dist/smartdata.classes.dbdoc.d.ts b/dist/smartdata.classes.dbdoc.d.ts index 7c32743..61c6932 100644 --- a/dist/smartdata.classes.dbdoc.d.ts +++ b/dist/smartdata.classes.dbdoc.d.ts @@ -1,5 +1,5 @@ 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 */ diff --git a/test/test.ts b/test/test.ts index e7a241d..0fda708 100644 --- a/test/test.ts +++ b/test/test.ts @@ -23,7 +23,7 @@ describe('mongodb', function () { this.timeout(30000) mongoChildProcess = shelljs.exec('mongod --dbpath=./test/data --port 27017', { async: true, silent: true }) let doneCalled = false - mongoChildProcess.stdout.on('data', function (data) { + mongoChildProcess.stdout.on('new', function (data) { console.log(smartstring.indent.indentWithPrefix(data, '*** MongoDB Process *** : ')) if (!doneCalled) { if (/waiting for connections on port 27017/.test(data)) { diff --git a/ts/smartdata.classes.dbdoc.ts b/ts/smartdata.classes.dbdoc.ts index 133c995..2829a2b 100644 --- a/ts/smartdata.classes.dbdoc.ts +++ b/ts/smartdata.classes.dbdoc.ts @@ -3,10 +3,10 @@ import * as plugins from './smartdata.plugins' import { Db } from './smartdata.classes.db' 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, key: string) { console.log('called sva') @@ -47,6 +47,13 @@ export class DbDoc { for (let propertyNameString of this.saveableProperties) { saveableObject[propertyNameString] = this[propertyNameString] } + switch (this.creationType) { + case 'db': + this.collection // TODO implement collection.update() + break + case 'new': + this.collection.insertOne(saveableObject) + } } /**