New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

mongodb-datamapper

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongodb-datamapper

A MongoDb Data-Mapper implementation.

latest
npmnpm
Version
0.0.2
Version published
Maintainers
1
Created
Source

MongoDb Data Mapper Build Status npm version

What ?

A data mapper is an abstraction on top of a persistence mechanism. It works as a bridge between domain entities and a data store.

Why ?

MongoDb Data Mapper is easier to test alternative to popular Active Record-based ORMs. It achieves so by exposing a minimalist (therefore trivial to mock) API and providing set-up/tear-down methods.

How ?

const coroutine = require('co');
const mongoDataMapper = require('mongodb-datamapper');

const petsDataMapper = mongoDataMapper({
  connectionUri: 'mongodb://localhost/test',
  collectionName: 'pets',
});

coroutine(function* () {
  // Always `initialize` before querying.
  yield petsDataMapper.initialize();

  const herPets = yield petsDataMapper.find({ owner: 'Sabrina' });

  herPets.forEach(p => console.log(p.name));

  // `destroy` mapper once you're done.
  yield petsDataMapper.destroy();
});

Using with your transform-s:

const coroutine = require('co');
const mongoDataMapper = require('mongodb-datamapper');

const student = require('./my-awesome-domain/student');

const studentsDataMapper = mongoDataMapper({
  transform: student,
  connectionUri: 'mongodb://localhost/test',
  collectionName: 'students',
});

coroutine(function* () {
  yield studentsDataMapper.initialize();

  const allStudents = yield studentsDataMapper.find();
  const studentsWithHighScores = allStudents.map(s => s.averageScore > 90);

  studentsWithHighScores.forEach(s => {
    s.showOffGoldenStars(); // Assume `student#showOffGoldenStars`
  });

  yield studentsDataMapper.destroy();
});

Keywords

mongodb

FAQs

Package last updated on 12 Apr 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts