Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jinhduong/linq-fns
👴 LINQ for Javascript, written by TypeScript
https://github.com/jinhduong/linq-fns
firebase gist javascript linq typescript
Last synced: about 2 months ago
JSON representation
👴 LINQ for Javascript, written by TypeScript
- Host: GitHub
- URL: https://github.com/jinhduong/linq-fns
- Owner: jinhduong
- License: mit
- Created: 2018-04-18T06:56:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T11:24:16.000Z (almost 2 years ago)
- Last Synced: 2024-10-13T13:22:21.393Z (2 months ago)
- Topics: firebase, gist, javascript, linq, typescript
- Language: TypeScript
- Homepage:
- Size: 1.03 MB
- Stars: 72
- Watchers: 9
- Forks: 2
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# linq-fns
.NET LINQ functions for JavaScript written in TypeScript.
- âš¡ Provides `Queryable`,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`).```js
npm install linq-fns --save
```Browser client files can be found in the [release](https://github.com/jinhduong/linq-fns/tree/master/release) folder.
### Basic example
#### Node or browser
```ts
// 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
}
})// 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
``` ts
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,'.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
```js// 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
```js//Node
const GistQueryable = require('linq-fns').GistQueryable;
const postsRepo = new GistQueryable(
"6d183b7f997819cd5a8354f35c1e471f123", // gist file
"259f97b96762c9d3a155630d12321fd1cfaf253ff", // access token
"posts") // table namepostsRepo.add(item);
postsRepo.remove(item);
postsRepo.update(item);
postsRepo.commitChanges();
```### Process
#### 1.Methods
- [x] from
- [x] where
- [x] select
- [x] selectMany
- [x] join
- [x] leftJoin
- [x] groupJoin
- [x] orderBy
- [x] orderByDescending
- [x] take
- [x] takeWhile
- [x] skip
- [x] skipWhile
- [x] groupBy
- [x] distinct
- [x] concat
- [x] zip
- [x] union
- [x] intersect
- [x] except
- [x] first : `Promise`
- [x] firstOrDefault : `Promise`
- [x] last : `Promise`
- [x] lastOrDefault : `Promise`
- [x] single
- [x] singleOrDefault
- [x] contains
- [x] sequenceEqual
- [x] any : `Promise`
- [x] all : `Promise`
- [x] count : `Promise`
- [x] min : `Promise`
- [x] max : `Promise`
- [x] sum : `Promise`
- [x] average
- [x] aggregate
- [x] toList : `Promise`#### 2. Drivers
- [x] Firebase : `Node`
- [x] Localstorage : `Node` & `Browser`
- [x] Gists Github : `Node` & `Browser`
- [ ] ...### Documents
https://github.com/jinhduong/linq-fns/tree/docs### License
[MIT License](http://opensource.org/licenses/MIT)