Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

clientside-model-manager

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

clientside-model-manager

sequelize and mongoose style object-modeling database-interface for the browser

  • 1.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

clientside-model-manager

Basic Usage

1. define your models

var Backtest = function(object){
    Object.assign(this, object); // when we retrieve an object from the database, append its values to this object
}
Backtest.prototype = {
    find : async function(options){
        // validate the options
        var [valid, error] = this.validate_find_options(options);
        if(valid !== true) throw error;

        // pass request to server
        var database_object = await api.get("/models/find/backtest", options); // let the server handle interpreting and validating the where string

        // cast server response to backtest objects
        var casted_object =  new this.constructor(database_object); // same as `new Backtest(database_object)``

        // return the data
        return data;
    },
}

2. initialize the model manager

var active_models = {
    "Plan" : "/_models/plan.js",
    "Funding" : "/_models/funding.js",
    "Backtest" : {path:"/_models/backtest.js", preload:true}
}
var models = new Model_Manager(active_models)
module.exports = models;

3. use the models - like you would with sequelize or mongodb

var models = await require("path/to/models")
models.Backtest.find({
    where : {
        Parent : parent.type,
        ParentId : parent.id,
    }
})

Caching

Since making requests to the database is expensive from the client, the module manager comes with the ability to cache data. The only thing a developer must keep in mind while using the caching functionality is that the developer will need to manually trigger data_pulls from the database to ensure that data is up to date.

  • note, automatic timed updates will be availible in future - but this will still not resolve this problem entirely

Keywords

FAQs

Package last updated on 23 Mar 2018

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc