added Decorator support for easy connection between classes and collections

This commit is contained in:
Philipp Kunz 2016-09-14 01:02:11 +02:00
parent f7f7852b7f
commit 6683c05c22
12 changed files with 53 additions and 23 deletions

View File

@ -41,6 +41,7 @@ So to get to get access to a specific collection you document
```typescript ```typescript
// continues from the block before... // continues from the block before...
@Collection(myDb1)
class myObject extends smartdata.DbDoc { // read the next block about DbDoc class myObject extends smartdata.DbDoc { // read the next block about DbDoc
property1:string property1:string
property2:number property2:number
@ -48,7 +49,7 @@ class myObject extends smartdata.DbDoc { // read the next block about DbDoc
property1:string, property1:string,
property2:number property2:number
}) { }) {
super(this,myDb1) super()
} }
} }
let myCollection = myDb1.getCollectionByName<myObject>(myObject) let myCollection = myDb1.getCollectionByName<myObject>(myObject)
@ -71,10 +72,6 @@ DbDoc extends your class with the following methods:
So now we can **store** instances of classes to Db... So now we can **store** instances of classes to Db...
How do we **get** a new class instance from a Doc in the DB? How do we **get** a new class instance from a Doc in the DB?
Easy! Take a look at the constructor. When you specify `optionsArg.queryArg`
smartdata will fill in the data from the database!
But when you specify a `optionsArg.dataArg` instead
the data for the class is taken from there :)
## TypeScript ## TypeScript
How does TypeScript play into this? How does TypeScript play into this?

View File

@ -21,4 +21,5 @@ export declare class Db {
* gets a collection by name: string * gets a collection by name: string
*/ */
getCollectionByName<T>(nameArg: string): plugins.q.Promise<DbCollection<T>>; getCollectionByName<T>(nameArg: string): plugins.q.Promise<DbCollection<T>>;
addCollection(dbCollectionArg: DbCollection<any>): void;
} }

View File

@ -48,6 +48,9 @@ class Db {
return done.promise; return done.promise;
} }
; ;
addCollection(dbCollectionArg) {
this.collections.add(dbCollectionArg);
}
} }
exports.Db = Db; exports.Db = Db;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYi50cyJdLCJuY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sQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFBO1FBQzVCLElBQUksQ0FBQyxFQUFFLENBQUMsS0FBSyxFQUFFLENBQUE7UUFDZixPQUFPLENBQUMsU0FBUyxDQUFDLEVBQUUsQ0FBQywrQkFBK0IsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDLENBQUE7UUFDakUsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztJQUVELDRFQUE0RTtJQUU1RTs7T0FFRztJQUNILG1CQUFtQixDQUFJLE9BQWU7UUFDbEMsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQXFCLENBQUE7UUFDL0MsSUFBSSxnQkFBZ0IsR0FBRyxJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksQ0FBQyxDQUFDLGVBQWU7WUFDekQsTUFBTSxDQUFDLGVBQWUsQ0FBQyxJQUFJLEtBQUssT0FBTyxDQUFBO1FBQzNDLENBQUMsQ0FBQyxDQUFBO1FBQ0YsRUFBRSxDQUFDLENBQUMsZ0JBQWdCLEtBQUssSUFBSSxDQUFDLENBQUMsQ0FBQztZQUM1QixJQUFJLENBQUMsT0FBTyxDQUFDLGdCQUFnQixDQUFDLENBQUE7UUFDbEMsQ0FBQztRQUNELE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7O0lBRUQsYUFBYSxDQUFDLGVBQWtDO1FBQzVDLElBQUksQ0FBQyxXQUFXLENBQUMsR0FBRyxDQUFDLGVBQWUsQ0FBQyxDQUFBO0lBQ3pDLENBQUM7QUFDTCxDQUFDO0FBekRZLFVBQUUsS0F5RGQsQ0FBQSJ9

View File

