2016-09-11 18:01:46 +02:00
|
|
|
import * as plugins from './smartdata.plugins'
|
|
|
|
import { DbConnection } from './smartdata.classes.dbconnection'
|
|
|
|
|
|
|
|
export class DbCollection<T> {
|
|
|
|
collection: plugins.mongodb.Collection
|
|
|
|
constructor(nameArg: string, dbConnectionArg: DbConnection) {
|
|
|
|
this.collection = dbConnectionArg.db.collection(nameArg)
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* adds a validation function that all newly inserted and updated objects have to pass
|
|
|
|
*/
|
2016-09-12 17:31:23 +02:00
|
|
|
addObjectValidation(funcArg){}
|
2016-09-11 18:01:46 +02:00
|
|
|
|
|
|
|
/**
|
2016-09-12 17:31:23 +02:00
|
|
|
* finds an object in the DbCollection
|
2016-09-11 18:01:46 +02:00
|
|
|
*/
|
2016-09-12 17:31:23 +02:00
|
|
|
find(docMatchArg: T): T[] {
|
|
|
|
return this.collection.find().toArray()
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* inserts object into the DbCollection
|
|
|
|
*/
|
|
|
|
insertOne(docArg: T): PromiseLike<void> {
|
|
|
|
return this.collection.insertOne(docArg)
|
|
|
|
}
|
2016-09-11 18:01:46 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* inserts many objects at once into the DbCollection
|
|
|
|
*/
|
2016-09-12 17:31:23 +02:00
|
|
|
insertMany(docArrayArg: T[]): void {
|
|
|
|
|
|
|
|
}
|
2016-09-11 18:01:46 +02:00
|
|
|
}
|