GithubHelp home page GithubHelp logo

falcor-ioredis's Introduction

falcor-ioredis

NPM Build Status

What is this?

Falcor-ioredis is a simple piece of middleware that uses the Falcor-model to sync with a JSON Graph stored in a Redis database. If references are found, redis will be queried automatically for the references.

Useful links: Falcor, Ioredis

Installation

$ npm install falcor-ioredis
'use strict';

var EXPRESS         = require('express'),
    FALCORIOREDIS   = require('falcor-ioredis'),
    FALCORSERVER    = require('falcor-express'),
    FALCOR          = require('falcor'),
    EXPRESS         = require('express'),
    APP             = EXPRESS();

APP
    .use('/', function(req, res){
        var falcorIoredis = new FALCORIOREDIS('redis://localhost:6379', req, function(resultModel){
            var falcorModel = new FALCOR
                                    .Model(resultModel) ;
            var dataSourceRoute = FALCORSERVER
                                    .dataSourceRoute(function(req, res) {
                                        return  falcorModel
                                                    .asDataSource();
                                    });
            dataSourceRoute(req,res);
        });
    });

var server = APP
                .listen(8080, function(err) {
                    if (err) console.error(err);
                    console.log('JSON graph available on http://localhost:8080');
                });

How does it work?

Json Graph example:

{
    "somethingById": {
        "a": {
            "foo": "bar"
        },
        "b": {
            "foo": {
                "$type": "ref",
                "value": "valuesById[c]"
            }
        }
    },
    "valuesById": {
        "c": {
            "foo": "baz"
        }
    }
}

The above example will be stored like this in Redis:

HSET somethingById a '{"foo":{$type:"ref","value":"valuesById[a]"}}'
HSET somethingById b '{"foo":{"$type":"ref","value":"valuesById[c]"}}'
HSET valuesById c '{"foo":"baz"}'

Model request for: //localhost/?paths=[["somethingById","a","foo"]]&method=get will return:

{
    "jsonGraph": {
        "somethingById": {
            "a": {
                "foo": {
                    "$type": "atom",
                    "value": "bar",
                    "$modelCreated": true,
                    "$size": 3
                }
            }
        }
    },
    "paths": [
        [
            "somethingById",
            "a",
            "foo"
        ]
    ]
}

falcor-ioredis's People

Contributors

bobvanluijt avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

falcor-ioredis's Issues

Max call error

In redisPathsSorted.map(redisRequest); function redisRequest() should only be called on the last i

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.