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

storage-js

v1.0.3

Published

Storage-JS is a database menagement for localStorage. You can store data on local storage easily and APIs like Yii Framework AR

Downloads

5

Readme

Storage-JS

Storage-JS is a database menagement for localStorage. You can store data on local storage easily and APIs like Yii Framework AR.

Install

Bower

bower install storage-js --save

NPM

npm install storage-js --save

or download here

<script type="text/javascript" src="path/to/storage-js/storage.js"></script>

Define

NodeJS

var storagejs = require('storage-js');

RequireJS

define([
	'/bower_components/storage-js/storage.js'
], function(storagejs) {
	// your code
});

or global variable name 'storagejs'

Callback

Callback Async

storagejs('tableName').yourMethod(your_arguments, function(err, result) {
	// all method use this callback format (err, result)
	// for check error
	if (err === null) {
		// not error
	} else {
		console.log(err) // error message
	}
});

Callback Sync

  • all method for Reading Record, return result data
  • all method for Create, Update, Delete Record, return error message
var result = storagejs('tableName').all();
console.log(result)

var error = storagejs('tableName').insert({_id: 1, name: 'Storage JS'});
if (error === null) {
	alert('success')
} else {
	alert(error);
}

Quick Start

All method support Sync and Async. for example, this use Async method.

table require id for primary key, default attribute name '_id'

Creating Record

  • insert(id, object)
  • insert(object)
  • batchInsert(object)

Insert record

var attr = {
	name: 'Dida Nurwanda',
	age: 23,
	city: 'Pandeglang'
}
storagejs('tableName').insert('dida', attr, function(err, result) {
	if (err === null) {
		// your code
	}
});

or

var attr = {
	_id: 'dida',
	name: 'Dida Nurwanda',
	age: 23,
	city: 'Pandeglang'
}
storagejs('tableName').insert(attr, function(err, result) {
	if (err === null) {
		// your code
	}
});

Insert multiple record

var attrs = [
    {
    	_id: 'dida',
    	name: 'Dida Nurwanda',
    	age: 23,
    	city: 'Pandeglang'
    },
    {
    	_id: 'septi',
    	name: 'Siwi Septi Hastuti',
    	age: 11,
    	city: 'Pandeglang'
    }
]
storagejs('tableName').batchInsert(attrs, function(err, result) {
	if (err === null) {
		// your code
	}
});

Reading Record

  • all()
  • findById(id)
  • findIndexById(id)
  • findByAttribute(key, value)
  • findByAttributes(object)
  • findAllByAttribute(key, value)
  • findAllByAttributes(object)
  • findAll(object)

Get all record

storagejs('tableName').all(function(err, result) {
	if (err === null) {
		console.log(result)
	}
});

Find record by ID

storagejs('tableName').findById('dida', function(err, result) {
	if (err === null) {
		console.log(result)
	}
});

Find the first row satisfying the specified condition

storagejs('tableName').findByAttribute('_id', 'dida', function(err, result) {
	if (err === null) {
		console.log(result)
	}
});

Find the row with the specified attribute values

storagejs('tableName').findByAttributes({age: '23', city: 'Pandeglang'}, function(err, result) {
	if (err === null) {
		console.log(result)
	}
});

Find all rows satisfying the specified condition

storagejs('tableName').findAllByAttribute('id', 'dida', function(err, result) {
	if (err === null) {
		console.log(result)
	}
});

Find all row with the specified attribute values

storagejs('tableName').findAllByAttributes({age: '23', city: 'Pandeglang'}, function(err, result) {
	if (err === null) {
		console.log(result)
	}
});

or

storagejs('tableName').findAll({age: '23', city: 'Pandeglang'}, function(err, result) {
	if (err === null) {
		console.log(result)
	}
});

Find position index row by id

storagejs('tableName').findIndexById('dida', function(err, result) {
	if (err === null) {
		console.log(result)
	}
});

Limit and Offset

Limit and offset work on method :

  • all()
  • findAll()
  • findAllByAttribute()
  • findAllByAttributes()

to use it, limit or a limit and offset inserted after attribute condition.

// limit only
storagejs('tableName').findAll({city: 'Pandeglang'}, 5, function(err, result) {
	if (err === null) {
		console.log(result)
	}
});

storagejs('tableName').all(5, function(err, result) {
	if (err === null) {
		console.log(result)
	}
});

// limit and offset
storagejs('tableName').findAll({city: 'Pandeglang'}, 5, 3, function(err, result) {
	if (err === null) {
		console.log(result)
	}
});

storagejs('tableName').all(5, 3, function(err, result) {
	if (err === null) {
		console.log(result)
	}
});

Update Record

  • updateById(id, object)
  • updateAllByAttributes(objectFinder, objectAttr)

Update the rows matching the specified condition

var attr = {
	city: 'Serang'
}
storagejs('tableName').updateById('dida', attr, function(err, result) {
	if (err === null) {
		// your code
	}
});

Update all rows matching the specified condition

var findAttr = {
	city: 'Pandeglang'
}
var newDataAttr = {
	city: 'Serang'
}

storagejs('tableName').updateAllByAttributes(findAttr, newDataAttr, function(err, result) {
	if (err === null) {
		// your code
	}
});

Delete Record

  • deleteById(id)
  • deleteAllByAttribute(key, val)
  • deleteAllByAttributes(object)
  • deleteAll()

Delete the rows matchin ID

storagejs('tableName').deleteById('dida', function(err, result) {
	if (err === null) {
		// your code
	}
});

Delete all rows matching the specified condition

storagejs('tableName').deleteAllByAttribute('city', 'Pandeglang', function(err, result) {
	if (err === null) {
		// your code
	}
});

Delete all row with the specified attribute values

var attr = {
	city: 'Pandeglang'
}
storagejs('tableName').deleteAllByAttributes(attr, function(err, result) {
	if (err === null) {
		// your code
	}
});

Delete all record

storagejs('tableName').deleteAll(function(err, result) {
	if (err === null) {
		// your code
	}
});

Remove Table

storagejs('tableName').remove(function(err, result) {
	if (err === null) {
		// your code
	}
});

Contributor