Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/ghondar/lowdb-recursive

Flat JSON file database recursive
https://github.com/ghondar/lowdb-recursive

Last synced: about 2 months ago
JSON representation

Flat JSON file database recursive

Awesome Lists containing this project

README

        

# lowdb-recursive

[![Build Status](https://travis-ci.org/ghondar/lowdb-recursive.svg?branch=master)](https://travis-ci.org/ghondar/lowdb-recursive)
[![Dependencies](https://david-dm.org/Ghondar/lowdb-recursive.svg?style=flat-square)](https://david-dm.org/Ghondar/lowdb-recursive)
[![DevDependencies](https://david-dm.org/Ghondar/lowdb-recursive/dev-status.svg?style=flat-square)](https://david-dm.org/Ghondar/lowdb-recursive#info=devDependencies&view=list)
[![Donate to help support Ghondar development](https://img.shields.io/gratipay/ghondar.svg?style=flat)](https://www.gittip.com/ghondar/)

> Quick dot-notation seeker

if you know for the first time lowdb, please go [here](https://github.com/typicode/lowdb)

## Add Documents

```javascript
var low = require('lowdb-recursive')

var db = low('db.json')

var collection = [
{
"nombre": "Villareal",
"numero": 1,
"carreras": [
{
"nombre": "Fisico",
"rating": 4.3,
"cursos": [
{
"nombre": "cuantica",
"id": 1
},
{
"nombre": "algebra",
"id": 2
}
]
},
{
"nombre": "Matematica",
"rating": 4,
"cursos": [
{
"nombre": "algebra",
"id": 2
},
{
"nombre": "Aritmetica",
"id": 3
}
]
}
]
},
{
"nombre": "San Marcos",
"numero": 2,
"carreras": [
{
"nombre": "Medicina",
"rating": 9.6,
"cursos": [
{
"nombre": "Quimica",
"id": 4
},
{
"nombre": "Biologia",
"id": 5
}
]
},
{
"nombre": "Metalurgia",
"rating": 5,
"cursos": [
{
"nombre": "quimica",
"id": 4
},
{
"nombre": "Fisica",
"id": 5
}
]
}
]
}
]

collection.forEach(function(document){
db.get('universidades').push(document).write();
});

```
## Find

```javascript

/*
[ { nombre: 'Villareal',
numero: 1,
carreras: [ [Object], [Object] ] } ]
*/

db.get('universidades').whereAll({ 'carreras.cursos.nombre': 'cuantica'})

//or
/*
[ { nombre: 'cuantica', id: 1 } ]
*/

db.get('universidades').findAll({ 'carreras.cursos.nombre': 'cuantica'})

```

## Update and get values

```javascript

db.get('universidades')
.chain()
.updateAll({'carreras.cursos.nombre': 'cuantica'}, {'nombre': 'mecanica'})
.write()
.value()

//or
db.get('universidades')
.chain()
.findAll('carreras.cursos.nombre': 'cuantica')
.updateAll({'nombre': 'mecanica'})
.write()
.value()

```
## Push value

```javascript

db.get('universidades')
.chain()
.pushAll({'carreras.cursos.nombre': 'cuantica'}, {'nombre': 'javascript', 'id': 100})
.write()
.value()

//or
db.get('universidades')
.chain()
.findAll({"carreras.rating": 4.3})
.pushAll({"cursos": {'nombre': 'javascript', 'id': 100})
.write()
.value()

```

## Remove value

```javascript

db.get('universidades')
.chain()
.removeAll({'carreras.cursos.nombre': 'cuantica'})
.write()
.value()

```