How to use cradle - 10 common examples

To help you get started, we’ve selected a few cradle examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github adrai / node-eventstore / lib / storage / couchDb / couchDbStorage.js View on Github external
var Storage = function(options) {
    // set options and load defaults if needed
    this.options = options || {};
    this.options.host = this.options.host || 'localhost';
    this.options.port = this.options.port || 5984;
    
    cradle.setup({host: this.options.host,
                  port: this.options.port,
                  options: {cache: true, raw: false}});
    
    this.collectionName = 'events';
    
    this.store = new(cradle.Connection)();
    
    this.client = this.store.database(this.collectionName);
    this.client.exists(function(err, res) {
        if (!res) {
            this.client.create();
        }
    }.bind(this));
};
github adrai / node-eventstore / lib / storage / couchDb / storage.js View on Github external
callback = !callback ? options : callback;
    options = callback ? options : {};
 
    // Set options and load defaults if needed.
    this.options = options || {};
    this.options.host = this.options.host || 'localhost';
    this.options.port = this.options.port || 5984;
    
    this.logger = this.options.logger || null;
    this.collectionName = this.options.collectionName || 'events';
    
    cradle.setup({host: this.options.host,
                  port: this.options.port,
                  options: {cache: true, raw: false}});
    
    this.store = new(cradle.Connection)();
    
    this.client = this.store.database(this.collectionName);
    this.client.exists(function(err, res) {
		if (err) {
			if (this.logger) {
				this.logger.error(JSON.stringify(err));
			}
		}
		else if (res === false) {
            this.client.create(function(err) {
                if (err) {
                    if (this.logger) {
						this.logger.error(JSON.stringify(err));
					}
                }
                else {
github ForgeRock / node-openam-agent / lib / cache.js View on Github external
function CouchDBCache(options) {
    var self = this;

    options = options || {};

    this.connection = new cradle.Connection({
        protocol: options.protocol || 'http',
        host: options.host || 'localhost',
        port: options.port || '5984',
        auth: options.auth,
        cache: false,
        raw: false,
        forceSave: true
    });

    this.db = this.connection.database(options.db || 'openamagent');

    this.expireAfterSeconds = options.expireAfterSeconds || 60;

    // create database if it doesn't exist
    this.db.exists(function (err, exists) {
        if (err) throw err;
github flatiron / resourceful / test / engines / couchdb.js View on Github external
engine.load = function (resourceful, data, callback) {
  var db = new(cradle.Connection)(engine.options).database(engine.options.database);
  db.destroy(function () {
    db.create(function () {
      db.save(data, function (e, res) {
        callback();
      });
    });
  });
};
github BrainJS / brain.js / test / cvalidate / runcv.js View on Github external
function getDb(couchUrl) {
  var parts = url.parse(couchUrl);
  var client = new cradle.Connection(parts.hostname, parts.port || 80);
  return client.database(parts.pathname);  
}
github prasmussen / glot.io / deploy / examples.js View on Github external
var glob = require("glob");
var cradle = require("cradle");
var fs = require("fs");

var path = require("path");
var config = JSON.parse(fs.readFileSync(path.join(__dirname, "config.json"), "utf8"));
var db = new(cradle.Connection)(config.url, config.port, {auth: {username: config.username, password: config.password}}).database(config.database);


glob.sync("examples/**/*.*").forEach(function(fpath) {
    var parts = fpath.split(path.sep);

    if (parts.length !== 4) {
        console.log("Skipping: " + fpath);
        return;
    }

    var code = fs.readFileSync(fpath, "utf8");

    var data = {
        type: "example",
        author: "_admin",
        language: parts[1],
github adrai / node-eventstore / storage / couchDb / storage.js View on Github external
this.filename = __filename;
    
    if (typeof options === 'function')
        callback = options;
        
    var defaults = {
        host: 'localhost',
        port: 5984,
        dbName: 'eventstore',
        eventsCollectionName: 'events',
        snapshotsCollectionName: 'snapshots'
    };
    
    this.options = mergeOptions(options, defaults);
    
    this.store = new(cradle.Connection)();
    this.client = this.store.database(this.options.dbName);
    this.client.exists(function(err, res) {
        if (err) {
			callback(err);
		}
		else if (res === false) {
            this.client.create(function(err) {
                if (err) {
                    callback(err);
                }
                else {
                    this.client.save('_design/'+this.options.dbName, {
                        eventsByStreamId: {
                            map: function (evt) {
                                if (!evt.snapshotId) {
                                    emit(evt.streamId, evt);
github prasmussen / glot.io / deploy / design.js View on Github external
var cradle = require("cradle");
var fs = require("fs");

var path = require("path");
var config = JSON.parse(fs.readFileSync(path.join(__dirname, "config.json"), "utf8"));
var db = new(cradle.Connection)(config.url, config.port, {auth: {username: config.username, password: config.password}}).database(config.database);


db.save("_design/languages", {
    views: {
        list: {
            map: function(doc) {
                if (doc.type === "language") {
                    emit(null, doc);
                }
            }
        }
    }
});

db.save("_design/snippets", {
    views: {
github nodester / nodester / lib / lib.js View on Github external
var get_couchdb_connection = function () {
  return new cradle.Connection({
    host: config.opt.couch_host,
    port: config.opt.couch_port,
    auth: {user: config.opt.couch_user, pass: config.opt.couch_pass},
    options: {cache: true, raw: false}
  });
};
exports.get_couchdb_connection = get_couchdb_connection;
github mklabs / backnode / examples / sync / couch / store.js View on Github external
var Store = module.exports = function Store(options){
  options = _.extend({}, options, {host: 'localhost', db: 'backnode'});
  this.db = new(cradle.Connection)().database(options.db);
};

cradle

the high-level, caching, CouchDB library

MIT
Latest version published 9 years ago

Package Health Score

48 / 100
Full package analysis

Popular cradle functions