sarala
Version:
Javascript library to communicate with RESTful API built following JSON API specification. inspired by Laravel’s Eloquent.
54 lines (39 loc) • 1.07 kB
Markdown
---
sidebarDepth: 0
---
As there are many collection javascript libraries out there, Sarala does not wrap collection object data with another library. But it is very easy to wrap collection object data with your favorite library by overriding `newCollection` method.
```javascript
import { Model } from 'sarala'
import collect from 'collect.js'
export default class BaseModel extends Model
{
...
newCollection (data) {
return collect(data)
}
}
```
```javascript
const user = new User()
let users = await user.all()
let youngest = user.data.sortBy('age').first()
```
```javascript
import { Model } from 'sarala'
import _ from 'lodash'
export default class BaseModel extends Model
{
...
newCollection (data) {
return _.chain(data)
}
}
```
```javascript
const user = new User()
let users = await user.all()
let youngest = user.data.sortBy('age').head().value()
```