πŸ‘΄ LINQ for Javascript, written by TypeScript
Branch: master
Clone or download
Latest commit d150c5b Oct 9, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.vscode Features: Apr 25, 2018
demo Fixes and update somethings Apr 25, 2018
docs Update docs Apr 23, 2018
release Release alpha.5 Apr 30, 2018
src Fixed typo in 'gist' Sep 22, 2018
test Features: Apr 25, 2018
.gitignore Update gitigore Apr 28, 2018
CODE_OF_CONDUCT.md
LICENSE Initial commit Apr 18, 2018
README.md Update README.md Jun 29, 2018
gulpfile.js Firebase real database driver Apr 26, 2018
package-lock.json
package.json Add localStogare and gist drivers Apr 30, 2018
rollup.config.js Some updates Apr 27, 2018
tsconfig.json Release alpha.5 Apr 30, 2018
webpack.config.js

README.md

linq-fns

.NET LINQ functions for JavaScript written in TypeScript.

  • ⚑ Provides Queryable<T>,which is reusable, variable and uses a predicate collection for deferred execution.
  • πŸ”¨ Contains most of the original .NET methods and some additional methods.
  • πŸ”¨ Supports Promise as an input source.
  • πŸ™… All APIs are JavaScript native methods so can be easily incorporated into existing JavaScript projects.
  • πŸ“Š Includes some simple drivers (such as Firebase Realtime database).
npm install linq-fns --save

Browser client files can be found in the release folder.

Basic example

Node or browser

// ES6
import { Queryable } from 'linq-fns';
// ES5
const Queryable = require('linq-fns').Queryable;

let query = Queryable
            .from(nations)
            .join(continents, (x, y) => x.areaId === y.id)
            .groupBy(o => o.y.areaName)
            .select(x => {
                return {
                    area: x.key,
                    total: Queryable.fromSync(x.items).count() 
                    // This will return a number, not Promise<number>
                }
            })

// Async/ await
const data = await query.toList();

// Promise
// Will return Promise<{area:string, total:number}>
const asyncData = query.toList(); 
asyncData.then(data => {
    console.log(data);
    // [
    //     {area: 'Euro': total: 2},
    //     {area:'South America', total: 1}
    // ]
});

Firebase

const FireBaseQueryable = require('linq-fns').FireBaseQueryable;
const admin = require('firebase-admin');
const serviceAccount = require('./serviceAccountKey');

admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: 'https://xxx.firebaseio.com'
});

const db = admin.database();
const postsRepo = new FireBaseQueryable(db,'<yourdb>.posts');

// READ AND QUERY DATA
// ES5 Promise
postsRepo.getQuery()
    .where('...')
    .select('...')
    .toList().then(x=>'...');

// Async/await
const data = await postsRepo.getQuery()
                            .where('...')
                            .select('...')
                            .toList();

// WRITE DATA
// Prepare calls, but do not send requests to server
postsRepo.add(item);
postsRepo.remove(item);
postsRepo.update(item);

// Call this to execute 3 above methods
postsRepo.commitChanges();

localStorage

// Node
const LocalStorageQueryable = require('linq-fns').LocalStorageQueryable;
const postsRepo = new LocalStorageQueryable("posts");

postsRepo.add(item);
postsRepo.remove(item);
postsRepo.update(item);

// Call this to execute 3 above methods
postsRepo.commitChanges();

gist file

//Node
const GistQueryable = require('linq-fns').GistQueryable;
const postsRepo = new GistQueryable(
    "6d183b7f997819cd5a8354f35c1e471f123", // gist file
    "259f97b96762c9d3a155630d12321fd1cfaf253ff", // access token
    "posts") // table name

postsRepo.add(item);
postsRepo.remove(item);
postsRepo.update(item);
postsRepo.commitChanges();

Process

1.Methods

  • from
  • where
  • select
  • selectMany
  • join
  • leftJoin
  • groupJoin
  • orderBy
  • orderByDescending
  • take
  • takeWhile
  • skip
  • skipWhile
  • groupBy
  • distinct
  • concat
  • zip
  • union
  • intersect
  • except
  • first : Promise<T>
  • firstOrDefault : Promise<T | null>
  • last : Promise<T>
  • lastOrDefault : Promise<T | null>
  • single
  • singleOrDefault
  • contains
  • sequenceEqual
  • any : Promise<boolean>
  • all : Promise<boolean>
  • count : Promise<number>
  • min : Promise<number>
  • max : Promise<number>
  • sum : Promise<number>
  • average
  • aggregate
  • toList : Promise<T[]>

2. Drivers

  • Firebase : Node
  • Localstorage : Node & Browser
  • Gists Github : Node & Browser
  • ...

Documents

https://github.com/jinhduong/linq-fns/tree/docs

License

MIT License