improve README

This commit is contained in:
Philipp Kunz 2016-09-12 22:11:17 +02:00
parent e508a942e3
commit 11149b2712
8 changed files with 69 additions and 19 deletions

View File

@ -2,3 +2,18 @@
smartdata is a ODM that adheres to TypeScript practices and uses classes to organize data.
It uses MongoDB as persistent storage.
## Intention
There are many ODMs out there, however when we searched for a ODM that uses TypeScript,
acts smart while still embracing an easy the NoSQL idea we didn't find a matching solution.
This is why we started smartdata
How MongoDB terms map to smartdata classes
MongoDB term | smartdata class
--- | ---
Database | smartdata.DbConnection
Collection | smartdata.DbCollection
Document | smartdata.DbDoc
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

View File

@ -11,7 +11,7 @@ export declare class DbCollection<T> {
/**
* finds an object in the DbCollection
*/
find(docMatchArg: T): plugins.q.Promise<T[]>;
find(docMatchArg: T | any): plugins.q.Promise<T[]>;
/**
* inserts object into the DbCollection
*/

View File

@ -54,4 +54,4 @@ class DbCollection {
}
}
exports.DbCollection = DbCollection;
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRkYXRhLmNsYXNzZXMuZGJjb2xsZWN0aW9uLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQSxNQUFZLE9BQU8sV0FBTSxxQkFDekIsQ0FBQyxDQUQ2QztBQUc5QztJQUVJLFlBQVksT0FBZSxFQUFFLGVBQTZCO1FBQ3RELElBQUksQ0FBQyxVQUFVLEdBQUcsZUFBZSxDQUFDLEVBQUUsQ0FBQyxVQUFVLENBQUMsT0FBTyxDQUFDLENBQUE7SUFDNUQsQ0FBQztJQUVEOztPQUVHO0lBQ0gsbUJBQW1CLENBQUMsT0FBTyxJQUFJLENBQUM7SUFFaEM7O09BRUc7SUFDSCxJQUFJLENBQUMsV0FBYztRQUNmLElBQUksS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7O09BRUc7SUFDSCxVQUFVLENBQUMsV0FBZ0I7UUFDdkIsSUFBSSxJQUFJLEdBQUcsT0FBTyxDQUFDLENBQUMsQ0FBQyxLQUFLLEVBQVEsQ0FBQTtRQUNsQyxJQUFJLG9CQUFvQixHQUE4QixFQUFFLENBQUE7UUFDeEQsR0FBRyxDQUFDLENBQUMsSUFBSSxNQUFNLElBQUksV0FBVyxDQUFDLENBQUEsQ0FBQztZQUM1QixvQkFBb0IsQ0FBQyxJQUFJLENBQUMsSUFBSSxDQUFDLFFBQVEsQ0FBQyxNQUFNLENBQUMsQ0FBQyxDQUFBO1FBQ3BELENBQUM7UUFDRCxPQUFPLENBQUMsQ0FBQyxDQUFDLEdBQUcsQ0FBQyxvQkFBb0IsQ0FBQyxDQUFDLElBQUksQ0FBQztZQUNyQyxJQUFJLENBQUMsVUFBVSxDQUFDLFVBQVUsQ0FBQyxXQUFXLENBQUM7aUJBQ2xDLElBQUksQ0FBQyxRQUFRLElBQUksQ0FBQyxPQUFPLEVBQUUsQ0FBQSxDQUFDLENBQUMsQ0FBQyxDQUFBO1FBQ3ZDLENBQUMsQ0FBQyxDQUFBO1FBQ0YsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztJQUVPLFFBQVEsQ0FBQyxHQUFNO1FBQ25CLElBQUksSUFBSSxHQUFHLE9BQU8sQ0FBQyxDQUFDLENBQUMsS0FBSyxFQUFRLENBQUE7UUFDbEMsSUFBSSxDQUFDLE9BQU8sRUFBRSxDQUFBO1FBQ2QsTUFBTSxDQUFDLElBQUksQ0FBQyxPQUFPLENBQUE7SUFDdkIsQ0FBQztBQUNMLENBQUM7QUF4RFksb0JBQVksZUF3RHhCLENBQUEifQ==

19
docs/index.md Normal file
View File

