npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

periodicjs.core.data

v2.4.1

Published

Core data is the ORM wrapping component of periodicjs.core.controller that provides database adapters for commonly used databases (ie. mongo, sql, postgres). Adapters provide a standard set of methods and options regardless of the type of database and so

Downloads

179

Readme

periodicjs.core.data

Build Status NPM version Coverage Status Join the chat at https://gitter.im/typesettin/periodicjs.core.data

Description

Core data is the ORM wrapping component of periodicjs.core.controller that provides database adapters for commonly used databases (ie. mongo, sql, postgres). Adapters provide a standard set of methods and options regardless of the type of database and so the methods for querying, updating, creating etc. that are exposed across your application always expect the same inputs and provide the same outputs.

Standardization of usage makes implementation easier and allows for more confidence in development. Additionally, core data implements a basic interface for instantiating adapters and so all custom adapters are guaranteed to operate under the same basic guidelines.

Full Documentation

Usage (basic)

//Basic usage (mongodb)
const mongoose = require('mongoose');
mongoose.connect();
const AdapterInterface = require('periodicjs.core.data');
const ExampleSchema = require('./some/path/to/schema');
let ExampleModel = mongoose.model('Example', ExampleSchema);
let Adapter = AdapterIterface.create({ adapter: 'mongo', model: ExampleModel }); //example core datum for the Example mongoose schema
let exampleDocument = { //example mongo document
    title:'example document',
    createdat: new Date(),
};
mongoose.once('open', () => {
    // The model property in above example can also be set to the name of the registered model. 
    // See documentation for full list of options for .create method
    Adapter.create({ newdoc: exampleDocument })

    //Adapters also have a stream method which resolves with a stream of query data
    let writeStream = require('fs').createWriteStream('./some/path/to/file');
    Adapter.stream({...})
    	.then(dbstream => {
        	dbstream.pipe(writeStream);
        });
});

Usage (with configuration Options)

const mongoose = require('mongoose');
mongoose.connect();
const AdapterInterface = require('periodicjs.core.data');
const ExampleSchema = require('./some/path/to/schema');
let ExampleModel = mongoose.model('Example', ExampleSchema);
let config = { limit: 500, sort: '-createdat'};
let Adapter = AdapterIterface.create(Object.assign({ adapter: 'mongo', model: ExampleModel }, config)); //example core datum for the Example mongoose schema
let exampleDocument = { //example mongo document
    title:'example document',
    createdat: new Date(),
};
mongoose.once('open', () => {
    //All adapter methods optionally accept a callback argument
    Adapter.load({title:'example'}, function (err, data) {
    	//Provide some error first callback function
    });

});

Usage (with custom adapter)

const mongoose = require('mongoose');
mongoose.connect();
const AdapterInterface = require('periodicjs.core.data');
const ExampleSchema = require('./some/path/to/schema');
let ExampleModel = mongoose.model('Example', ExampleSchema);
let config = { limit: 500, sort: '-createdat' };
let Adapter = AdapterIterface.create(Object.assign({ adapter: 'mongo', model: ExampleModel }, config)); //example core datum for the Example mongoose schema
let exampleDocument = { //example mongo document
    title:'example document',
    createdat: new Date(),
};
mongoose.once('open', () => {
    //Implementing a custom adapter
    const CustomAdapter = function () {
        this.search = function () {};
        this.load   = function () {};
        this.query  = function () {};
        this.update = function () {};
        this.delete = function () {};
        this.stream = function () {};
        this.create = function () {};
        return this;
    };
    const Adapter = AdapterInterface.create({ adapter: CustomAdapter, model: ExampleModel });
    //Custom adapters must implement .search, .load, .query, .update, .delete, .stream and .create methods
});

Development

Make sure you have grunt installed

$ npm install -g grunt-cli jsdoc-to-markdown

For generating documentation

$ grunt doc
$ jsdoc2md adapters/**/*.js utility/**/*.js defaults/**/*.js index.js > doc/api.md

Notes

Testing

$ npm test

Contributing

License

MIT