Intro


BrowseDB is a javascript client side library for managing localStorage data mongoose style. BrowseDB provides it's users methods for managing localStorage data efficiently. It can be used for simple CRUD operations. BrowseDB data is stored in string format but all data operations are done in json format.

Getting Starting


It's really simple to get started with BrowseDB.

const notes = new BrowseDB("notes");

notes.create({text: "BrowseDB is awesome!"}); // Creates a new Document

Installation


Using NPM

$ npm install browsedb

CDN Link

<script src="https://unpkg.com/browsedb@1.0.0/browsedb.min.js"></script>

Docs


BrowseDB v1 includes several functions for handling localStorage data. These will be discussed in the below.


BrowseDB.prototype.create

This method is used for creating documents. It acccepts two parameters: data(required) and schema(optional). Data represents data to be stored in localStorage, while schema reperesents a structure or blueprint which each document should follow. Note: Schema is optional so BrowseDB will check for schema, if schema is present it checks data attribute against schema for correctness. This helps for maintaining data integrity.


BrowseDB.prototype.find

This method is dedicated to finding documents. It accepts two optional parameters: query and key. If query is not present or is empty it returns all documents. The query object works like SQL's 'WHERE' statement. The key parameter is also an object. It dictates which field in the each found document will be shown.


BrowseDB.prototype.findById

This method works like the find method except that it finds a document based on the documents id. It accepts one required parameter: data(represents the document ID).


BrowseDB.prototype.update

The update method is used for updating documents. It accepts two parameters: query and data. The query object works like a SQL's WHERE statement. While data object represents the data used for updating the document(s).


BrowseDB.prototype.updateById

The updateById method will update a documents provided document with the id exists. It accepts two required parameters: id and data. The id parameter is expected to be a string and represents the id of the document to be updated. The data parameter is expected to be an object containing changes to the document.


BrowseDB.prototype.updateAll

The updateAll method will update all documents in a collection. It accepts only one parameter: data. The 'data' parameter is expected to be an object holding values for changes.


BrowseDB.prototype.delete

This method works like the find method only that it deletes the found data. It accepts only one optional parameter, used for filter data


BrowseDB.prototype.deleteById

This method is used to delete a document provided the ID matches the document's ID. It accepts one parameter: id(this represents a documents id, which is deleted if found).


BrowseDB.prototype.deleteAll

The deleteAll method accepts no parameter and simply clears the database(localStorage).


BrowseDB.prototype.remove

This is a very similar variant of delete.

Try it out



{}