Coder Social home page Coder Social logo

brainstormingtrooper / jinqjs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from fordth/jinqjs

0.0 1.0 0.0 299 KB

jinqJs provides a simple way to perform SQL like queries on javaScript arrays, collections and web services using LINQ expressions.

License: Other

JavaScript 95.06% HTML 0.06% TypeScript 4.88%

jinqjs's Introduction

jinqJs

jinqJs provides a simple, leightweight & fast way to perform queries, updates and deletes on javaScript arrays, collections and web services using LINQ expressions. You can visit the jinqJs.com for more examples and demos.

TypeScript Support

Include the definition file jinqJs.d.ts

Unit Tested

All stable versions have had a 100% success rate with all 80+ unit tests.

Online Detailed API Documentation With Examples of Every Function

The full API documentation can be found here

Installing via the NuGet Package

You can start using jinqJs by simply using the NuGet package manager.

Install-Package jinqJs

Installing the jinq module by running:

npm install -g jinq

Installing jinqJs via Bower

bower install jinqjs

Extensibility

jinqJs has a simple plug-in architecture which allows you to simply add your own functions to the jinqJs library without modifying any of the base library code. View the online documentation Extensibility section for more information.

Node.js

As of version 1.3+ jinqJs is Node.js ready. You load the jinqJs module in Node.js via the following:

var jinqJs = require('jinq');

Angular 1.x Service

If angular 1.x is loaded then jinqJs is available as a service in the module 'angular-jinqjs':

angular.module('app', ['angular-jinqjs']).controller('demoCtrl', ['$jinqJs', function ($jinqJs) { 
    var result = $jinqJs.from(data).select();
}]);

Perform RUD Operations

Starting in version 1.5.1 you can perform update and delete operations.

Examples

Joining Results With A Web Service Response And A Collection

var people = [{Name: 'Tom', Age: 15, Location: 'Port Jefferson'},
                {Name: 'Jen', Age: 30, Location: 'Huntington'},
                {Name: 'Diana', Age: 5, Location: 'Huntington'}];
                
/* WEB SERVICE TO QUERY */
var weatherSvc = 'http://api.openweathermap.org/data/2.5/weather?q=Huntington,NY';
/* Sample use of a .select() predicate to flatten result */ 
/* Calling a web service to query the response           */
var weather = new jinqJs()
                .from(weatherSvc)
                .select( function(row){
                    return { Location: row.name, Condition: row.weather[0].description };
                });
                    
/* Performs a join on the web service response and local collection */
var result = new jinqJs()
                .from(people)
                .where( function(row) { return (row.Age > 3 && row.Location == 'Huntington'); } )
                .leftJoin(weather).on('Location')
                .groupBy('Huntington', 'Condition').avg('Age')
                .select([{field: 'Location'}, {field: 'Age', text: 'Average Age'}, {field: 'Condition'}]);
RESULT
|  Location  | Average Age |     Condition |
|:----------:|:-----------:|--------------:|
| Huntington |     17.5    | Partly Cloudy |

Performing An Asynchronous Web Service Call

new jinqJs()
    .from('http://www.telize.com/geoip',
        function(self) {
        var result = self
                        .top(1)
                        .select('city', 'region');
        }
    );
RESULT
|     city    |  region  |
|:-----------:|:--------:|
| Stony Brook | New York |

Using Predicates For Complex Outer Join & Where Condition

var people = [
              {Name: 'Jane', Age: 20, Location: 'Smithtown'},
              {Name: 'Ken', Age: 57, Location: 'Islip'},
              {Name: 'Tom', Age: 10, Location: 'Islip'}
            ];

var population = [
              {Location: 'Islip', People: 123},
              {Location: 'Melville', People: 332},
            ];
                                        
var result = new jinqJs()
    .from(people)
    .leftJoin(population)
      .on( function( left, right ) {
        return (left.Location === right.Location);
      } )
    .where( function(row) {
      return ( row.Age > 15);
    })
    .select('Name', 'Location', 'People');
RESULT
| Name |  Location | People |
|:----:|:---------:|--------|
| Jane | Smithtown |        |
| Ken  | Islip     |        |

Creating Calculated Columns

function isChild(row) {
  return (row.Age < 18 ? 'Yes' : 'No');
}
var people = [
              {Name: 'Jane', Age: 20, Location: 'Smithtown'},
              {Name: 'Ken', Age: 57, Location: 'Islip'},
              {Name: 'Tom', Age: 10, Location: 'Islip'}
            ];
                        
var result = new jinqJs()
    .from(people)
    .orderBy('Age')
    .select([{field: 'Name'}, 
            {field: 'Age', text: 'Your Age'}, 
            {text: 'Is Child', value: isChild}]);
}]);
RESULT
| Name | Your Age | Is Child |
|:----:|:--------:|----------|
| Tom  |    10    |    Yes   |
| Jane |    20    |    No    |
| Ken  |    57    |    No    |

Folder Structure

jinqJs/
├── demo/           <-- Demo code using angularJs to demonstrate some LINQ queries
│   ├── index.html
│   ├── README.md
│   ├── script.js
├── versions/           <-- A history of versions
│   ├── v.0.1
│   └── v.x.x
├── tests/              <-- Unit test using jasmine JS
│   └── index.html      <-- Home page for unit test results
├── jinqjs-unstable.js  <-- Current work in progress version
├── jinqjs.js           <-- Will always be the latest stable version
├── jinsjs.min.js       <-- Latest minified stable version
├── LICENSE
└── README.md

Bugs and Feature Requests

For comments, bugs or feature requests you can open an issue at New Issue.

Copyright and License

Code is released under the MIT license

jinqjs's People

Contributors

fordth avatar svenschoenung avatar

Watchers

James Cloos avatar

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.