hydrate-mongodb
Version:
An Object Document Mapper (ODM) for MongoDB.
49 lines (48 loc) • 1.87 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var mongodb_1 = require("mongodb");
var mappingBase_1 = require("./mappingBase");
var mappingModel_1 = require("./mappingModel");
var BufferMapping = (function (_super) {
__extends(BufferMapping, _super);
function BufferMapping() {
return _super.call(this, 16384) || this;
}
BufferMapping.prototype.read = function (context, value) {
if (value == null)
return null;
if (!value._bsontype || value._bsontype != "Binary") {
context.addError("Expected Binary.");
return;
}
return value.value(true);
};
BufferMapping.prototype.write = function (context, value) {
if (value == null)
return null;
if (!Buffer.isBuffer(value)) {
context.addError("Expected Buffer.");
return;
}
return new mongodb_1.Binary(value);
};
BufferMapping.prototype.areEqual = function (documentValue1, documentValue2) {
if (documentValue1 === documentValue2)
return true;
if (documentValue1 == null || documentValue2 == null)
return false;
return documentValue1.value(true).equals(documentValue2.value(true));
};
return BufferMapping;
}(mappingBase_1.MappingBase));
exports.BufferMapping = BufferMapping;