Coder Social home page Coder Social logo

dataquery's Introduction

DataQuery

Forked the query language from Datascript, and changed to only utilize external indexes in an asynchronous manner.

To-Do

  • More documentation.
  • More examples.
  • More tests.

Usage

For instance, say you have a PouchDB database with two views, one called eav/eav and one called ave/ave. These views would have array keys, such as [entity,attribute,value] and [attribute,value,entity], respectively, and both (for ease in our example) would have values of [entity,attribute,value]. (Another way of thinking of these triples is [id,label,value].)

Then, you could query the database as follows:

var d = require( "dataquery" );
var PouchDB = require( "pouchdb" );
var db = new PouchDB( "dataquery" );

var searchPouchIndex = function( db, index ) {
  return function( search, callback ) {
    var view = index + "/" + index;
    var endkey = search.map( function( el ) {
      if ( el === null ) {
        return {};
      }
      return el;
    });
    db.query( view, {
      startkey: search,
      endkey: endkey
    }, function( error, data ) {
      callback( data.rows.map( function( el ) {
        return el.value;
      }) );
    })
  }
};

var initPouchDB = function() {
  return d.db( db, searchPouchIndex( db, "eav" ), searchPouchIndex( db, "ave" ) );
};

var datalog = initPouchDB();
d.q( '[:find ?id :in :where [?id "last_name" "benson"]]', function( data ) {
  console.log( "Query results: ", data );
}, datalog );

In fact, as long as you can provide functions to search the "eav" and "ave" indexes on any dataset, returning "eav" triples, you can use Dataquery to query those indexes. This should include in-memory indexes (though I'd suggest using Datascript as it has been optimized for that use-case), IndexedDB, or pretty much any persistent store that would allow you to define indexes as necessary.

Installation

npm install --save dataquery

Status

Quite alpha. Contributions/suggestions/constructive critique very welcome!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.