implenting dbDoc
This commit is contained in:
parent
eb54fbcd0d
commit
df4346e0a2
11
README.md
11
README.md
@ -45,16 +45,13 @@ class myObject extends smartdata.DbDoc { // read the next block about DbDoc
|
|||||||
property1:string
|
property1:string
|
||||||
property2:number
|
property2:number
|
||||||
constructor(optionsArg:{
|
constructor(optionsArg:{
|
||||||
queryArg?:any,
|
property1:string,
|
||||||
dataArg?:{
|
property2:number
|
||||||
property1:string,
|
|
||||||
property2:number
|
|
||||||
}
|
|
||||||
}) {
|
}) {
|
||||||
super(this,optionsArg,myDb1)
|
super(this,myDb1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let myCollection = myDb1.getCollection<myObject>(myObject)
|
let myCollection = myDb1.getCollectionByName<myObject>(myObject)
|
||||||
```
|
```
|
||||||
|
|
||||||
> Alert: You NEVER instantiate a collection.
|
> Alert: You NEVER instantiate a collection.
|
||||||
|
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -1,2 +1,3 @@
|
|||||||
export * from './smartdata.classes.dbcollection';
|
|
||||||
export * from './smartdata.classes.db';
|
export * from './smartdata.classes.db';
|
||||||
|
export * from './smartdata.classes.dbcollection';
|
||||||
|
export * from './smartdata.classes.dbdoc';
|
||||||
|
5
dist/index.js
vendored
5
dist/index.js
vendored
@ -2,6 +2,7 @@
|
|||||||
function __export(m) {
|
function __export(m) {
|
||||||
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
||||||
}
|
}
|
||||||
__export(require('./smartdata.classes.dbcollection'));
|
|
||||||
__export(require('./smartdata.classes.db'));
|
__export(require('./smartdata.classes.db'));
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaUJBQWMsa0NBQ2QsQ0FBQyxFQUQrQztBQUNoRCxpQkFBYyx3QkFDZCxDQUFDLEVBRHFDIn0=
|
__export(require('./smartdata.classes.dbcollection'));
|
||||||
|
__export(require('./smartdata.classes.dbdoc'));
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaUJBQWMsd0JBQ2QsQ0FBQyxFQURxQztBQUN0QyxpQkFBYyxrQ0FDZCxDQUFDLEVBRCtDO0FBQ2hELGlCQUFjLDJCQUNkLENBQUMsRUFEd0MifQ==
|
13
dist/smartdata.classes.db.d.ts
vendored
13
dist/smartdata.classes.db.d.ts
vendored
@ -1,11 +1,24 @@
|
|||||||
/// <reference types="q" />
|
/// <reference types="q" />
|
||||||
import * as plugins from './smartdata.plugins';
|
import * as plugins from './smartdata.plugins';
|
||||||
|
import { Objectmap } from 'lik';
|
||||||
|
import { DbCollection } from './smartdata.classes.dbcollection';
|
||||||
export declare type TConnectionStatus = 'disconnected' | 'connected' | 'failed';
|
export declare type TConnectionStatus = 'disconnected' | 'connected' | 'failed';
|
||||||
export declare class Db {
|
export declare class Db {
|
||||||
dbUrl: string;
|
dbUrl: string;
|
||||||
db: plugins.mongodb.Db;
|
db: plugins.mongodb.Db;
|
||||||
status: TConnectionStatus;
|
status: TConnectionStatus;
|
||||||
|
collections: Objectmap<DbCollection<any>>;
|
||||||
constructor(dbUrl: string);
|
constructor(dbUrl: string);
|
||||||
|
/**
|
||||||
|
* connects to the database that was specified during instance creation
|
||||||
|
*/
|
||||||
connect(): plugins.q.Promise<any>;
|
connect(): plugins.q.Promise<any>;
|
||||||
|
/**
|
||||||
|
* closes the connection to the databse
|
||||||
|
*/
|
||||||
close(): plugins.q.Promise<any>;
|
close(): plugins.q.Promise<any>;
|
||||||
|
/**
|
||||||
|
* gets a collection by name: string
|
||||||
|
*/
|
||||||
|
getCollectionByName<T>(nameArg: string): plugins.q.Promise<DbCollection<T>>;
|
||||||
}
|
}
|
||||||
|
26
dist/smartdata.classes.db.js
vendored
26
dist/smartdata.classes.db.js
vendored
@ -1,9 +1,15 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
const plugins = require('./smartdata.plugins');
|
const plugins = require('./smartdata.plugins');
|
||||||
|
const lik_1 = require('lik');
|
||||||
class Db {
|
class Db {
|
||||||
constructor(dbUrl) {
|
constructor(dbUrl) {
|
||||||
|
this.collections = new lik_1.Objectmap();
|
||||||
this.dbUrl = dbUrl;
|
this.dbUrl = dbUrl;
|
||||||
}
|
}
|
||||||
|
// basic connection stuff ----------------------------------------------
|
||||||
|
/**
|
||||||
|
* connects to the database that was specified during instance creation
|
||||||
|
*/
|
||||||
connect() {
|
connect() {
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
|
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
|
||||||
@ -17,6 +23,9 @@ class Db {
|
|||||||
});
|
});
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* closes the connection to the databse
|
||||||
|
*/
|
||||||
close() {
|
close() {
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
this.db.close();
|
this.db.close();
|
||||||
@ -24,6 +33,21 @@ class Db {
|
|||||||
done.resolve();
|
done.resolve();
|
||||||
return done.promise;
|
return done.promise;
|
||||||
}
|
}
|
||||||
|
// advanced communication with the database --------------------------------
|
||||||
|
/**
|
||||||
|
* gets a collection by name: string
|
||||||
|
*/
|
||||||
|
getCollectionByName(nameArg) {
|
||||||
|
let done = plugins.q.defer();
|
||||||
|
let resultCollection = this.collections.find((dbCollectionArg) => {
|
||||||
|
return dbCollectionArg.name === nameArg;
|
||||||
|
});
|
||||||
|
if (resultCollection !== null) {
|
||||||
|
done.resolve(resultCollection);
|
||||||
|
}
|
||||||
|
return done.promise;
|
||||||
|
}
|
||||||
|
;
|
||||||
}
|
}
|
||||||
exports.Db = Db;
|
exports.Db = Db;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGIuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsTUFBWSxPQUFPLFdBQU0scUJBRXpCLENBQUMsQ0FGNkM7QUFJOUM7SUFLSSxZQUFZLEtBQWE7UUFDckIsSUFBSSxDQUFDLEtBQUssR0FBRyxLQUFLLENBQUE7SUFDdEIsQ0FBQztJQUVELE9BQU87UUFDSCxJQUFJLElBQUksR0FBRyxPQUFPLENBQUMsQ0FBQyxDQUFDLEtBQUssRUFBRSxDQUFBO1FBQzVCLE9BQU8sQ0FBQyxPQUFPLENBQUMsV0FBVyxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsS0FBSyxFQUFFLENBQUMsR0FBRyxFQUFFLEVBQUU7WUFDcEQsRUFBRSxDQUFDLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQztnQkFBQyxPQUFPLENBQUMsR0FBRyxDQUFDLEdBQUcsQ0FBQyxDQUFBO1lBQUMsQ0FBQztZQUM3QixPQUFPLENBQUMsTUFBTSxDQUFDLEtBQUssQ0FBQyxJQUFJLEVBQUUsR0FBRyxDQUFDLENBQUE7WUFDL0IsSUFBSSxDQUFDLEVBQUUsR0FBRyxFQUFFLENBQUE7WUFDWixPQUFPLENBQUMsU0FBUyxDQUFDLE9BQU8sQ0FBQyw0QkFBNEIsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDLENBQUE7WUFDbkUsSUFBSSxDQUFDLE9BQU8sQ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SUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQXFCLENBQUE7UUFDL0MsSUFBSSxnQkFBZ0IsR0FBRyxJQUFJLENBQUMsV0FBVyxDQUFDLElBQUksQ0FBQyxDQUFDLGVBQWU7WUFDekQsTUFBTSxDQUFDLGVBQWUsQ0FBQyxJQUFJLEtBQUssT0FBTyxDQUFBO1FBQzNDLENBQUMsQ0FBQyxDQUFBO1FBQ0YsRUFBRSxDQUFDLENBQUMsZ0JBQWdCLEtBQUssSUFBSSxDQUFDLENBQUMsQ0FBQztZQUM1QixJQUFJLENBQUMsT0FBTyxDQUFDLGdCQUFnQixDQUFDLENBQUE7UUFDbEMsQ0FBQztRQUNELE1BQU0sQ0FBQyxJQUFJLENBQUMsT0FBTyxDQUFBO0lBQ3ZCLENBQUM7O0FBQ0wsQ0FBQztBQXJEWSxVQUFFLEtBcURkLENBQUEifQ==
|
6
dist/smartdata.classes.dbcollection.d.ts
vendored
6
dist/smartdata.classes.dbcollection.d.ts
vendored
@ -1,8 +1,12 @@
|
|||||||
/// <reference types="q" />
|
/// <reference types="q" />
|
||||||
import * as plugins from './smartdata.plugins';
|
import * as plugins from './smartdata.plugins';
|
||||||
import { Db } from './smartdata.classes.db';
|
import { Db } from './smartdata.classes.db';
|
||||||
|
export interface IFindOptions {
|
||||||
|
limit?: number;
|
||||||
|
}
|
||||||
export declare class DbCollection<T> {
|
export declare class DbCollection<T> {
|
||||||
collection: plugins.mongodb.Collection;
|
collection: plugins.mongodb.Collection;
|
||||||
|
name: string;
|
||||||
constructor(nameArg: string, dbArg: Db);
|
constructor(nameArg: string, dbArg: Db);
|
||||||
/**
|
/**
|
||||||
* adds a validation function that all newly inserted and updated objects have to pass
|
* adds a validation function that all newly inserted and updated objects have to pass
|
||||||
@ -11,7 +15,7 @@ export declare class DbCollection<T> {
|
|||||||
/**
|
/**
|
||||||
* finds an object in the DbCollection
|
* finds an object in the DbCollection
|
||||||
*/
|
*/
|
||||||
find(docMatchArg: T | any): plugins.q.Promise<T[]>;
|
find(docMatchArg: T | any, optionsArg?: IFindOptions): plugins.q.Promise<T[]>;
|
||||||
/**
|
/**
|
||||||
* inserts object into the DbCollection
|
* inserts object into the DbCollection
|
||||||
*/
|
*/
|
||||||
|
13
dist/smartdata.classes.dbcollection.js
vendored
13
dist/smartdata.classes.dbcollection.js
vendored
@ -2,6 +2,7 @@
|
|||||||
const plugins = require('./smartdata.plugins');
|
const plugins = require('./smartdata.plugins');
|
||||||
class DbCollection {
|
class DbCollection {
|
||||||
constructor(nameArg, dbArg) {
|
constructor(nameArg, dbArg) {
|
||||||
|
this.name = nameArg;
|
||||||
this.collection = dbArg.db.collection(nameArg);
|
this.collection = dbArg.db.collection(nameArg);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@ -11,9 +12,15 @@ class DbCollection {
|
|||||||
/**
|
/**
|
||||||
* finds an object in the DbCollection
|
* finds an object in the DbCollection
|
||||||
*/
|
*/
|
||||||
find(docMatchArg) {
|
find(docMatchArg, optionsArg) {
|
||||||
let done = plugins.q.defer();
|
let done = plugins.q.defer();
|
||||||
this.collection.find(docMatchArg).toArray((err, docs) => {
|
let findCursor = this.collection.find(docMatchArg);
|
||||||
|
if (optionsArg) {
|
||||||
|
if (optionsArg.limit) {
|
||||||
|
findCursor = findCursor.limit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
findCursor.toArray((err, docs) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
throw err;
|
throw err;
|
||||||
}
|
}
|
||||||
@ -54,4 +61,4 @@ class DbCollection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
exports.DbCollection = DbCollection;
|
exports.DbCollection = DbCollection;
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi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cEQsQ0FBQztRQUNELE9BQU8sQ0FBQyxDQUFDLENBQUMsR0FBRyxDQUFDLG9CQUFvQixDQUFDLENBQUMsSUFBSSxDQUFDO1lBQ3JDLElBQUksQ0FBQyxVQUFVLENBQUMsVUFBVSxDQUFDLFdBQVcsQ0FBQztpQkFDbEMsSUFBSSxDQUFDLFFBQVEsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBLENBQUMsQ0FBQyxDQUFDLENBQUE7UUFDdkMsQ0FBQyxDQUFDLENBQUE7UUFDRixNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUN2QixDQUFDO0lBRU8sUUFBUSxDQUFDLEdBQU07UUFDbkIsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQVEsQ0FBQTtRQUNsQyxJQUFJLENBQUMsT0FBTyxFQUFFLENBQUE7UUFDZCxNQUFNLENBQUMsSUFBSSxDQUFDLE9BQU8sQ0FBQTtJQUN2QixDQUFDO0FBQ0wsQ0FBQztBQTlEWSxvQkFBWSxlQThEeEIsQ0FBQSJ9
|
10
dist/smartdata.classes.dbdoc.d.ts
vendored
10
dist/smartdata.classes.dbdoc.d.ts
vendored
@ -0,0 +1,10 @@
|
|||||||
|
import { Db } from './smartdata.classes.db';
|
||||||
|
import { DbCollection } from './smartdata.classes.dbcollection';
|
||||||
|
export declare type TDocCreation = 'db' | 'data' | 'mixed';
|
||||||
|
export declare class DbDoc<T> {
|
||||||
|
collection: DbCollection<T>;
|
||||||
|
creationType: TDocCreation;
|
||||||
|
constructor(collectionNameArg: string, dbArg: Db);
|
||||||
|
save(): void;
|
||||||
|
saveDeep(): void;
|
||||||
|
}
|
14
dist/smartdata.classes.dbdoc.js
vendored
14
dist/smartdata.classes.dbdoc.js
vendored
@ -1 +1,13 @@
|
|||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYmRvYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiIn0=
|
"use strict";
|
||||||
|
const smartdata_classes_dbcollection_1 = require('./smartdata.classes.dbcollection');
|
||||||
|
class DbDoc {
|
||||||
|
constructor(collectionNameArg, dbArg) {
|
||||||
|
this.collection = new smartdata_classes_dbcollection_1.DbCollection(collectionNameArg, dbArg);
|
||||||
|
}
|
||||||
|
save() {
|
||||||
|
}
|
||||||
|
saveDeep() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
exports.DbDoc = DbDoc;
|
||||||
|
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYmRvYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBR0EsaURBQTZCLGtDQUU3QixDQUFDLENBRjhEO0FBSS9EO0lBR0ksWUFBWSxpQkFBeUIsRUFBRSxLQUFTO1FBQzVDLElBQUksQ0FBQyxVQUFVLEdBQUcsSUFBSSw2Q0FBWSxDQUFJLGlCQUFpQixFQUFFLEtBQUssQ0FBQyxDQUFBO0lBQ25FLENBQUM7SUFDRCxJQUFJO0lBRUosQ0FBQztJQUNELFFBQVE7SUFFUixDQUFDO0FBQ0wsQ0FBQztBQVpZLGFBQUssUUFZakIsQ0FBQSJ9
|
@ -22,6 +22,7 @@
|
|||||||
"@types/mongodb": "^2.1.32",
|
"@types/mongodb": "^2.1.32",
|
||||||
"@types/q": "0.0.30",
|
"@types/q": "0.0.30",
|
||||||
"beautylog": "^5.0.23",
|
"beautylog": "^5.0.23",
|
||||||
|
"lik": "^1.0.15",
|
||||||
"mongodb": "^2.2.9",
|
"mongodb": "^2.2.9",
|
||||||
"q": "^1.4.1",
|
"q": "^1.4.1",
|
||||||
"typings-global": "^1.0.14"
|
"typings-global": "^1.0.14"
|
||||||
|
25
test/test.js
25
test/test.js
@ -8,18 +8,13 @@ const smartdata = require('../dist/index');
|
|||||||
let mongoChildProcess;
|
let mongoChildProcess;
|
||||||
let testDb;
|
let testDb;
|
||||||
let testDbCollection;
|
let testDbCollection;
|
||||||
class testCar {
|
|
||||||
constructor(colorArg) {
|
|
||||||
this.color = colorArg;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
describe('mongodb', function () {
|
describe('mongodb', function () {
|
||||||
it('should start mongodb', function (done) {
|
it('should start mongodb', function (done) {
|
||||||
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('data', 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)) {
|
||||||
doneCalled = true;
|
doneCalled = true;
|
||||||
@ -63,6 +58,22 @@ describe('smartdata', function () {
|
|||||||
it('should close the db Connection', function () {
|
it('should close the db Connection', function () {
|
||||||
testDb.close();
|
testDb.close();
|
||||||
});
|
});
|
||||||
|
it('should create an extended class', function () {
|
||||||
|
class TestCar extends smartdata.DbDoc {
|
||||||
|
constructor(optionsArg) {
|
||||||
|
super('testCar', testDb);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
;
|
||||||
|
let testCarInstance = new TestCar({
|
||||||
|
color: 'red',
|
||||||
|
property2: 2
|
||||||
|
});
|
||||||
|
should(testCarInstance).be.instanceof(smartdata.DbDoc);
|
||||||
|
testCarInstance.save();
|
||||||
|
it('should get a collection for testCar', function () {
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
describe('mongodb', function () {
|
describe('mongodb', function () {
|
||||||
it('should kill mongodb', function (done) {
|
it('should kill mongodb', function (done) {
|
||||||
@ -76,4 +87,4 @@ describe('mongodb', function () {
|
|||||||
mongoChildProcess.kill('SIGTERM');
|
mongoChildProcess.kill('SIGTERM');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FFUCxDQUFDLENBRm9CO0FBRXJCLE1BQVksT0FBTyxXQUFNLFNBQ3pCLENBQUMsQ0FEaUM7QUFDbEMsTUFBWSxNQUFNLFdBQU0sUUFDeEIsQ0FBQyxDQUQrQjtBQUNoQyxNQUFZLFdBQVcsV0FBTSxhQUc3QixDQUFDLENBSHlDO0FBRTFDLG9CQUFvQjtBQUNwQixNQUFZLFNBQVMsV0FBTSxlQUUzQixDQUFDLENBRnlDO0FBRTFDLElBQUksaUJBQWlCLENBQUE7QUFDckIsSUFBSSxNQUFvQixDQUFBO0FBUXhCLElBQUksZ0JBQXNELENBQUE7QUFFMUQ7SUFFSSxZQUFZLFFBQWU7UUFDdkIsSUFBSSxDQUFDLEtBQUssR0FBRyxRQUFRLENBQUE7SUFDekIsQ0FBQztBQUNMLENBQUM7QUFHRCxRQUFRLENBQUMsU0FBUyxFQUFFO0lBQ2hCLEVBQUUsQ0FBQyxzQkFBc0IsRUFBRSxVQUFVLElBQUk7UUFDckMsSUFBSSxDQUFDLE9BQU8sQ0FBQyxLQUFLLENBQUMsQ0FBQ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QUFDLENBQUE7UUFDbkIsaUJBQWlCLENBQUMsTUFBTSxDQUFDLEVBQUUsQ0FBQyxNQUFNLEVBQUUsVUFBVSxJQUFJO1lBQzlDLEVBQUUsQ0FBQyxDQUFDLGdCQUFnQixDQUFDLElBQUksQ0FBQyxJQUFJLENBQUMsQ0FBQyxDQUFDLENBQUM7Z0JBQzlCLElBQUksRUFBRSxDQUFBO1lBQ1YsQ0FBQztRQUNMLENBQUMsQ0FBQyxDQUFBO1FBQ0YsT0FBTyxDQUFDLElBQUksQ0FBQyx3Q0FBd0MsQ0FBQyxDQUFBO1FBQ3RELGlCQUFpQixDQUFDLElBQUksQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUNyQyxDQUFDLENBQUMsQ0FBQTtBQUNOLENBQUMsQ0FBQyxDQUFBIn0=
|
29
test/test.ts
29
test/test.ts
@ -18,12 +18,6 @@ interface ITestObject1 {
|
|||||||
|
|
||||||
let testDbCollection: smartdata.DbCollection<ITestObject1>
|
let testDbCollection: smartdata.DbCollection<ITestObject1>
|
||||||
|
|
||||||
class testCar {
|
|
||||||
color: string
|
|
||||||
constructor(colorArg:string) {
|
|
||||||
this.color = colorArg
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
describe('mongodb', function () {
|
describe('mongodb', function () {
|
||||||
@ -32,7 +26,7 @@ describe('mongodb', function () {
|
|||||||
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('data', 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)) {
|
||||||
doneCalled = true
|
doneCalled = true
|
||||||
@ -68,7 +62,7 @@ describe('smartdata', function () {
|
|||||||
]).then(() => { done() })
|
]).then(() => { done() })
|
||||||
})
|
})
|
||||||
it('should find a specified doc', function (done) {
|
it('should find a specified doc', function (done) {
|
||||||
testDbCollection.find({'value3': {'$exists': true}}).then((resultArray) => {
|
testDbCollection.find({ 'value3': { '$exists': true } }).then((resultArray) => {
|
||||||
console.log(resultArray)
|
console.log(resultArray)
|
||||||
should(resultArray[0].value3).equal('hi')
|
should(resultArray[0].value3).equal('hi')
|
||||||
done()
|
done()
|
||||||
@ -77,6 +71,25 @@ describe('smartdata', function () {
|
|||||||
it('should close the db Connection', function () {
|
it('should close the db Connection', function () {
|
||||||
testDb.close()
|
testDb.close()
|
||||||
})
|
})
|
||||||
|
it('should create an extended class', function () {
|
||||||
|
class TestCar extends smartdata.DbDoc<TestCar> {
|
||||||
|
color: string
|
||||||
|
constructor(optionsArg: {
|
||||||
|
color: string,
|
||||||
|
property2: number
|
||||||
|
}) {
|
||||||
|
super('testCar',testDb)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
let testCarInstance = new TestCar({
|
||||||
|
color: 'red',
|
||||||
|
property2: 2
|
||||||
|
})
|
||||||
|
should(testCarInstance).be.instanceof(smartdata.DbDoc)
|
||||||
|
testCarInstance.save()
|
||||||
|
it('should get a collection for testCar',function() {
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('mongodb', function () {
|
describe('mongodb', function () {
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import * as plugins from './smartdata.plugins'
|
import * as plugins from './smartdata.plugins'
|
||||||
|
|
||||||
export * from './smartdata.classes.dbcollection'
|
|
||||||
export * from './smartdata.classes.db'
|
export * from './smartdata.classes.db'
|
||||||
|
export * from './smartdata.classes.dbcollection'
|
||||||
|
export * from './smartdata.classes.dbdoc'
|
||||||
|
@ -1,4 +1,7 @@
|
|||||||
import * as plugins from './smartdata.plugins'
|
import * as plugins from './smartdata.plugins'
|
||||||
|
import { Objectmap } from 'lik'
|
||||||
|
|
||||||
|
import { DbCollection } from './smartdata.classes.dbcollection'
|
||||||
|
|
||||||
export type TConnectionStatus = 'disconnected' | 'connected' | 'failed'
|
export type TConnectionStatus = 'disconnected' | 'connected' | 'failed'
|
||||||
|
|
||||||
@ -6,11 +9,17 @@ export class Db {
|
|||||||
dbUrl: string
|
dbUrl: string
|
||||||
db: plugins.mongodb.Db
|
db: plugins.mongodb.Db
|
||||||
status: TConnectionStatus
|
status: TConnectionStatus
|
||||||
|
collections = new Objectmap<DbCollection<any>>()
|
||||||
|
|
||||||
constructor(dbUrl: string) {
|
constructor(dbUrl: string) {
|
||||||
this.dbUrl = dbUrl
|
this.dbUrl = dbUrl
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// basic connection stuff ----------------------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* connects to the database that was specified during instance creation
|
||||||
|
*/
|
||||||
connect(): plugins.q.Promise<any> {
|
connect(): plugins.q.Promise<any> {
|
||||||
let done = plugins.q.defer()
|
let done = plugins.q.defer()
|
||||||
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
|
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
|
||||||
@ -23,6 +32,9 @@ export class Db {
|
|||||||
return done.promise
|
return done.promise
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* closes the connection to the databse
|
||||||
|
*/
|
||||||
close(): plugins.q.Promise<any> {
|
close(): plugins.q.Promise<any> {
|
||||||
let done = plugins.q.defer()
|
let done = plugins.q.defer()
|
||||||
this.db.close()
|
this.db.close()
|
||||||
@ -30,4 +42,20 @@ export class Db {
|
|||||||
done.resolve()
|
done.resolve()
|
||||||
return done.promise
|
return done.promise
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// advanced communication with the database --------------------------------
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gets a collection by name: string
|
||||||
|
*/
|
||||||
|
getCollectionByName<T>(nameArg: string): plugins.q.Promise<DbCollection<T>> {
|
||||||
|
let done = plugins.q.defer<DbCollection<any>>()
|
||||||
|
let resultCollection = this.collections.find((dbCollectionArg) => {
|
||||||
|
return dbCollectionArg.name === nameArg
|
||||||
|
})
|
||||||
|
if (resultCollection !== null) {
|
||||||
|
done.resolve(resultCollection)
|
||||||
|
}
|
||||||
|
return done.promise
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,15 @@
|
|||||||
import * as plugins from './smartdata.plugins'
|
import * as plugins from './smartdata.plugins'
|
||||||
import { Db } from './smartdata.classes.db'
|
import { Db } from './smartdata.classes.db'
|
||||||
|
|
||||||
|
export interface IFindOptions {
|
||||||
|
limit?: number
|
||||||
|
}
|
||||||
|
|
||||||
export class DbCollection<T> {
|
export class DbCollection<T> {
|
||||||
collection: plugins.mongodb.Collection
|
collection: plugins.mongodb.Collection
|
||||||
|
name: string
|
||||||
constructor(nameArg: string, dbArg: Db) {
|
constructor(nameArg: string, dbArg: Db) {
|
||||||
|
this.name = nameArg
|
||||||
this.collection = dbArg.db.collection(nameArg)
|
this.collection = dbArg.db.collection(nameArg)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -15,9 +21,13 @@ export class DbCollection<T> {
|
|||||||
/**
|
/**
|
||||||
* finds an object in the DbCollection
|
* finds an object in the DbCollection
|
||||||
*/
|
*/
|
||||||
find(docMatchArg: T | any): plugins.q.Promise<T[]> {
|
find(docMatchArg: T | any, optionsArg?: IFindOptions): plugins.q.Promise<T[]> {
|
||||||
let done = plugins.q.defer<T[]>()
|
let done = plugins.q.defer<T[]>()
|
||||||
this.collection.find(docMatchArg).toArray((err, docs) => {
|
let findCursor = this.collection.find(docMatchArg)
|
||||||
|
if (optionsArg) {
|
||||||
|
if ( optionsArg.limit ) { findCursor = findCursor.limit(1) }
|
||||||
|
}
|
||||||
|
findCursor.toArray((err, docs) => {
|
||||||
if (err) { throw err }
|
if (err) { throw err }
|
||||||
done.resolve(docs)
|
done.resolve(docs)
|
||||||
})
|
})
|
||||||
|
@ -0,0 +1,20 @@
|
|||||||
|
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 class DbDoc<T> {
|
||||||
|
collection: DbCollection<T>
|
||||||
|
creationType: TDocCreation
|
||||||
|
constructor(collectionNameArg: string, dbArg: Db ) {
|
||||||
|
this.collection = new DbCollection<T>(collectionNameArg, dbArg)
|
||||||
|
}
|
||||||
|
save() {
|
||||||
|
|
||||||
|
}
|
||||||
|
saveDeep() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user