Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
MarsDB is a lightweight client-side MongoDB-like database, Promise based, written in ES6
MarsDB is a lightweight client-side database.
It based on a Meteor’s minimongo
mathing/modifying implementation. It carefully written on ES6
, usess modular lodash
, have a Promise
based interface and may be backed with any storage implementation (LevelUP, LocalStorage, IndexDB, etc). It also supports observable
cursors.
MarsDB supports any kind of find/update/remove operations that Meteor’s minimongo does. So, go to the Meteor docs for supported query/modifier operations.
You can use it in any JS environment (Browser, Electron, NW.js, Node.js).
Include marsdb.angular.js
after marsdb.min.js
and angular.js
in your <head>
. Then add a MarsDB
dependency in your module. That's it. Now you can use $collection
factory. For example:
angular.module(‘app’, [‘MarsDB’])
.controller(function($scope, $collection) {
const posts = $collection(‘posts’);
// All methods in $collection returns a $q promise
// So you don’t need to manually call $digest
posts.find({authorId: 123}).observe((docs) => {
$scope.posts = docs;
}, $scope).then(() => {
$scope.loaded = true;
});
// $scope at last argument needed for auto-binding
// to a “$destroy” event of the scope for stop
// observing changes. You can call it manually and
// don’t pass last argument.
});
You also can use MarsDB within browserify environment. Just require(‘marsdb/dist/angular’)
and MarsDB module will be added to the angular. Angular must be defined in a window
or must be available as a module require(‘angular’)
.
The ./dist
folder contains already compiled to a ES5 code, but some polyfills needed. For using in a browser you must to include marsdb.polyfills.js
before marsdb.min.js
. In node.js you need to require(‘marsdb/polyfills’)
.
It sets in a window/global: Promise, Set and Symbol.
import Collection from ‘marsdb’;
import LocalStorageManager from 'marsdb/lib/LocalStorageManager';
// Setup different id generator and storage managers
// Default storage is in-memory
Collection.defaultStorageManager(LocalStorageManager);
Collection.defaultIdGenerator(() => {
return {
value: Math.random(),
seed: 0,
};
});
const users = new Collection(‘users’);
const posts = new Collection(‘posts’);
posts.find({author: ‘Bob’})
.sort([‘createdAt’])
.then(docs => {
// do something with docs
});
An order of pipeline methods invokation is important. Next pipeline operation gives as argument a result of a previous operation.
const posts = new Collection(‘posts’);
posts.find()
.limit(10)
.sortFunc((a, b) => a - b + 10)
.filter(doc => Matsh.sqrt(doc.comment.length) > 1.5)
.map(doc => doc.comments.length)
.reduce((acum, val) => acum + val)
.then(result => {
// result is a sum of coutn of comments
// in all found posts
});
Observable cursor returned only by a find
method of a collection. Updates of the cursor is batched and debounced (default batch size is 20
and debounce time is 1000 / 15
ms). You can change the paramters by batchSize
and debounce
methods of an observable cursor (methods is chained).
const posts = new Collection(‘posts’);
const stopper = posts.find({tags: {$in: [‘marsdb’, ‘is’, ‘awesome’]}})
.observe(docs => {
// invoked on every result change
// (on initial result too)
stopper.stop(); // stops observing
}).then(docs => {
// invoked once on initial result
// (after `observer` callback)
});
Joined objects is not obervable yet.
const users = new Collection(‘users’);
const posts = new Collection(‘posts’);
posts.find()
.join(doc => {
// Return a Promise for waiting of the result
return users.findOne(doc.authorId).then(user => {
doc.authorObj = user;
return doc;
});
})
.join(doc => {
// Also any other “join” mutations supported
doc.another = _cached_data_by_post[doc._id];
// You need to return a document, bacause it's
// a pipeline operation
return doc;
});
const posts = new Collection(‘posts’);
posts.insert({text: ‘MarsDB is awesome’}).then(docId => {
// Invoked after persisting document
})
posts.insertAll(
{text: ‘MarsDB’},
{text: ‘is’},
{text: ‘awesome’}
).then(docsIds => {
// invoked when all documents inserted
});
const posts = new Collection(‘posts’);
posts.update(
{authorId: {$in: [1, 2, 3]}},
{$set: {text: ‘noop’}}
).then(result => {
console.log(result.modified) // count of modified docs
console.log(result.updated) // array of updated docs
console.log(result.original) // array of original docs
});
const posts = new Collection(‘posts’);
posts.remove({authorId: {$in: [1,2,3]}})
.then(removedDocs => {
// do something with removed documents array
});
I’m waiting for your pull requests and issues.
Don’t forget to execute gulp lint
before requesting. Accepted only requests without errors.
See License
FAQs
MarsDB is a lightweight client-side MongoDB-like database, Promise based, written in ES6
The npm package marsdb receives a total of 1,088 weekly downloads. As such, marsdb popularity was classified as popular.
We found that marsdb demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.