lowdb-recursive

1.5.0 • Public • Published

lowdb-recursive

Build Status Dependencies DevDependencies Donate to help support Ghondar development

Quick dot-notation seeker

if you know for the first time lowdb, please go here

Add Documents

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

 
/*
  [ { 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

 
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

 
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

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

Dependencies (2)

Dev Dependencies (8)

Package Sidebar

Install

npm i lowdb-recursive

Weekly Downloads

7

Version

1.5.0

License

MIT

Unpacked Size

21.9 kB

Total Files

8

Last publish

Collaborators

  • ghondar