octonom-mongodb
Advanced tools
Comparing version
import { Collection as DbCollection, CollectionInsertManyOptions, Cursor, Db, FindOneOptions } from 'mongodb'; | ||
import { Collection, ICollectionOptions, Model, ModelArray } from 'octonom'; | ||
export declare class MongoCollection<T extends object, TModel extends Model<T>> extends Collection<T, TModel> { | ||
import { Collection, ICollectionOptions, IModelConstructor, Model, ModelArray } from 'octonom'; | ||
export declare class MongoCollection<TModel extends Model<TModel>> extends Collection<TModel> { | ||
protected name: string; | ||
protected collection: DbCollection; | ||
constructor(name: string, model: new (data: any) => TModel, options?: ICollectionOptions); | ||
constructor(name: string, model: IModelConstructor<TModel>, options?: ICollectionOptions); | ||
insertMany(models: TModel[], options?: CollectionInsertManyOptions): Promise<void>; | ||
@@ -12,3 +12,3 @@ insertOne(model: TModel): Promise<void>; | ||
findById(id: string): Promise<TModel>; | ||
findByIds(ids: string[]): Promise<ModelArray<T, TModel>>; | ||
findByIds(ids: string[]): Promise<ModelArray<TModel>>; | ||
findOne(query: object, options?: FindOneOptions): Promise<TModel>; | ||
@@ -15,0 +15,0 @@ init(db: Db): Promise<void>; |
@@ -5,3 +5,3 @@ import { cloneDeep } from 'lodash'; | ||
import { CatModel, ICat } from 'octonom/build/test/data/models/cat'; | ||
import { CatModel } from 'octonom/build/test/data/models/cat'; | ||
@@ -11,3 +11,3 @@ import { MongoCollection } from './mongo-collection'; | ||
describe('MongoCollection', () => { | ||
class CatCollection extends MongoCollection<ICat, CatModel> {} | ||
class CatCollection extends MongoCollection<CatModel> {} | ||
const catObj = {id: '42', name: 'Yllim'}; | ||
@@ -14,0 +14,0 @@ |
import { Collection as DbCollection, CollectionInsertManyOptions, Cursor, | ||
Db, FindOneOptions } from 'mongodb'; | ||
import { Collection, ICollectionOptions, Model, ModelArray, utils } from 'octonom'; | ||
import { Collection, ICollectionOptions, IModelConstructor, Model, ModelArray, utils } from 'octonom'; | ||
export class MongoCollection<T extends object, TModel extends Model<T>> extends Collection<T, TModel> { | ||
export class MongoCollection<TModel extends Model<TModel>> extends Collection<TModel> { | ||
protected collection: DbCollection; | ||
@@ -11,3 +11,3 @@ | ||
protected name: string, | ||
model: new (data: any) => TModel, | ||
model: IModelConstructor<TModel>, | ||
options: ICollectionOptions = {}, | ||
@@ -49,3 +49,3 @@ ) { | ||
docs.forEach(doc => idInstanceMap[doc._id] = this.fromDb(doc)); | ||
return new ModelArray<T, TModel>(this.model, ids.map(id => idInstanceMap[id])); | ||
return new ModelArray<TModel>(this.model, ids.map(id => idInstanceMap[id])); | ||
} | ||
@@ -52,0 +52,0 @@ |
{ | ||
"name": "octonom-mongodb", | ||
"version": "1.0.0-alpha.5", | ||
"version": "1.0.0-alpha.6", | ||
"description": "MongoDB collection for Octonom", | ||
@@ -28,4 +28,5 @@ "main": "build/lib/main.js", | ||
"mongodb": "^2.2.29", | ||
"octonom": "^1.0.0-alpha.10" | ||
"octonom": "^1.0.0-alpha.11", | ||
"ts-node": "^3.3.0" | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
16567
0.08%4
33.33%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
Updated