jps-ds

This is a simple MongoDB datasource module.

#jps-ds

This is a simple MongoDB datasource module.

Install the module with: npm install jps-ds

var DS = require('jps-ds').DS;

To create and configure a new connection use the following:

var _ds = new DS( {
    //host: 'localhost/learning-yeoman',
    host: 'test:test@ds037498.mongolab.com:37498/learning-yeoman',
    models: {
        'pages': { title: String, body: String, published: Boolean, created: Date}
    }
} );

To find all objects in the database use the following:

_ds.findAll('pages').then(function(data){
    pages = data;
    console.log(pages[0]._id);
});

To find 1 object in the database use the following:

_ds.findAll('pages').then(function(data){
    pages = data;
    console.log(pages[0]._id);
});

To create an object in the database use the following:

_ds.create( 'pages', {
    title: 'Page ' + Date.now(),
    body: 'This is the page content.',
    published: true,
    created: new Date()
} ).then( function (page) {
    console.log( 'page created', page );
} );

To update an object in the database use the following:

_ds.update( 'pages', pages[0]._id, {title: 'updated title'} ).then( function (data) {
        console.log(data);
} );

To delete an object in the database use the following:

_ds.destroy( 'pages', 1).then( function (data) {
    console.log(data); //true
} );

Download the production version or the development version.

In your web page:

<script src="dist/ds.min.js"></script>
<script>
ds(); // "data source"
</script> 

(Coming soon)

(Coming soon)

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using Grunt.

Also, please don't edit files in the "dist" subdirectory as they are generated via Grunt. You'll find source code in the "lib" subdirectory!

(Nothing yet)

Copyright (c) 2014 Jonnie Spratley. Licensed under the MIT license.