npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

batoh

v0.0.4

Published

IndexedDB wrapper.

Downloads

2

Readme

##Batoh.js

Wrapper for IndexedDB API makes common operations simple and does not hide the original API, unifies the error handling using NodeJS callback convetions.

Optional Backbone to IndexedDB sync replacement included.

npm install batoh

###Usage:

setup: {
  database: 'Batoh',
  version: 1,
  stores: {
    trustyPocket: {
      keyPath: things,
      autoIncrement: true,
      indexes: [
        {
          name: 'food',
          keyPath: '',
          unique: true,
          multiEntry: false
        }
      ]
    }
    hiddenPocket: {
      keyPath: null,
      autoIncrement: true,
      indexes: []
    }
  }
}
var db = new Batoh.Database(setup);
db.[method](store, [params], function(err, result) {
  // shuffle more
});

More usage examples can be also found in tests.

###Build: Only base wrapper is included by default in dist/ directory. To include extras in the build you need to have gulp installed and run command

gulp dist --backbone

Options:

--backbone adds Batoh.backboneSync module.

#####Batoh.backboneSync(method, object, options) Can be used to replace Backbone.sync, adds UUID attribute as an ID. It is needed to be done specifically:

Backbone.sync = Batoh.backboneSync;

Can only fetch a collection.

Model PATCH operation is not supported.

#####Batoh.sync(store, setup, options) Simple server synchronization with assumptions. This module is going to be removed in future.

###API:

#####Batoh

Top-level namespace, global object.

#####Batoh.Database(setup)

Constructor, accepts a setup object.

#####Database.open(callback)

Open or create the database specified in setup passed to the constructor.

callback gets one argument (err), if there is no error err is null.

Example:

db.open(function() {
  db.[method](store, [params], function(err, result) {
    // shuffle more
  });
});

#####Database.close()

Always have to close the database in callback after the last operation in chain.

Example:

db.[method](store, [params], function(err, result) {
  db.close();
});

#####Database.destroy(callback)

Delete the database. Once the operation is successful callback is invoked.

callback gets one argument (err), if there is no error err is null.

Example:

db.destroy(function(err, result) {
  // database doesn't exist anymore
});

#####Database.add(store, value, [key], callback)

Add one or more records. If record already exist in object store, returns an Error.

store String, name of them object store to use.

value Object or an Array of objects to store.

key String or an Array of strings, as a keys for the values. If an Array is passed indexes have to be corresponding to the indexes in values Array.

callback Function gets two arguments (err, result), if there is no Error err is null. result is always an Array of keys of the values added.

Example:

#####Database.put(store, value, [key], callback)

Put one or more records, updating existing or creating a new one.

store String, name of them object store to use.

value Object or an Array of objects to be stored.

key Key or an Array of keys for the values, if an Array is passed indexes have to be corresponding to the indexes in values Array.

callback Function, gets two arguments (err, result), if there is no Error err is null. result is always an Array of keys of the values put.

Example:

#####Database.get(store, key, callback)

Retrieve one or more records specified by the key.

store String, name of the object store to use.

key String, key that identifies the record to be retrieved.

callback Function, gets two arguments (err, result), if there is no Error err is null. result is always an Array of the retrieved objects.

Example:

#####Database.delete(store, key, callback)

Delete one or more records specified by the key.

store String, name of the object store to use.

key String, key that identifies the record to be deleted.

callback Function, gets two arguments (err, result), if there is no Error err is null. result is always an Array of the results of delete operations undefined.

Example:

#####Database.query(store, [query], [each], callback)

Open a cursor and query the object store.

store string, name of the object store to use.

query configuration Object defining the query, with following options:

query.index index to use, if omitted cursor is opened on the key path of the store.

query.range IDBKeyRange Object defining the range.

query.direction direction to move the cursor, next, prev, nextunique, preunique.

query.limit Number of records to retrieve.

each Function, operation to be called on each cursor value.

callback Function, gets two arguments (err, result), if there is no Error err is null. result is an Array of records, returned b

If query and each are not passed returns all records from the object store.

Example:

For query parameter examlpe look on getLastSync from sync.js.

For each parameter example look on getDirtyRecords from sync.js.

#####Database.count(store, callback)

Count the objects in the store.

store String, name of the object store to count.

callback Function, gets one argument (err), if there is no error err is null.

Example:

#####Database.clear(store, callback)

Delete all records in the object store.

store String, name of object store to clear.

callback Function, gets one argument (err), if there is no error err is null.

Example:

###TODO: more tests

examples/

#####Why the name? A rucksack.