@ -0,0 +1,19 @@
# smartdata
smartdata is a ODM that adheres to TypeScript practices and uses classes to organize data.
It uses MongoDB as persistent storage.
## Intention
There are many ODMs out there, however when we searched for a ODM that uses TypeScript,
acts smart while still embracing an easy the NoSQL idea we didn't find a matching solution.
This is why we started smartdata
How MongoDB terms map to smartdata classes
MongoDB term | smartdata class
--- | ---
Database | smartdata.DbConnection
Collection | smartdata.DbCollection
Document | smartdata.DbDoc
[![npm](https://push.rocks/assets/repo-header.svg)](https://push.rocks)

View File

@ -33,25 +33,25 @@ describe('smartdata', function () {
testDbCollection = new smartdata.DbCollection('something', testDbConnection);
});
it('should insert a doc into the collection', function (done) {
testDbCollection.insertOne({ hello: 'test' }).then(() => { done(); });
testDbCollection.insertOne({ value1: 'test' }).then(() => { done(); });
});
it('should find all docs of testDbCollection', function (done) {
testDbCollection.find({}).then((resultArray) => {
console.log(resultArray);
should(resultArray[0].hello).equal('test');
should(resultArray[0].value1).equal('test');
done();
});
});
it('should insert many docs into the collection', function (done) {
testDbCollection.insertMany([
{ hello: 'test' },
{ wow: 'what is this', wow2: 3 }
{ value1: 'test2' },
{ value1: 'test', value2: 3, value3: 'hi' }
]).then(() => { done(); });
});
it('should find a specified doc', function (done) {
testDbCollection.find({ 'wow2': { '$exists': true } }).then((resultArray) => {
testDbCollection.find({ 'value3': { '$exists': true } }).then((resultArray) => {
console.log(resultArray);
should(resultArray[0].wow2).equal(3);
should(resultArray[0].value3).equal('hi');
done();
}).catch(console.log);
});
@ -71,4 +71,4 @@ describe('mongodb', function () {
mongoChildProcess.kill('SIGTERM');
});
});
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoidGVzdC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbInRlc3QudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IjtBQUFBLFFBQU8sY0FFUCxDQUFDLENBRm9CO0FBRXJCLE1BQVksT0FBTyxXQUFNLFNBQ3pCLENBQUMsQ0FEaUM7QUFDbEMsTUFBWSxNQUFNLFdBQU0sUUFDeEIsQ0FBQyxDQUQrQjtBQUNoQyxNQUFZLFdBQVcsV0FBTSxhQUc3QixDQUFDLENBS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FDTCxDQUFDLENBQUMsQ0FBQTtRQUNGLE9BQU8sQ0FBQyxJQUFJLENBQUMsd0NBQXdDLENBQUMsQ0FBQTtRQUN0RCxpQkFBaUIsQ0FBQyxJQUFJLENBQUMsU0FBUyxDQUFDLENBQUE7SUFDckMsQ0FBQyxDQUFDLENBQUE7QUFDTixDQUFDLENBQUMsQ0FBQSJ9

View File

@ -9,7 +9,22 @@ import * as smartdata from '../dist/index'
let mongoChildProcess
let testDbConnection: smartdata.DbConnection
let testDbCollection: smartdata.DbCollection<any>
interface ITestObject1 {
value1: string
value2?: number
value3?: string
}
let testDbCollection: smartdata.DbCollection<ITestObject1>
class testCar {
color: string
constructor(colorArg:string) {
this.color = colorArg
}
}
describe('mongodb', function () {
it('should start mongodb', function (done) {
@ -27,34 +42,35 @@ describe('mongodb', function () {
})
})
})
describe('smartdata', function () {
it('should establish a connection to mongodb', function (done) {
testDbConnection = new smartdata.DbConnection('mongodb://localhost:27017/smartdata')
testDbConnection.connect().then(() => { done() })
})
it('should create a collection', function () {
testDbCollection = new smartdata.DbCollection('something', testDbConnection)
testDbCollection = new smartdata.DbCollection<ITestObject1>('something', testDbConnection)
})
it('should insert a doc into the collection', function (done) {
testDbCollection.insertOne({ hello: 'test' }).then(() => { done() })
testDbCollection.insertOne({ value1: 'test' }).then(() => { done() })
})
it('should find all docs of testDbCollection', function (done) {
testDbCollection.find({}).then((resultArray) => {
console.log(resultArray)
should(resultArray[0].hello).equal('test')
should(resultArray[0].value1).equal('test')
done()
})
})
it('should insert many docs into the collection', function (done) {
testDbCollection.insertMany([
{ hello: 'test' },
{ wow: 'what is this', wow2: 3}
{ value1: 'test2' },
{ value1: 'test', value2: 3, value3: 'hi' }
]).then(() => { done() })
})
it('should find a specified doc', function (done) {
testDbCollection.find({'wow2': {'$exists': true}}).then((resultArray) => {
testDbCollection.find({'value3': {'$exists': true}}).then((resultArray) => {
console.log(resultArray)
should(resultArray[0].wow2).equal(3)
should(resultArray[0].value3).equal('hi')
done()
}).catch(console.log)
})

View File

@ -15,7 +15,7 @@ export class DbCollection<T> {
/**
* finds an object in the DbCollection
*/
find(docMatchArg: T): plugins.q.Promise<T[]> {
find(docMatchArg: T | any): plugins.q.Promise<T[]> {
let done = plugins.q.defer<T[]>()
this.collection.find(docMatchArg).toArray((err, docs) => {
if (err) { throw err }

View File