Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

@nelson_echeverria/pandadb

nelEcheverria0133MIT1.0.5

pandadb is a local document-oriented JSON database, ready to be implemented in an application in a simple way

JSON, db, database, JSON database, lowdb, local db, local, mql, MQL, local database, pandadb, panda, panda database

readme

pandadb

pandadb is a local document-oriented JSON database, ready to be implemented in an application in a simple way.

it is worth mentioning that the author of panda db was inspired by other packages to develop pandadb, such as lowdb, taffydb among others.

JavaScript Style Guide NPM Version NPM Downloads License: MIT

introduction

pandadb is a local JSON database, which uses a JSON file locally to persist the data, which is managed in a specific application, as a JSON format is used, pandadb uses MQL as a syntax to perform queries, which makes queries more intuitive and friendly to end customers.

example of an MQL query

// should return the element that has the property 'foo', with the value of 'bar'
{ "foo": "bar" }

installation

npm i --save-exact pandadb

usage

[!NOTE] If you do not pass a file name to the PandaDB instance, it will create a JSON file called 'pandadb.json' by default. `js const PandaDB = require('pandadb') const db = new PandaDB('NBA.json') //

const players = db.collection('players')

players.createMany([ { name: 'Michael Jordan', team: 'Chicago Bulls', shirtNumber: 23 }, { name: 'Lebron James', team: 'Leakers', shirtNumber: 23 }, { name: 'Kyle Irving', team: 'Celtics', shirtNumber: 11 } ]).then(() => console.log('data was created successfully'))

players.find({ shirtNumber: 11 }).then(player => console.log(here is kyle irving \n ${player}))


# API

All of the following methods listed are available when creating a collection with the 'collection()' method.

- `list` 
obtains/lists all the data of the collection in question
```js
players.list().then(console.log)
  • create creates and automatically inserts an id - UUID for subsequent persistence `js const MJ = { name: 'Michael Jordan', team: 'Chicago Bulls', shirtNumber: 23 }

players.create(MJ) .then(response => console.log(response)) // { status: 'success', collection: 'players', createdItems: 1 }

- `createMany` creates/saves a data set within a collection
```js
players.createMany([
    {
        name: 'Michael Jordan',
        team: 'Chicago Bulls',
        shirtNumber: 23
    },
    {
        name: 'Lebron James',
        team: 'Leakers',
        shirtNumber: 23
    },
    {
        name: 'Kyle Irving',
        team: 'Celtics',
        shirtNumber: 11
    }
]).then(response => console.log(response)) // { status: 'success', collection: 'players', createdItems: 3 }
  • find returns the first element that matches the query
    players.find({ team: 'Celtics' }).then(player => console.log('here is Kyle Irving \n', player))
  • findMany will recover all the data that matches the query made
    players.findMany({ shirtNumber: 23 }).then(players => console.log('the basketball gods:', players))
  • edit edit the first element that matches the query
    players.edit({ name: 'Michael Jordan' }, { retired: true })
         .then(response => console.log(response)) // { status: 'success', collection: 'players', updatedItems: 1 }
  • editMany edit all the elements of a collection that match the query made
    players.editMany({ shirtNumber: 23 }, { level: 'god' })
         .then(response => console.log(response)) // { status: 'success', collection: 'players', updatedItems: 2 }
  • remove removes from the collection the first element of the collection that matches the query
    players.remove({ shirtNumber: 11 })
         .then(response => console.log(response)) // { status: 'success', collection: 'players', removedItems: 1 }
  • removeMany removes all elements from the collection that match the query
    players.removeMany({})
         .then(response => console.log(response)) // { status: 'success', collection: 'players', removedItems: 3 }
  • destroy destroys/removes the collection from which it is called.

    [!IMPORTANT] the methods can still be accessed, but they will have no effect

    players.destroy().then(() => console.log('the players collection was eliminated'))
    players.list() // undefined

license

pandadb is under the MIT license