added nedb to the mix

This commit is contained in:
Philipp Kunz 2016-11-17 12:20:52 +01:00
parent 3a24f829b4
commit af8c41ad6c
16 changed files with 105 additions and 58 deletions

8
dist/index.js vendored
View File

@ -2,7 +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.db')); __export(require("./smartdata.classes.db"));
__export(require('./smartdata.classes.dbcollection')); __export(require("./smartdata.classes.dbcollection"));
__export(require('./smartdata.classes.dbdoc')); __export(require("./smartdata.classes.dbdoc"));
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsaUJBQWMsd0JBQ2QsQ0FBQyxFQURxQztBQUN0QyxpQkFBYyxrQ0FDZCxDQUFDLEVBRCtDO0FBQ2hELGlCQUFjLDJCQUNkLENBQUMsRUFEd0MifQ== //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7O0FBRUEsNENBQXNDO0FBQ3RDLHNEQUFnRDtBQUNoRCwrQ0FBeUMifQ==

View File

@ -1,14 +1,23 @@
/// <reference types="nedb" />
/// <reference types="q" /> /// <reference types="q" />
import * as plugins from './smartdata.plugins'; import * as plugins from './smartdata.plugins';
import { Objectmap } from 'lik'; import { Objectmap } from 'lik';
import { DbCollection } from './smartdata.classes.dbcollection'; import { DbCollection } from './smartdata.classes.dbcollection';
/**
* interface - indicates the database type
*/
export declare type TDbType = 'mongodb' | 'nedb';
/**
* interface - indicates the connection status of the db
*/
export declare type TConnectionStatus = 'disconnected' | 'connected' | 'failed'; export declare type TConnectionStatus = 'disconnected' | 'connected' | 'failed';
export declare class Db { export declare class Db {
dbType: TDbType;
dbUrl: string; dbUrl: string;
db: plugins.mongodb.Db; db: plugins.mongodb.Db | plugins.nedb;
status: TConnectionStatus; status: TConnectionStatus;
collections: Objectmap<DbCollection<any>>; collections: Objectmap<DbCollection<any>>;
constructor(dbUrl: string); constructor(dbUrlArg: string, dbTypeArg?: TDbType);
/** /**
* connects to the database that was specified during instance creation * connects to the database that was specified during instance creation
*/ */

View File

@ -1,10 +1,11 @@
"use strict"; "use strict";
const plugins = require('./smartdata.plugins'); const plugins = require("./smartdata.plugins");
const lik_1 = require('lik'); const lik_1 = require("lik");
class Db { class Db {
constructor(dbUrl) { constructor(dbUrlArg, dbTypeArg = 'mongodb') {
this.collections = new lik_1.Objectmap(); this.collections = new lik_1.Objectmap();
this.dbUrl = dbUrl; this.dbType = dbTypeArg;
this.dbUrl = dbUrlArg;
} }
// basic connection stuff ---------------------------------------------- // basic connection stuff ----------------------------------------------
/** /**
@ -12,6 +13,7 @@ class Db {
*/ */
connect() { connect() {
let done = plugins.q.defer(); let done = plugins.q.defer();
if (this.dbType === 'mongodb') {
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => { plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
if (err) { if (err) {
console.log(err); console.log(err);
@ -21,6 +23,10 @@ class Db {
plugins.beautylog.success(`connected to database at ${this.dbUrl}`); plugins.beautylog.success(`connected to database at ${this.dbUrl}`);
done.resolve(this.db); done.resolve(this.db);
}); });
}
else if (this.dbType === 'nedb') {
this.db = new plugins.nedb();
}
return done.promise; return done.promise;
} }
/** /**
@ -53,4 +59,4 @@ class Db {
} }
} }
exports.Db = Db; exports.Db = Db;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGIuanMiLCJzb3VyY2VSb290I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sQ0FBQyxDQUFDLENBQUE7UUFDRixFQUFFLENBQUMsQ0FBQyxnQkFBZ0IsS0FBSyxJQUFJLENBQUMsQ0FBQyxDQUFDO1lBQzVCLElBQUksQ0FBQyxPQUFPLENBQUMsZ0JBQWdCLENBQUMsQ0FBQTtRQUNsQyxDQUFDO1FBQ0QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztJQUFBLENBQUM7SUFFRixhQUFhLENBQUMsZUFBa0M7UUFDNUMsSUFBSSxDQUFDLFdBQVcsQ0FBQyxHQUFHLENBQUMsZUFBZSxDQUFDLENBQUE7SUFDekMsQ0FBQztDQUNKO0FBL0RELGdCQStEQyJ9

View File

@ -6,6 +6,9 @@ export interface IFindOptions {
} }
export declare function Collection(db: Db): (constructor: any) => void; export declare function Collection(db: Db): (constructor: any) => void;
export declare class DbCollection<T> { export declare class DbCollection<T> {
/**
* the collection that is used
*/
collection: plugins.mongodb.Collection; collection: plugins.mongodb.Collection;
name: string; name: string;
constructor(nameArg: string, dbArg: Db); constructor(nameArg: string, dbArg: Db);

View File

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

View File

@ -9,4 +9,4 @@ class DbDoc {
} }
} }
exports.DbDoc = DbDoc; exports.DbDoc = DbDoc;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYmRvYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBUUE7SUFHSTtRQUNJLElBQUksQ0FBQyxVQUFVLEdBQUcsSUFBSSxDQUFDLFdBQVcsQ0FBQyxjQUFjLENBQUMsQ0FBQTtJQUN0RCxDQUFDO0lBQ0QsSUFBSTtJQUVKLENBQUM7SUFDRCxRQUFRO0lBRVIsQ0FBQztBQUNMLENBQUM7QUFaWSxhQUFLLFFBWWpCLENBQUEifQ== //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJkb2MuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEuY2xhc3Nlcy5kYmRvYy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBUUE7SUFHSTtRQUNJLElBQUksQ0FBQyxVQUFVLEdBQUcsSUFBSSxDQUFDLFdBQVcsQ0FBQyxjQUFjLENBQUMsQ0FBQTtJQUN0RCxDQUFDO0lBQ0QsSUFBSTtJQUVKLENBQUM7SUFDRCxRQUFRO0lBRVIsQ0FBQztDQUNKO0FBWkQsc0JBWUMifQ==

View File

@ -3,3 +3,4 @@ export import assert = require('assert');
export import beautylog = require('beautylog'); export import beautylog = require('beautylog');
export import mongodb = require('mongodb'); export import mongodb = require('mongodb');
export import q = require('q'); export import q = require('q');
export import nedb = require('nedb');

View File

@ -1,7 +1,8 @@
"use strict"; "use strict";
require('typings-global'); require("typings-global");
exports.assert = require('assert'); exports.assert = require("assert");
exports.beautylog = require('beautylog'); exports.beautylog = require("beautylog");
exports.mongodb = require('mongodb'); exports.mongodb = require("mongodb");
exports.q = require('q'); exports.q = require("q");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsUUFBTyxnQkFDUCxDQUFDLENBRHNCO0FBQ1QsY0FBTSxXQUFXLFFBQVEsQ0FBQyxDQUFBO0FBQzFCLGlCQUFTLFdBQVcsV0FBVyxDQUFDLENBQUE7QUFDaEMsZUFBTyxXQUFXLFNBQVMsQ0FBQyxDQUFBO0FBQzVCLFNBQUMsV0FBVyxHQUFHLENBQUMsQ0FBQSJ9 exports.nedb = require("nedb");
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLnBsdWdpbnMuanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9zbWFydGRhdGEucGx1Z2lucy50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsMEJBQXVCO0FBQ3ZCLG1DQUF3QztBQUN4Qyx5Q0FBOEM7QUFDOUMscUNBQTBDO0FBQzFDLHlCQUE4QjtBQUM5QiwrQkFBb0MifQ==

View File

@ -19,20 +19,23 @@
}, },
"homepage": "https://gitlab.com/pushrocks/smartdata#README", "homepage": "https://gitlab.com/pushrocks/smartdata#README",
"dependencies": { "dependencies": {
"@types/mongodb": "^2.1.32", "@types/mongodb": "^2.1.34",
"@types/q": "0.0.30", "@types/nedb": "0.0.31",
"beautylog": "^5.0.23", "@types/q": "0.0.32",
"lik": "^1.0.15", "beautylog": "^6.0.0",
"mongodb": "^2.2.9", "lik": "^1.0.24",
"mongodb": "^2.2.11",
"nedb": "^1.8.0",
"q": "^1.4.1", "q": "^1.4.1",
"runtime-type-checks": "0.0.4",
"typings-global": "^1.0.14" "typings-global": "^1.0.14"
}, },
"devDependencies": { "devDependencies": {
"@types/shelljs": "^0.3.30", "@types/shelljs": "^0.3.32",
"@types/should": "^8.1.29", "@types/should": "^8.1.30",
"shelljs": "^0.7.4", "shelljs": "^0.7.5",
"should": "^11.1.0", "should": "^11.1.1",
"smartstring": "^2.0.17", "smartstring": "^2.0.22",
"typings-test": "^1.0.3" "typings-test": "^1.0.3"
} }
} }

