1.5.0 • Published 6 years ago

lowdb-recursive v1.5.0

Weekly downloads
5
License
MIT
Repository
github
Last release
6 years ago

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()
1.5.0

6 years ago

1.0.7

10 years ago

1.0.6

10 years ago

1.0.5

10 years ago

1.0.4

10 years ago

1.0.3

10 years ago

1.0.2

10 years ago

1.0.1

10 years ago

1.0.0

10 years ago