Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/selfup/lspi
ORM for local storage that can save you time!
https://github.com/selfup/lspi
Last synced: 3 months ago
JSON representation
ORM for local storage that can save you time!
- Host: GitHub
- URL: https://github.com/selfup/lspi
- Owner: selfup
- License: mit
- Created: 2016-06-18T00:24:06.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2023-10-24T04:05:01.000Z (about 1 year ago)
- Last Synced: 2024-04-13T21:56:35.937Z (9 months ago)
- Language: JavaScript
- Homepage:
- Size: 1.2 MB
- Stars: 6
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Local Storage Programming Interface
### Basic ORM for local storage that can save you time!
Super easy to use!
Store and retrieve valid JSON objects/arrays or simple strings :smile:
Make sure to use polyfills for `Array.from` and `Object.assign` when bundling your application code! :tada:
### Install
`npm install lspi --save`
### Basics
```javascript
const lspi = require('lspi');//= set string ->
lspi.set('testOne', 'testing');
// Returns: undefined
// Stores: "testing"//= get string ->
lspi.get('testOne');
// Returns: "testOne"//= set object literal ->
lspi.set('testOne', {});
// Returns: undefined
// Stores: "{}"//= get object literal ->
lspi.get('testOne');
// Returns: {}//= set array ->
lspi.set('testTwo', []);
// Returns: undefined
// Stores: "[]"//= get array ->
lspi.get('testTwo');
// Returns: []//= set array of objects ->
lspi.set('testOne', [{ name: 'test' }, { name: 'test2' }]);
// Returns: undefined
// Stores: "{"name": "test2"}"//= where query on array of objects ->
lspi.where('testOne', 'name', 'test2');
// Returns: [{ name: 'test2' }]//= update state ->
lspi.set('test42', { hey: 'hi' });lspi.update('test42', { ok: 'new stuff' });
// Returns: undefined
// Adds ok key and 'new stuff' value to the 'testOne' recordlspi.update('test42', { hey: 'hello' });
// Returns: undefined
// Updates hey value to 'hello' instead of 'hi'//= remove data (singular) ->
lspi.drop('testOne');
// Returns: undefined
// This will delete the 'testOne' record from localStorage//= remove all data ->
lspi.dropAll();
// Returns: undefined
// Drops ALL localStorage associated to your domain//= Mutiple set ->
lspi.sets(['test', { wow: 'wow1' }], ['test2', { wow: 'wow2' }]);
// Returns: undefined
// Stores: {wow: 'wow1'} in mthe 'test' key
// Stores: {wow: 'wow2'} in the 'test2' keyconst testDataOne = lspi.get('test');
const testDataTwo = lspi.get('test2');testDataOne; // => {wow: 'wow1'}
testDataTwo; // => {wow: 'wow2'}//= Multiple get ->\
lspi.sets(['test', { wow: 'wow' }], ['test2', { wow: 'wow' }]);const testData = lspi.gets('test', 'test2');
testData; // => ['test', {wow: 'wow'}], ['test2', {wow: 'wow'}]
//= Multiple drop ->
lspi.sets(
['test', { wow: 'wow1' }],
['test2', { wow: 'wow2' }],
['test3', { wow: 'wow3' }],
);lspi.drops('test', 'test2');
// Returns: undefined
// 'test3' -> {wow: 'wow3'} remains
```