View File

@ -5,12 +5,15 @@ var __decorate = (this && this.__decorate) || function (decorators, target, key,
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; 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; return c > 3 && r && Object.defineProperty(target, key, r), r;
}; };
require('typings-test'); var __metadata = (this && this.__metadata) || function (k, v) {
const shelljs = require('shelljs'); if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
const should = require('should'); };
const smartstring = require('smartstring'); require("typings-test");
const shelljs = require("shelljs");
const should = require("should");
const smartstring = require("smartstring");
// the tested module // the tested module
const smartdata = require('../dist/index'); const smartdata = require("../dist/index");
let mongoChildProcess; let mongoChildProcess;
let testDb; let testDb;
let testDbCollection; let testDbCollection;
@ -72,13 +75,15 @@ describe('smartdata', function () {
} }
}; };
TestCar = __decorate([ TestCar = __decorate([
smartdata.Collection(testDb) smartdata.Collection(testDb),
__metadata("design:paramtypes", [Object])
], TestCar); ], TestCar);
; ;
let testCarInstance = new TestCar({ let testCarInstance = new TestCar({
color: 'red', color: 'red',
property2: 2 property2: 2
}); });
console.log(TestCar);
should(testCarInstance.collection).be.instanceof(smartdata.DbCollection); should(testCarInstance.collection).be.instanceof(smartdata.DbCollection);
should(testCarInstance).be.instanceof(smartdata.DbDoc); should(testCarInstance).be.instanceof(smartdata.DbDoc);
testCarInstance.save(); testCarInstance.save();
@ -98,4 +103,4 @@ describe('mongodb', function () {
mongoChildProcess.kill('SIGTERM'); mongoChildProcess.kill('SIGTERM');
}); });
}); });
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7Ozs7OztBQUFBLFFBQU8sY0FFUCxDQUFDLENBRm9CO0FBRXJCLE1BQVksT0FBTyxXQUFNLFNBQ3pCLENBQUMsQ0FEaUM7QUFDbEMsTUFBWSxNQUFNLFdBQU0sUUFDeEIsQ0FBQyxDQUQrQjtBQUNoQyxNQUFZLFdBQVcsV0FBTSxhQUc3QixDQUFDLENBSHlDO0FBRTFDLG9CQUFvQjtBQUNwQixNQUFZLFNBQVMsV0FBTSxlQUUzQixDQUFDLENBRnlDO0FBRTFDLElBQUksaUJBQWlCLENBQUE7QUFDckIsSUFBSSxNQUFvQixDQUFBO0FBUXhCLElBQUksZ0JBQXNELENBQUE7QUFFMUQsUUFBUSxDQUFDLFNBQVMsRUFBRTtJQUNoQixFQUFFLENBQUMsc0JBQXNCLEVBQUUsVUFBVSxJQUFJO1FBQ3JDLElBQUksQ0FBQyxPQUFPLENBQUMsS0FBSyxDQUFDLENBQUE7UUFDbkIsaUJBQWlCLEdBQUcsT0FBTyxDQUFDLElBQUksQ0FBQywwQ0FBMEMsRUFBRSxFQUFFLEtBQUssRUFBRSxJQUFJLEVBQUUsTUFBTSxFQUFFLElBQUks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DQUFDLENBQUMsQ0FBQTtRQUNGLE9BQU8sQ0FBQyxJQUFJLENBQUMsd0NBQXdDLENBQUMsQ0FBQTtRQUN0RCxpQkFBaUIsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUE7SUFDckMsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9

