eloquent-js
Version:
JSON Query Builder
54 lines (34 loc) • 1.32 kB
Markdown
This library help us to execute queries on json files in simplest posible way.
After install:
import DB from "../assets/data/countries.json";
import {EloquentJS} from '../../node_modules/eloquent-js/EloquentJS';
export class Country extends EloquentJS {
JSONFile = DB;
statesOf(CountryName) {
let result = this.query('name', CountryName).states;
return result;
}
}
const country = new Country();
let cities = country
.where('name', 'Iran')
.pluck('states')
.andWhere('name', 'Tehran')
.pluck('cities')
.get();
- all() // return JsonFile as an object.
- where(key, value)
- pluck(field) // pick a part of current query result.
- andWhwre(key, value) // apllay another where statement to current query.
- get() // execute and return final query result.
- etc ...