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.3
  • 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.

Browser Support

Currently only supports browsers with ES6 Map(), Classes and Arrow features/functions.

<!-- MapQL() WITHOUT chain() support -->
<script src="./dist/MapQL.es6.js"></script>
<!-- MapQL() WITH chain() support -->
<script src="./dist/MapQL.es6.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

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 19 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