@ -4,6 +4,7 @@ import { Db } from './smartdata.classes.db';
export interface IFindOptions { export interface IFindOptions {
limit?: number; limit?: number;
} }
export declare function Collection(db: Db): (constructor: any) => void;
export declare class DbCollection<T> { export declare class DbCollection<T> {
collection: plugins.mongodb.Collection; collection: plugins.mongodb.Collection;
name: string; name: string;

View File

@ -1,5 +1,11 @@
"use strict"; "use strict";
const plugins = require('./smartdata.plugins'); const plugins = require('./smartdata.plugins');
function Collection(db) {
return function (constructor) {
constructor['dbCollection'] = new DbCollection(constructor.name, db);
};
}
exports.Collection = Collection;
class DbCollection { class DbCollection {
constructor(nameArg, dbArg) { constructor(nameArg, dbArg) {
this.name = nameArg; this.name = nameArg;
@ -61,4 +67,4 @@ class DbCollection {
} }
} }
exports.DbCollection = DbCollection; exports.DbCollection = DbCollection;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFDekIsQ0FBQyxDQUQ2QztBQU85QztJQUdJLFlBQVksT0FBZSxFQUFFLEtBQVM7UUFDbEMsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUE7UUFDbkIsSUFBSSxDQUFDLFVBQVUsR0FBRyxLQUFLLENBQUMsRUFBRSxDQUFDLFVBQVUsQ0FBQyxPQUFPLENBQUMsQ0FBQTtJQUNsRCxDQUFDO0lBRUQ7O09BRUc7SUFDSCxtQkFBbUIsQ0FBQyxPQUFPLElBQUksQ0FBQztJQUVoQzs7T0FFRztJQUNILElBQUksQ0FBQyxXQUFvQixFQUFFLFVBQXlCO1FBQ2hELElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFPLENBQUE7UUFDakMsSUFBSSxVQUFVLEdBQUcsSUFBSSxDQUFDLFVBQVUsQ0FBQ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ENBQUMsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxvQkFBb0IsQ0FBQyxDQUFDLElBQUksQ0FBQztZQUNyQyxJQUFJLENBQUMsVUFBVSxDQUFDLFVBQVUsQ0FBQyxXQUFXLENBQUM7aUJBQ2xDLElBQUksQ0FBQyxRQUFRLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQ3ZDLENBQUMsQ0FBQyxDQUFBO1FBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztJQUVPLFFBQVEsQ0FBQyxHQUFNO1FBQ25CLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFRLENBQUE7UUFDbEMsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztBQUNMLENBQUM7QUE5RFksb0JBQVksZUE4RHhCLENBQUEifQ==

View File

@ -1,10 +1,9 @@
import { Db } from './smartdata.classes.db';
import { DbCollection } from './smartdata.classes.dbcollection'; import { DbCollection } from './smartdata.classes.dbcollection';
export declare type TDocCreation = 'db' | 'data' | 'mixed'; export declare type TDocCreation = 'db' | 'data' | 'mixed';
export declare class DbDoc<T> { export declare class DbDoc<T> {
collection: DbCollection<T>; collection: DbCollection<T>;
creationType: TDocCreation; creationType: TDocCreation;
constructor(collectionNameArg: string, dbArg: Db); constructor();
save(): void; save(): void;
saveDeep(): void; saveDeep(): void;
} }

View File

@ -1,8 +1,7 @@
"use strict"; "use strict";
const smartdata_classes_dbcollection_1 = require('./smartdata.classes.dbcollection');
class DbDoc { class DbDoc {
constructor(collectionNameArg, dbArg) { constructor() {
this.collection = new smartdata_classes_dbcollection_1.DbCollection(collectionNameArg, dbArg); this.collection = this.constructor['dbCollection'];
} }
save() { save() {
} }
@ -10,4 +9,4 @@ class DbDoc {
} }
} }
exports.DbDoc = DbDoc; exports.DbDoc = DbDoc;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYmRvYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBR0EsaURBQTZCLGtDQUU3QixDQUFDLENBRjhEO0FBSS9EO0lBR0ksWUFBWSxpQkFBeUIsRUFBRSxLQUFTO1FBQzVDLElBQUksQ0FBQyxVQUFVLEdBQUcsSUFBSSw2Q0FBWSxDQUFJLGlCQUFpQixFQUFFLEtBQUssQ0FBQyxDQUFBO0lBQ25FLENBQUM7SUFDRCxJQUFJO0lBRUosQ0FBQztJQUNELFFBQVE7SUFFUixDQUFDO0FBQ0wsQ0FBQztBQVpZLGFBQUssUUFZakIsQ0FBQSJ9 //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYmRvYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBUUE7SUFHSTtRQUNJLElBQUksQ0FBQyxVQUFVLEdBQUcsSUFBSSxDQUFDLFdBQVcsQ0FBQyxjQUFjLENBQUMsQ0FBQTtJQUN0RCxDQUFDO0lBQ0QsSUFBSTtJQUVKLENBQUM7SUFDRCxRQUFRO0lBRVIsQ0FBQztBQUNMLENBQUM7QUFaWSxhQUFLLFFBWWpCLENBQUEifQ==

View File

@ -1,4 +1,10 @@
"use strict"; "use strict";
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
require('typings-test'); require('typings-test');
const shelljs = require('shelljs'); const shelljs = require('shelljs');
const should = require('should'); const should = require('should');
@ -59,16 +65,21 @@ describe('smartdata', function () {
testDb.close(); testDb.close();
}); });
it('should create an extended class', function () { it('should create an extended class', function () {
class TestCar extends smartdata.DbDoc { let TestCar = class TestCar extends smartdata.DbDoc {
constructor(optionsArg) { constructor(optionsArg) {
super('testCar', testDb); super();
this.color = optionsArg.color;
} }
} };
TestCar = __decorate([
smartdata.Collection(testDb)
], TestCar);
; ;
let testCarInstance = new TestCar({ let testCarInstance = new TestCar({
color: 'red', color: 'red',
property2: 2 property2: 2
}); });
should(testCarInstance.collection).be.instanceof(smartdata.DbCollection);
should(testCarInstance).be.instanceof(smartdata.DbDoc); should(testCarInstance).be.instanceof(smartdata.DbDoc);
testCarInstance.save(); testCarInstance.save();
it('should get a collection for testCar', function () { it('should get a collection for testCar', function () {
@ -87,4 +98,4 @@ describe('mongodb', function () {
mongoChildProcess.kill('SIGTERM'); mongoChildProcess.kill('SIGTERM');
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FFUCxDQUFDLENBRm9CO0FBRXJCLE1BQVksT0FBTyxXQUFNLFNBQ3pCLENBQUMsQ0FEaUM7QUFDbEMsTUFBWSxNQUFNLFdBQU0sUUFDeEIsQ0FBQyxDQUQrQjtBQUNoQyxNQUFZLFdBQVcsV0FBTSxhQUc3QixDQUFDLENBSHlD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QUE7UUFDbkIsaUJBQWlCLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsVUFBVSxJQUFJO1lBQzlDLEVBQUUsQ0FBQyxDQUFDLGdCQUFnQixDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUM7Z0JBQzlCLElBQUksRUFBRSxDQUFBO1lBQ1YsQ0FBQztRQUNMLENBQUMsQ0FBQyxDQUFBO1FBQ0YsT0FBTyxDQUFDLElBQUksQ0FBQyx3Q0FBd0MsQ0FBQyxDQUFBO1FBQ3RELGlCQUFpQixDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUNyQyxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=

View File

@ -18,8 +18,6 @@ interface ITestObject1 {
let testDbCollection: smartdata.DbCollection<ITestObject1> let testDbCollection: smartdata.DbCollection<ITestObject1>
describe('mongodb', function () { describe('mongodb', function () {
it('should start mongodb', function (done) { it('should start mongodb', function (done) {
this.timeout(30000) this.timeout(30000)
@ -72,22 +70,26 @@ describe('smartdata', function () {
testDb.close() testDb.close()
}) })
it('should create an extended class', function () { it('should create an extended class', function () {
@smartdata.Collection(testDb)
class TestCar extends smartdata.DbDoc<TestCar> { class TestCar extends smartdata.DbDoc<TestCar> {
color: string color: string
constructor(optionsArg: { constructor(optionsArg: {
color: string, color: string,
property2: number property2: number
}) { }) {
super('testCar',testDb) super()
this.color = optionsArg.color
} }
}; };
let testCarInstance = new TestCar({ let testCarInstance = new TestCar({
color: 'red', color: 'red',
property2: 2 property2: 2
}) })
should(testCarInstance.collection).be.instanceof(smartdata.DbCollection)
should(testCarInstance).be.instanceof(smartdata.DbDoc) should(testCarInstance).be.instanceof(smartdata.DbDoc)
testCarInstance.save() testCarInstance.save()
it('should get a collection for testCar',function() { it('should get a collection for testCar',function() {
}) })
}) })
}) })

View File

@ -58,4 +58,8 @@ export class Db {
} }
return done.promise return done.promise
}; };
addCollection(dbCollectionArg: DbCollection<any>) {
this.collections.add(dbCollectionArg)
}
} }

View File

@ -5,6 +5,12 @@ export interface IFindOptions {
limit?: number limit?: number
} }
export function Collection(db: Db) {
return function(constructor){
constructor['dbCollection'] = new DbCollection(constructor.name, db)
}
}
export class DbCollection<T> { export class DbCollection<T> {
collection: plugins.mongodb.Collection collection: plugins.mongodb.Collection
name: string name: string

View File

@ -5,16 +5,17 @@ import { DbCollection } from './smartdata.classes.dbcollection'
export type TDocCreation = 'db' | 'data' | 'mixed' export type TDocCreation = 'db' | 'data' | 'mixed'
export class DbDoc<T> { export class DbDoc<T> {
collection: DbCollection<T> collection: DbCollection<T>
creationType: TDocCreation creationType: TDocCreation
constructor(collectionNameArg: string, dbArg: Db ) { constructor() {
this.collection = new DbCollection<T>(collectionNameArg, dbArg) this.collection = this.constructor['dbCollection']
} }
save() { save() {
} }
saveDeep() { saveDeep() {
} }
} }