View File

@ -85,6 +85,7 @@ describe('smartdata', function () {
color: 'red', color: 'red',
property2: 2 property2: 2
}) })
console.log(TestCar)
should(testCarInstance.collection).be.instanceof(smartdata.DbCollection) should(testCarInstance.collection).be.instanceof(smartdata.DbCollection)
should(testCarInstance).be.instanceof(smartdata.DbDoc) should(testCarInstance).be.instanceof(smartdata.DbDoc)
testCarInstance.save() testCarInstance.save()

View File

@ -3,16 +3,26 @@ import { Objectmap } from 'lik'
import { DbCollection } from './smartdata.classes.dbcollection' import { DbCollection } from './smartdata.classes.dbcollection'
/**
* interface - indicates the database type
*/
export type TDbType = 'mongodb' | 'nedb'
/**
* interface - indicates the connection status of the db
*/
export type TConnectionStatus = 'disconnected' | 'connected' | 'failed' export type TConnectionStatus = 'disconnected' | 'connected' | 'failed'
export class Db { export class Db {
dbType: TDbType
dbUrl: string dbUrl: string
db: plugins.mongodb.Db db: plugins.mongodb.Db | plugins.nedb
status: TConnectionStatus status: TConnectionStatus
collections = new Objectmap<DbCollection<any>>() collections = new Objectmap<DbCollection<any>>()
constructor(dbUrl: string) { constructor(dbUrlArg: string, dbTypeArg: TDbType = 'mongodb') {
this.dbUrl = dbUrl this.dbType = dbTypeArg
this.dbUrl = dbUrlArg
} }
// basic connection stuff ---------------------------------------------- // basic connection stuff ----------------------------------------------
@ -22,6 +32,7 @@ export class Db {
*/ */
connect(): plugins.q.Promise<any> { connect(): plugins.q.Promise<any> {
let done = plugins.q.defer() let done = plugins.q.defer()
if (this.dbType === 'mongodb') {
plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => { plugins.mongodb.MongoClient.connect(this.dbUrl, (err, db) => {
if (err) { console.log(err) } if (err) { console.log(err) }
plugins.assert.equal(null, err) plugins.assert.equal(null, err)
@ -29,6 +40,9 @@ export class Db {
plugins.beautylog.success(`connected to database at ${this.dbUrl}`) plugins.beautylog.success(`connected to database at ${this.dbUrl}`)
done.resolve(this.db) done.resolve(this.db)
}) })
} else if (this.dbType === 'nedb') {
this.db = new plugins.nedb()
}
return done.promise return done.promise
} }

View File

@ -12,6 +12,9 @@ export function Collection(db: Db) {
} }
export class DbCollection<T> { export class DbCollection<T> {
/**
* the collection that is used
*/
collection: plugins.mongodb.Collection collection: plugins.mongodb.Collection
name: string name: string
constructor(nameArg: string, dbArg: Db) { constructor(nameArg: string, dbArg: Db) {

View File

@ -3,3 +3,4 @@ export import assert = require('assert')
export import beautylog = require('beautylog') export import beautylog = require('beautylog')
export import mongodb = require('mongodb') export import mongodb = require('mongodb')
export import q = require('q') export import q = require('q')
export import nedb = require('nedb')