Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

mapql

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mapql

A MongoDB inspired ES6 Map() query langauge.

  • 0.0.9
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15
decreased by-48.28%
Maintainers
1
Weekly downloads
 
Created
Source

MapQL (WIP)

A MongoDB inspired ES6 Map() query language. - Build Status

This is a WIP; do NOT use in production yet! See TODO for more information.

Testing

Node:

You can test with node.js via npm test.

Browser:

For local browser testing with karma run npm run-script local or karma start tests/local.karma.js to run tests with PhantomJS and/or any browsers you have access to.

Sauce Labs:

See karma-sauce-launcher and sauce.karma.js.

 # See more about Open Source testing at https://saucelabs.com/open-source
 $ export SAUCE_USERNAME=*****        # Your Sauce Labs username.
 $ export SAUCE_ACCESS_KEY=*****      # Your Sauce Labs access key.
 $ karma start tests/sauce.karma.js   # npm run-script sauce

Browser Support

Build Status

ES6 supported browsers:

<!-- MapQL() WITHOUT chain() support (es6)-->
<script src="./dist/MapQL.es6.js"></script>
<!-- MapQL() WITH chain() support (es6) -->
<script src="./dist/MapQL.es6.chainable.js"></script>

ES5 (babel transpiled):

<!-- MapQL() WITHOUT chain() support-->
<script src="./dist/MapQL.es5.js"></script>
<!-- MapQL() WITH chain() support (es6) -->
<script src="./dist/MapQL.es5.chainable.js"></script>

You can use unpkg to retrieve dist files.

Implemented Query Operators

Used with {Instance}.find(<Query>) and {Instance}.remove(<Query>[, <Multi (Boolean)>]).

  • Comparison
    • $eq, $gt, $gte, $lt, $lte, $ne, $in, $nin
  • Logical
    • $or, $and
  • Element
    • $exists, $type
  • Evaluation
    • $regex, $where
  • Array
    • $size

Implemented Update Operators

Used with {Instance}.update(<Query>, <Update>).

  • Fields
    • $set, $inc, $mul, $unset
  • Array
    • $pop

Import/Export

Please note that importing and exporting data is highly experimental. This feature currently exports as json, so certain keys or references may not be supported. Any input on how to improve import/export of Map() would be greatly appreciated. Please see #5 for further information.

Current (known) supported data types:

  • Primitives
    • Boolean, Null, Undefined, Number, String, Symbol, Object
  • Extended support
    • Array, Function, Date, Map, Set, Buffer/Uint8Array, RegExp, NaN
  • Experimental support

Typed arrays are tested with ArrayBuffer.isView(), this is an experimental (under tested) feature of MapQL. See TypedArray for more information about typed arrays.

Example: MapQL.find()

const MapQL = new (require('mapql'))(),
    util = require('util'),
    _print = (obj) => {
        console.log('%s\n', util.inspect(obj, { depth: null, showHidden: true }));
    };

// Start out with some base data.
MapQL.set('test0', 10);
MapQL.set('test1', 'this is a string');
MapQL.set('test2',{
    foo: 7,
    bar: 3,
    baz: null,
});
MapQL.set('test11',{
    foo: 7,
    string: 'Look at me example all the things!'
});
MapQL.set('test12',{
    foo: 7,
    string: 'Another example string!',
    baz: 'qux'
});
MapQL.set('test13',{
    foo: 8,
    baz: 'qux'
});
// Fill with junk.
for (let num = 3; num < 10; num++) {
    MapQL.set(`test${num}`, {
       foo: Math.floor(Math.random()*15)+1,
       bar: Math.floor(Math.random()*15)+1
    });
}

// Sync!
_print(MapQL.find({
    foo: 8
}));
_print(MapQL.find({
    foo: { '$gt': 6 },
    bar: { '$lt': 10 }
}));
_print(MapQL.find({
   '$gt': 3
}));
_print(MapQL.find({
   '$eq': 'this is a string'
}));
_print(MapQL.find({
   string: { '$regex': /Things!$/i }
}));
_print(MapQL.find({
   '$regex': /String$/i
}));
_print(MapQL.find({
  '$and': [{
       foo: { '$eq': 7 },
    }, {
       '$or': [
           { string: { '$regex': /Things!$/i } },
           { string: { '$regex': /String!$/i } },
       ]
   }]
}));

// Promise!
MapQL.findAsync({ foo: { '$gt': 2 }, bar: { '$lt': 10 } }).then((results) => {
    _print(results);
 }).catch((error) => {
    console.log(error);
});

Example: MapQL.chain()

const MapQL = new (require('mapql/chainable'))(),
      util = require('util');
7
// Add some base data.
MapQL.set('testing0', {
   foo: 4,
   bar: 11
});
MapQL.set('testing1', {
   foo: 2,
   bar: 9
});
MapQL.set('testing2', {
   foo: 8,
   bar: 3
});
MapQL.set('testing3', {
   foo: 2,
   bar: 100
});

// Generate a basic chained query.
let $gt = MapQL.chain().gt('foo', 3);

// Generate a somewhat complex query for $or.
let $or = MapQL.chain().or((chain) => {
    return [
        chain.eq('foo', 4),
        chain.eq('foo', 2)
    ]
});

// Generate a more complex chained query for $and.
let $and = MapQL.chain().and((chain) => {
    return [
        chain.lt('foo', 5),
        chain.or(() => {
            return [
                chain.lt('bar', 10),
                chain.eq('bar', 100)
            ];
        })
    ];
});

// Execute $gt!
console.log('$gt query:\n%s\n', util.inspect($gt.query, { depth: null }));
console.log('$gt results:\n%s\n', util.inspect($gt.execute(), { depth: null }));

// Execute $or!
console.log('$or query:\n%s\n', util.inspect($or.query, { depth: null }));
console.log('$or results:\n%s\n', util.inspect($or.execute(), { depth: null }));

// Execute $and!
console.log('$and query:\n%s\n', util.inspect($and.query, { depth: null }));
console.log('$and results:\n%s\n', util.inspect($and.execute(), { depth: null }));

// List all entries.
console.log('entries:\n%s', util.inspect([...MapQL.entries()], { depth: null }));

Keywords

FAQs

Package last updated on 29 Jun 2017

Did you know?

Socket

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc