Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Storage-JS is a database menagement for localStorage. You can store data on local storage easily and APIs like Yii Framework AR
Storage-JS is a database menagement for localStorage. You can store data on local storage easily and APIs like Yii Framework AR.
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>
NodeJS
var storagejs = require('storage-js');
RequireJS
define([
'/bower_components/storage-js/storage.js'
], function(storagejs) {
// your code
});
or global variable name 'storagejs'
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
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);
}
All method support Sync and Async. for example, this use Async method.
table require id for primary key, default attribute name '_id'
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
}
});
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 work on method :
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 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 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
}
});
storagejs('tableName').remove(function(err, result) {
if (err === null) {
// your code
}
});
FAQs
Storage-JS is a database menagement for localStorage. You can store data on local storage easily and APIs like Yii Framework AR
The npm package storage-js receives a total of 11 weekly downloads. As such, storage-js popularity was classified as not popular.
We found that storage-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.