New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

db-js

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

db-js

Efficient collection querying interface.

latest
Source
npmnpm
Version
1.3.0
Version published
Maintainers
1
Created
Source

DB.js

API

Methods acting on multiple records (as opposed to a single record, like #find) support method chaining and will only be lazily evaluated until #valueOf() is called.

Otherwise, to maintain consistency, call #valueOf() on #find.

// Initialize or fetch a collection.
// Collections inherit from EventEmitter, so all EventEmitter methods will work.
DB.collection('people');

// Configure the primary key
DB.collection('people').configure((options) => {
  options.pkey = 'id';
});

// Set the collection's data
let people = [
  { id: 1, name: "Kash", color: "red" },
  { id: 2, name: "Sanjna", color: "red" },
  { id: 3, name: "Saily", color: "purple" }
];
DB.collection('people').set(people);

// Find a record by primary key
// returns { id: 1 name: "Kash", color: "red" }
DB.collection('people').find(1).valueOf();

// Find a record by property value
// returns { id: 2, name: "Sanjna", color: "red" }
DB.collection('people').findBy({ name: "Sanjna" }).valueOf();

// Run a where-like query
// returns [
//   { id: 1, name: "Kash", color: "red" },
//   { id: 2, name: "Sanjna", color: "red" },
//   { id: 3, name: "Saily", color: "purple" }
// ]
DB.collection('people').where({ color: "red" }).valueOf();
// The #whereNot method is also available, where records that
// match the predicate are filtered out.

// Add a record. Will fail (and return undefined) if a record with
// the same primary key already exists.
DB.collection('people').add({ id: 1, name: "Saily", color: "purple" });
// The above will fail since a record with id 1 already exists.

// Update an already-persisted record or save it as a new record.
// This only overwrites the specified properties. Aliased as `#save()`
DB.collection('people').update({ id: 2, color: "yellow" });

// Remove a record
DB.collection('people').remove({ id: 2 });

// Remove a record by primary key
DB.collection('people').destroy(1);
DB.collection('people').destroy(3);

// Get all records
DB.collection('people').all().valueOf();

// Get the number of records
DB.collection('people').count().valueOf();

Keywords

DB

FAQs

Package last updated on 12 Apr 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts