GithubHelp home page GithubHelp logo

mydb-expose's Introduction

This repository is no longer maintained

mydb-expose

Connect middleware to expose documents through MyDB.

Example

// dependencies
var mydb = require('mydb-expose');
var express = require('express');
var app = express();
var db = require('monk')():

// middleware
app.use(express.cookieParser());
app.use(mydb({ mongo: '127.0.0.1:27017', url: '127.0.0.1:3000' }));

// example session route
app.post('/login', function(req, res){
  req.session.set('user_id', '123');
  res.send(200);
});

// example document expose
app.get('/some/doc', function(req, res){
  res.send(db.get('collection').findOne({ some: 'query' }));
});

API

Middleware

Options:

  • url
    • a string like cloudup.mydb.io or a reference to the mydb server object in case it's in the same process
  • redis
    • a redis client instance or
    • a string like localhost:6379
  • mongo
    • a monk instance
    • a string like localhost:27017/test
  • sessionExpose
    • fields to expose from the session document (defaults to '-sid')

ServerResponse#send

The express method is overridden to detect monk-style Promise objects.

If the request contains the header X-Requested-With: MyDB.

ServerRequest#session

Points to the

MySession

Operations executed on the session object defer the response sent to the client automatically, unless a callback is passed to one of the functions below.

Errors are nextd automatically.

The object is populated with the latest snapshot from the database.

reload(fn)

Reloads the session from database.

set(key, val, fn)

Calls $set with the given key and val.

unset(key, fn)

Calls $unset with the given key.

pop(key, fn)

Calls $pop with the given key.

shift(key, fn)

Calls $pop with the given key and -1, producing a shift.

push(key, val, fn)

Calls $push to the given key with val.

pushAll(key, vals, fn)

Calls $push to the given key with vals.

pull(key, val, fn)

Calls $pull with the given key and val.

pullAll(key, vals, fn)

Calls $pullAll with the given key and vals.

rename(key, newKey, fn)

Calls $rename with the given key and newKey.

get(key, fn)

Gets the given key asynchronously. Normally you just want to access req.session[key].

mydb-expose's People

Contributors

belcherj avatar coreh avatar rauchg avatar tj 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.