How to use the sharedb.DB.prototype function in sharedb

To help you get started, we’ve selected a few sharedb 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 WinMinTun / sharedb-mysql / index.js View on Github external
console.log('Connection %d released', connection.threadId);
		});
			
		pool.on('enqueue', function () {
			console.log('Waiting for available connection slot');
		});
	}
	
	ops_table = options.ops_table ? options.ops_table : 'ops';
	snapshots_table = options.snapshots_table ? options.snapshots_table : 'snapshots';
	

};
module.exports = MySQLDB;

MySQLDB.prototype = Object.create(DB.prototype);

MySQLDB.prototype.close = function(callback) {
	this.closed = true;
	if (callback) callback();
};

function rollback(client, done) {
	client.query('ROLLBACK', function(err) {
		return done(err);
	})
}

// Persists an op and snapshot if it is for the next version. Calls back with
// callback(err, succeeded)
MySQLDB.prototype.commit = (collection, id, op, snapshot, options, callback) => {
github share / sharedb-mongo / index.js View on Github external
var id = conditions[i].d;
        var ops = opsBulk[id];
        var doc = docMap[id];
        var from = fromMap[id];
        var to = toMap && toMap[id];
        var filtered = filterOps(ops, doc, to);
        var err = checkOpsFrom(collectionName, id, filtered, from);
        if (err) return callback(err);
        opsMap[id] = filtered;
      }
      callback(null, opsMap);
    });
  });
};

DB.prototype.getCommittedOpVersion = function(collectionName, id, snapshot, op, callback) {
  var self = this;
  this.getOpCollection(collectionName, function(err, opCollection) {
    if (err) return callback(err);
    var query = {
      src: op.src,
      seq: op.seq
    };
    var projection = {v: 1, _id: 0};
    var sort = {v: 1};
    // Find the earliest version at which the op may have been committed.
    // Since ops are optimistically written prior to writing the snapshot, the
    // op could end up being written multiple times or have been written but
    // not count as committed if not backreferenced from the snapshot
    opCollection.find(query).project(projection).sort(sort).limit(1).next(function(err, doc) {
      if (err) return callback(err);
      // If we find no op with the same src and seq, we definitely don't have
github share / sharedb-mongo / index.js View on Github external
if (typeof mongo === 'string' || typeof mongo === 'function') {
    // We can only get the mongodb client instance in a callback, so
    // buffer up any requests received in the meantime
    this.mongo = null;
    this._mongoClient = null;
    this.mongoPoll = null;
    this._mongoPollClient = null;
    this.pendingConnect = [];
    this._connect(mongo, options);
  } else {
    throw new Error('deprecated: pass mongo as url string or function with callback');
  }
};

ShareDbMongo.prototype = Object.create(DB.prototype);

ShareDbMongo.prototype.projectsSnapshots = true;

ShareDbMongo.prototype.getCollection = function(collectionName, callback) {
  // Check the collection name
  var err = this.validateCollectionName(collectionName);
  if (err) return callback(err);
  // Gotcha: calls back sync if connected or async if not
  this.getDbs(function(err, mongo) {
    if (err) return callback(err);
    var collection = mongo.collection(collectionName);
    return callback(null, collection);
  });
};

ShareDbMongo.prototype._getCollectionPoll = function(collectionName, callback) {
github share / sharedb-mongo / index.js View on Github external
if (typeof mongo === 'string' || typeof mongo === 'function') {
    // We can only get the mongodb client instance in a callback, so
    // buffer up any requests received in the meantime
    this.mongo = null;
    this.mongoPoll = null;
    this.pendingConnect = [];
    this._connect(mongo, options);
  } else {
    this.mongo = mongo;
    this.mongoPoll = options.mongoPoll;
    this.pendingConnect = null;
  }
};

ShareDbMongo.prototype = Object.create(DB.prototype);

ShareDbMongo.prototype.projectsSnapshots = true;

ShareDbMongo.prototype.getCollection = function(collectionName, callback) {
  // Check the collection name
  var err = this.validateCollectionName(collectionName);
  if (err) return callback(err);
  // Gotcha: calls back sync if connected or async if not
  this.getDbs(function(err, mongo) {
    if (err) return callback(err);
    var collection = mongo.collection(collectionName);
    return callback(null, collection);
  });
};

ShareDbMongo.prototype._getCollectionPoll = function(collectionName, callback) {
github share / sharedb-postgres / index.js View on Github external
var DB = require('sharedb').DB;
var pg = require('pg');

// Postgres-backed ShareDB database

function PostgresDB(options) {
  if (!(this instanceof PostgresDB)) return new PostgresDB(options);
  DB.call(this, options);

  this.closed = false;

  this.pg_config = options;
};
module.exports = PostgresDB;

PostgresDB.prototype = Object.create(DB.prototype);

PostgresDB.prototype.close = function(callback) {
  this.closed = true;
  if (callback) callback();
};

function rollback(client, done) {
  client.query('ROLLBACK', function(err) {
    return done(err);
  })
}

// Persists an op and snapshot if it is for the next version. Calls back with
// callback(err, succeeded)
PostgresDB.prototype.commit = function(collection, id, op, snapshot, options, callback) {
  /*