Skip to content

jinhduong/linq-fns

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

66 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

linq-fns

.NET LINQ functions for Javascript, written by TypeScript.

  • ⚑ Provide Queryable<T>, it's reusable, also variable and use Predicate collection for holding query and execute later.
  • πŸ”¨ Contains almost the original .NET and some extends methods.
  • πŸ”¨ Support Promise like as a input source.
  • πŸ™… All APIs like a Javascript native methods so easily, simply implementation.
  • πŸ“Š Includes some simple drivers. (like as firebase real db)
npm install linq-fns --save

This version just alpha so if have any problem, don't hesitate to let me know. πŸ‘‹

Browser client files at 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() // Here will return number, not Promise<number>
                }
            })
const asyncData = query.toList() // Will return Promise<{area:string, total:number}>
asyncData.then(data => {
    console.log(data);
    // [
    //     {area: 'Euro': total: 2},
    //     {area:'South Ameria', 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 postsQuery = new FireBaseQueryable(db,'<yourdb>.posts');

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

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

// WRITE DATA
// Just call not execute to server
postsQuery.add(item);
postsQuery.remove(item);
postsQuery.update(item);

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

localStogare

// Node
const LocalStorageQueryable = require('linq-fns').LocalStorageQueryable;

const postsQuery = new LocalStorageQueryable("posts");

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

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

gist file

//Node
const GistQueryable = require('linq-fns').GistQueryable;

const postsQuery = new GistQueryable(
    "6d183b7f997819cd5a8354f35c1e471f123", // gist file
    "259f97b96762c9d3a155630d12321fd1cfaf253ff", // access token
    "posts") // table name

postsQuery.add(item);
postsQuery.remove(item);
postsQuery.update(item);
postsQuery.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
  • ...

License

MIT License