Skip to content

Commit

Permalink
Added more feature info to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
TekuConcept committed May 1, 2024
1 parent dda9058 commit a7053bd
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ $ npm install casl-bridge



## Example
## Examples

A simple demonstration...

Expand Down Expand Up @@ -61,25 +61,48 @@ const ids = await bridge
* select specific fields
*/

const select = ['id', 'title', ['author', ['name']]]
const names = await bridge
.createQueryTo('read', 'Book', [
'title',
[ 'author', [ 'name' ] ]
])
.createQueryTo('read', 'Book', select)
.limit(3)
.getMany()

/* --------------------------------------
* add extra mongo-like query filters
*/

const names = await bridge
.createQueryTo('read', 'Book', [
'title',
[ 'author', [ 'name' ] ]
], { id: { $ge: 10, $le: 20 } })
const filter = { id: { $ge: 10, $le: 20 } }
const limited = await bridge
.createQueryTo('read', 'Book', select, filter)
.limit(3)
.getMany()

/* --------------------------------------
* using just the filter feature
*/

const filtered = await bridge
.createFilterFor('Book', {
'author.name': 'Jane Austen',
id: { $in: [2, 3, 5] },
})
.getMany()

/* --------------------------------------
* [experimental] apply filter to query
*/

const query = bookRepo
.createQueryBuilder('book')
.leftJoin('book.author', 'author')
.where('book.id > :bookId', { bookId: 3 })

bridge.applyFilterTo(query, 'author', {
name: 'Jane Austen'
})

const moreBooks = await query.getOne()

```

### Database Setup
Expand Down

0 comments on commit a7053bd

Please sign in to comment.