Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhduong committed Jun 28, 2018
1 parent 99be8bb commit c11ad68
Showing 1 changed file with 35 additions and 23 deletions.
58 changes: 35 additions & 23 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Browser client files can be found in the [release](https://github.com/jinhduong/
```ts
// ES6
import { Queryable } from 'linq-fns';

// ES5
const Queryable = require('linq-fns').Queryable;

Expand All @@ -30,10 +29,17 @@ let query = Queryable
.select(x => {
return {
area: x.key,
total: Queryable.fromSync(x.items).count() // This will return a number, not Promise<number>
total: Queryable.fromSync(x.items).count()
// This will return a number, not Promise<number>
}
})
const asyncData = query.toList() // Will return Promise<{area:string, total: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);
// [
Expand All @@ -55,23 +61,29 @@ admin.initializeApp({
});

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

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

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

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

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

```

Expand All @@ -80,33 +92,30 @@ postsQuery.commitChanges();

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

const postsQuery = new LocalStorageQueryable("posts");

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

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

#### gist file
```js

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

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

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

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

### Process
Expand Down Expand Up @@ -155,6 +164,9 @@ postsQuery.commitChanges();
- [x] Gists Github : `Node` & `Browser`
- [ ] ...

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

### License

[MIT License](http:https://opensource.org/licenses/MIT)

0 comments on commit c11ad68

Please sign in to comment.