xpress-mongo
Advanced tools
Comparing version 0.0.27 to 0.0.28
@@ -332,2 +332,15 @@ "use strict"; | ||
/** | ||
* Update model using raw updateQuery | ||
* @param update | ||
* @param options | ||
* @return {Promise<UpdateWriteOpResult>} | ||
*/ | ||
updateRaw(update, options) { | ||
if (!this.id()) | ||
throw "UPDATE_RAW_ERROR: Model does not have an _id, so we assume it is not from the database."; | ||
return new Promise((resolve, reject) => { | ||
return this.constructor.thisCollection().updateOne({ _id: this.id() }, update, options, (error, res) => error ? reject(error) : resolve(res.connection)); | ||
}); | ||
} | ||
/** | ||
* Create Model if not id is missing or save document if id is found. | ||
@@ -559,3 +572,2 @@ * @param options | ||
* @param {{}} data | ||
* @return {XMongoModel} | ||
*/ | ||
@@ -779,3 +791,2 @@ static use(data) { | ||
* @param raw | ||
* @return {Promise<XMongoModel>} | ||
*/ | ||
@@ -782,0 +793,0 @@ static findOne(query, options = {}, raw = false) { |
{ | ||
"name": "xpress-mongo", | ||
"version": "0.0.27", | ||
"version": "0.0.28", | ||
"description": "Light Weight ODM for mongoDb", | ||
@@ -5,0 +5,0 @@ "main": "js/index.js", |
@@ -14,3 +14,3 @@ import ObjectCollection = require('object-collection'); | ||
CollectionInsertOneOptions, | ||
CollectionAggregationOptions, AggregationCursor | ||
CollectionAggregationOptions, AggregationCursor, UpdateQuery | ||
} from 'mongodb'; | ||
@@ -411,2 +411,19 @@ | ||
/** | ||
* Update model using raw updateQuery | ||
* @param update | ||
* @param options | ||
* @return {Promise<UpdateWriteOpResult>} | ||
*/ | ||
updateRaw(update: UpdateQuery<any> | Partial<any>, options?: UpdateOneOptions): Promise<UpdateWriteOpResult> { | ||
if (!this.id()) throw "UPDATE_RAW_ERROR: Model does not have an _id, so we assume it is not from the database."; | ||
return new Promise((resolve, reject) => { | ||
return (<typeof XMongoModel>this.constructor).thisCollection().updateOne( | ||
{_id: this.id()}, | ||
update, | ||
<UpdateOneOptions>options, | ||
(error, res) => error ? reject(error) : resolve(res.connection)) | ||
}); | ||
} | ||
/** | ||
* Create Model if not id is missing or save document if id is found. | ||
@@ -684,3 +701,2 @@ * @param options | ||
* @param {{}} data | ||
* @return {XMongoModel} | ||
*/ | ||
@@ -919,5 +935,4 @@ static use(data: StringToAnyObject): XMongoModel { | ||
* @param raw | ||
* @return {Promise<XMongoModel>} | ||
*/ | ||
static findOne(query: StringToAnyObject, options: FindOneOptions | boolean = {}, raw = false): Promise<XMongoModel | null> { | ||
static findOne<T extends XMongoModel>(query: StringToAnyObject, options: FindOneOptions | boolean = {}, raw = false): Promise<T | null> { | ||
@@ -936,3 +951,3 @@ if (typeof options === "boolean") { | ||
return resolve(this.use(data)); | ||
return resolve(this.use(data) as T); | ||
}); | ||
@@ -939,0 +954,0 @@ }); |
import ObjectCollection = require('object-collection'); | ||
import { ObjectID, Collection, UpdateWriteOpResult, InsertOneWriteOpResult, DeleteWriteOpResultObject, Cursor, FindOneOptions, UpdateOneOptions, CollectionInsertOneOptions, CollectionAggregationOptions, AggregationCursor } from 'mongodb'; | ||
import { ObjectID, Collection, UpdateWriteOpResult, InsertOneWriteOpResult, DeleteWriteOpResultObject, Cursor, FindOneOptions, UpdateOneOptions, CollectionInsertOneOptions, CollectionAggregationOptions, AggregationCursor, UpdateQuery } from 'mongodb'; | ||
import { XMongoSchemaBuilder } from './XMongoSchemaBuilder'; | ||
@@ -161,2 +161,9 @@ import { PaginationData, StringToAnyObject } from "./CustomTypes"; | ||
/** | ||
* Update model using raw updateQuery | ||
* @param update | ||
* @param options | ||
* @return {Promise<UpdateWriteOpResult>} | ||
*/ | ||
updateRaw(update: UpdateQuery<any> | Partial<any>, options?: UpdateOneOptions): Promise<UpdateWriteOpResult>; | ||
/** | ||
* Create Model if not id is missing or save document if id is found. | ||
@@ -194,3 +201,2 @@ * @param options | ||
* @param {{}} data | ||
* @return {XMongoModel} | ||
*/ | ||
@@ -274,5 +280,4 @@ static use(data: StringToAnyObject): XMongoModel; | ||
* @param raw | ||
* @return {Promise<XMongoModel>} | ||
*/ | ||
static findOne(query: StringToAnyObject, options?: FindOneOptions | boolean, raw?: boolean): Promise<XMongoModel | null>; | ||
static findOne<T extends XMongoModel>(query: StringToAnyObject, options?: FindOneOptions | boolean, raw?: boolean): Promise<T | null>; | ||
/** | ||
@@ -279,0 +284,0 @@ * Fetches the first document that matches id provided. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
126544
3433