1.1.2 • Published 3 years ago

browsedb v1.1.2

Weekly downloads
-
License
GPL-3.0-or-later
Repository
github
Last release
3 years ago

npm.io npm.io npm.io

npm.io npm.io npm.io npm.io

Visit Site For more Docs

🔗Description

BrowseDB is a JavaScript clientside library for managing localStorage data in mongoose style. BrowseDB provides its users, methods for managing localStorage data efficiently. It can be used for simple CRUD operations. BrowseDB's data is stored in string format but all data operations are done in JSON format.

📕 Terminologies

Collections - All BrowseDB instances are called collections, as they are just collections(arrays) of objects(documents).

Documents - As you might have guessed, are simply objects.

Schema - A schema is simply an object that describes the expected structure or blueprint of documents of a particular collection. This could be used for some sort of type checking. It is optional.

⚙️Usage and Settings

First, to use browsedb. Include/import browsedb, then create an instance of browsedb. Example

    const schema = {
        text: {
            type: String,
            required: true
        },
        done: Boolean,
        date: {
            type: Number,
            required: true,
            default: Date.now
        }
    };
    const todos = new BrowseDB("todos", schema);

Methods

  • create - Used for creating documents. It accepts an object containing required data for object creation and returns a copy of the new document inserted into localStorage with its ID. BrowseDB generates a unique ID for the newly inserted document.
    todos.create({ text: "Learn BrowseDB", done: false });
  • find - For finding documents. It accepts two optional parameters: query and key. query is used in similar fashion to 'WHERE' in SQL like databases, While key is used for filtering results. Example
    todos.find(); // Returns all documents
    todos.find({}) // Returns all documents
    todos.find({ done: true }); // Returns all documents where done equal true
    todos.find({ done: false }, {done: 0, id: 0}); // Returns documents where done equal false but doesn't show done and id's of each document.
  • findById - For finding documents based on id. It accepts one parameter: id. id(string) represents id of a document. It returns a document with the passed id.
    todos.findById("zUVxUed827"); // Returns Document with id 'zUVxUed827'
  • update - For updating data in document(s). It accepts two parameters: query and data. Here, query is used as 'WHERE' would be used Relational databases, while data represents the new data to be put into selected documents. The below example will find all documents where done = false, and update the text field.
    todos.update({done: false}, {text: "Todo is not yet done"});
  • updateById - For updating data in a document based on id. It finds a document by id, updates its content and returns the updated content. It accepts two parameters: id and data.

  • updateAll - For updating all documents data at once. It accepts one parameter: data.

  • delete - Finds and deletes documents. Accepts one parameter: query - Where the delete operation should take place.

  • deleteById - Finds, deletes and returns a document with id passed to it. Accepts one parameter id.

  • deleteAll - Deletes all documents in a collection.

  • remove - This function is a bit similar in behaviour to delete.

Installation

Content Delivery Networks

CDN Link https://unpkg.com/browsedb@1.1.2/browsedb.min.js

HTML Tag

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

Using NPM

    npm install browsedb

⛏️Development

  • yarn build or npm run build - produces a production version of library under the lib folder

⭐️Show your support

Please star this repository if this project helped you!

👋 Contributing

Please read the CONTRIBUTING.md file to see how to contribute.

🌤️Browser compatibility

Browsedb works across all browsers that support localStorage. You could check for compatibility here: