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; // Configure the primary keyDB; // Set the collection's datalet people = id: 1 name: "Kash" color: "red" id: 2 name: "Sanjna" color: "red" id: 3 name: "Saily" color: "purple" ;DB; // Find a record by primary key// returns { id: 1 name: "Kash", color: "red" }DB; // Find a record by property value// returns { id: 2, name: "Sanjna", color: "red" }DB; // 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;// 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;// 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; // Remove a recordDB; // Remove a record by primary keyDB;DB; // Get all recordsDBall; // Get the number of recordsDB;