Skip to content

Manipulate data using your LocalStorage in an easy and fluent way

License

Notifications You must be signed in to change notification settings

EltonCarreiro/easylocalstorage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Easy Local Storage (Under Construction)

About

Lightweight library that allows you to manipulate your LocalStorage data using a fluent syntax.

Supported Commands

There are commands we can perform over the local storage. See below the supported commands:

  • insert
  • get
  • getAll
  • update
  • updateAll
  • updateOrInsert
  • updateOrInsertAll
  • replace
  • replaceAll
  • del
  • delAll

The commands listed above are used combined with a criteria, which will tell when to act or ignore the registry. The list of supported criterias are lsited below:

  • eq (equals)
  • like (case sensitive)
  • ilike (case insensitive)
  • lessThan
  • lessOrEqualThan
  • greaterThan
  • greaterOrEqualThan
  • matches (RegExp support)

You can combine the listed criteria with all the available commands except the command insert, wich can be substituted with the command updateOrInsert

You also can use a command without criteria, doing so, you will reach all the registries stored in the local storage. The commands that can be used without criteria are those with the "All" suffix.

Examples


First of all instantiate the database:
var db = new easyStorage('dbname', true);

When you create a new instance of a database you must specify the name it should have in your local storage. If the name already exists, then the database will check the second parameter which means if you want to use the existing structure or you want it to be overrode. Specifying true means it must be overrode, specifying false or ommiting the parrameter means it must not be overrode.

"Get age from a person who is called John"
where('name').eq('John').get('age');

"Set age to 18 for a person with name equals to Jessy"
where('name').eq('Jessy').update({ "age" : 18 });

By default each command just manipulate the first found registry. If you want to manipulate all found registries then you can use the 'All version'. Example:

'Single version':
where('name').eq('John').get('age');

'All version':
where('name').eq('John').getAll('age');

Note: All commands has its 'All version'. To use it just add All at the end of the command name, then you will be able to reach all registries.

Future Implementations

We are at just the beggining of the library and we have lots of work to do! Take a look at our agenda:

  • Allow arrays at the pathfinder
    • Browser over the whole array like 'person.[hobbies].name (hobbies is an array)'
    • Browser over specific node like 'person.[hobbies][0].name (hobbies is an array)'
  • Local Storage fallback (to cookies!)
  • Allow adding custom criteria functions

About

Manipulate data using your LocalStorage in an easy and fluent way

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published