GithubHelp home page GithubHelp logo

nvdnkpr / mongoose-schema-registry Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sax1johno/mongoose-schema-registry

0.0 2.0 0.0 1.69 MB

This allows users to register schemas without creating a mongoose model. This allows extension of schemas later on prior to registering those models.

License: Mozilla Public License 2.0

mongoose-schema-registry's Introduction

mongoose-schema-registry

The Mongoose Schema Registry allows developers to register schemas without creating a mongoose model. This allows extension of schemas later on prior to registering those models.

The following quick example should help you get started (taken from the ghiraldi framework mvc.js file):

    File1.js
    // First, declare the registry object.
    var registry = require('mongoose-schema-registry'),

    // The registry fires events when schemas are added.
    registry.on('add', function(tag, schema) {
        // tag contains the name you gave the schema when you added it.
        // schema is the actual schema added.
    });
    
    // Add a schema to the registry using the add method
    registry.add('schema_name', schema);

You can modify an existing schema by calling the getSchema method. Since the registry is a singleton, requiring will give you the same object with the already registered schemas.

    // File2.js
    var registry = require('mongoose-schema-registry');
    
    var testSchema = registry.getSchema('testSchema');
    // From here, you can add things to your test schema.
    ..
    // When you're done, just re-add the schema.  The new one will clobber 
    // the old one.
    registry.add('testSchema', testSchema);

To finally register the schemas into mongoose models, just iterate through the schemas and call the mongoose.model method.

    var keys = registry.getKeys();
    _.each(keys, function(key, index, list) {
        var thisSchema = registry.getSchema(key);
        mongoose.model(key,  thisSchema);
    });

mongoose-schema-registry's People

Contributors

sax1johno avatar talamaska avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.