All Projects → kucukkanat → Localdb

kucukkanat / Localdb

Licence: mit
MongoDB on the browser. A database using Javascript localStorage

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Localdb

Web Storage Cache
对localStorage 和sessionStorage 进行了扩展,添加了超时时间,序列化方法
Stars: ✭ 582 (+768.66%)
Mutual labels:  localstorage
Tableexport
The simple, easy-to-implement library to export HTML tables to xlsx, xls, csv, and txt files.
Stars: ✭ 781 (+1065.67%)
Mutual labels:  localstorage
Use Persisted State
A custom React Hook that provides a multi-instance, multi-tab/browser shared and persistent state.
Stars: ✭ 943 (+1307.46%)
Mutual labels:  localstorage
Storage
Asynchronous browser storage with multiple back-ends (IndexedDB, WebSQL, localStorage)
Stars: ✭ 612 (+813.43%)
Mutual labels:  localstorage
Nano Sql
Universal database layer for the client, server & mobile devices. It's like Lego for databases.
Stars: ✭ 717 (+970.15%)
Mutual labels:  localstorage
Broadcast Channel
📡 BroadcastChannel to send data between different browser-tabs or nodejs-processes 📡
Stars: ✭ 843 (+1158.21%)
Mutual labels:  localstorage
Angular Async Local Storage
Efficient local storage module for Angular apps and PWA: simple API + performance + Observables + validation
Stars: ✭ 539 (+704.48%)
Mutual labels:  localstorage
Re Frame Storage
re-frame interceptors for browser local storage
Stars: ✭ 44 (-34.33%)
Mutual labels:  localstorage
Vue Music Player
🎵Vue.js写一个音乐播放器+📖One(一个).A music player + One by Vue.js
Stars: ✭ 729 (+988.06%)
Mutual labels:  localstorage
React Native Localstorage
Manage LocalStorage items in a web environment
Stars: ✭ 11 (-83.58%)
Mutual labels:  localstorage
Vue Local Storage
Vue.js localStorage plugin with types support
Stars: ✭ 639 (+853.73%)
Mutual labels:  localstorage
Histore
🏬 200b key-value store backed by navigation state
Stars: ✭ 683 (+919.4%)
Mutual labels:  localstorage
Aframe Persist Component
Persisting Aframe attribute data using localStorage
Stars: ✭ 10 (-85.07%)
Mutual labels:  localstorage
Notepad
基于vue2.0+vuex+localStorage+sass+webpack,实现一个本地存储的记事本。兼容PC端和移动端。
Stars: ✭ 597 (+791.04%)
Mutual labels:  localstorage
Remember Scroll
🎯 A plugin using localStorage to remember element scroll-position when closed the page.
Stars: ✭ 33 (-50.75%)
Mutual labels:  localstorage
Vuex Persistedstate
💾 Persist and rehydrate your Vuex state between page reloads.
Stars: ✭ 5,561 (+8200%)
Mutual labels:  localstorage
Storagedb
MongoDB-like API for HTML5 Storage (localStorage and sessionStorage)
Stars: ✭ 16 (-76.12%)
Mutual labels:  localstorage
Recoil Persist
Package for recoil state manager to persist and rehydrate store
Stars: ✭ 66 (-1.49%)
Mutual labels:  localstorage
Featherpasswordmanager
Highly portable extremely light-weight password manager that stores all your passwords in a local encrypted file.
Stars: ✭ 39 (-41.79%)
Mutual labels:  localstorage
Proxy Storage
Provides an adapter for storage mechanisms (cookies, localStorage, sessionStorage, memoryStorage) and implements the Web Storage interface
Stars: ✭ 10 (-85.07%)
Mutual labels:  localstorage

A local database implementation using localStorage API

This is a simple wrapper for javascript's localStorage API for a more convenient use.

Installation

yarn add local-db --dev

or

npm install local-db --save-dev

or

<!-- local-db will assign itself to window.LocalDB -->
<script src='https://unpkg.com/local-db'></script>

Usage

import LocalDB from 'local-db'

or

var LocalDB = require('local-db')

then

var usersTable = new LocalDB('users')

Methods

.create(object)

If object has an .id property, LocalDB will try to update the object in the table with regarding id.

usersTable.insert({username:'kucukkanat',city:'Izmir'})

returns : the user object created in table with generated ID

.read(query)

Returns an array of the elements matching the query

// Guys you are not allowed to buy cigarettes!
usersTable.query({age:{$lt:{18}}})

returns : the user object created in table with generated ID

.update(query,object)

Updates all objects in table matching the query. The update method does a deep merge using lodash 's _.merge method. _.merge

// Moves kucukkanat from Izmir to Amsterdam
usersTable.update({username:'kucukkanat'},{city:'Amsterdam'})

returns : LocalDB instance itself

.delete(query)

Deletes all objects in table matching the query

// Are you not a bit old for skating grandpa ?
usersTable.delete({age:{$gt:70}})

returns : LocalDB instance itself

.drop()

Empties the table

usersTable.drop()

returns : LocalDB instance itself

.on(eventName,fn)

Listens for events : insert , create , update , remove , delete , drop

users.on('$insert',(object)=>{
    // console.log(object, ' inserted!')
})
users.on('$delete',(object)=>{
    // console.log(object, ' deleted!')
})
users.on('$update',(object,nextObject)=>{
    console.log(object, ' updated to ',nextObject)
})

returns : LocalDB instance itself

Supported Operators:

See MongoDB's advanced queries for more info.

$in

array value must be $in the given query:

Intersecting two arrays:

//filtered: ['Brazil']
table.query({ $in: ['Costa Rica','Brazil'] }, ['Brazil','Haiti','Peru','Chile']);

Here's another example. This acts more like the $or operator:

table.query({ location: { $in: ['Costa Rica','Brazil'] } }, [ { name: 'Craig', location: 'Brazil' } ]);

$nin

Opposite of $in:

//filtered: ['Haiti','Peru','Chile']
table.query({ $nin: ['Costa Rica','Brazil'] }, ['Brazil','Haiti','Peru','Chile']);

$exists

Checks if whether a value exists:

//filtered: ['Craig','Tim']
table.query({ $exists: true }, ['Craig',null,'Tim']);

You can also filter out values that don't exist

//filtered: [{ name: 'Craig', city: 'Minneapolis' }]
table.query({ city: { $exists: false } }, [ { name: 'Craig', city: 'Minneapolis' }, { name: 'Tim' }]);

$gte

Checks if a number is >= value:

//filtered: [2, 3]
table.query({ $gte: 2 }, [0, 1, 2, 3]);

$gt

Checks if a number is > value:

//filtered: [3]
table.query({ $gt: 2 }, [0, 1, 2, 3]);

$lte

Checks if a number is <= value.

//filtered: [0, 1, 2]
table.query({ $lte: 2 }, [0, 1, 2, 3]);

$lt

Checks if number is < value.

//filtered: [0, 1]
table.query({ $lt: 2 }, [0, 1, 2, 3]);

$eq

Checks if query == value. Note that $eq can be omitted. For $eq, and $ne

//filtered: [{ state: 'MN' }]
table.query({ state: {$eq: 'MN' }}, [{ state: 'MN' }, { state: 'CA' }, { state: 'WI' }]);

Or:

//filtered: [{ state: 'MN' }]
table.query({ state: 'MN' }, [{ state: 'MN' }, { state: 'CA' }, { state: 'WI' }]);

$ne

Checks if query != value.

//filtered: [{ state: 'CA' }, { state: 'WI'}]
table.query({ state: {$ne: 'MN' }}, [{ state: 'MN' }, { state: 'CA' }, { state: 'WI' }]);

$mod

Modulus:

//filtered: [300, 600]
table.query({ $mod: [3, 0] }, [100, 200, 300, 400, 500, 600]);

$all

values must match everything in array:

//filtered: [ { tags: ['books','programming','travel' ]} ]
table.query({ tags: {$all: ['books','programming'] }}, [
{ tags: ['books','programming','travel' ] },
{ tags: ['travel','cooking'] } ]);

$and

ability to use an array of expressions. All expressions must test true.

//filtered: [ { name: 'Craig', state: 'MN' }]

table.query({ $and: [ { name: 'Craig' }, { state: 'MN' } ] }, [
{ name: 'Craig', state: 'MN' },
{ name: 'Tim', state: 'MN' },
{ name: 'Joe', state: 'CA' } ]);

$or

OR array of expressions.

//filtered: [ { name: 'Craig', state: 'MN' }, { name: 'Tim', state: 'MN' }]
table.query({ $or: [ { name: 'Craig' }, { state: 'MN' } ] }, [
{ name: 'Craig', state: 'MN' },
{ name: 'Tim', state: 'MN' },
{ name: 'Joe', state: 'CA' } ]);

$nor

opposite of or:

//filtered: [ { name: 'Tim', state: 'MN' }, { name: 'Joe', state: 'CA' }]
table.query({ $nor: [ { name: 'Craig' }, { state: 'MN' } ] }, [
{ name: 'Craig', state: 'MN' },
{ name: 'Tim', state: 'MN' },
{ name: 'Joe', state: 'CA' } ]);

$size

Matches an array - must match given size:

//filtered: ['food','cooking']
table.query({ tags: { $size: 2 } }, [ { tags: ['food','cooking'] }, { tags: ['traveling'] }]);

$type

Matches a values based on the type

table.query({ $type: Date }, [new Date(), 4342, 'hello world']); //returns single date
table.query({ $type: String }, [new Date(), 4342, 'hello world']); //returns ['hello world']

$regex

Matches values based on the given regular expression

table.query({ $regex: /^f/i, $nin: ["frank"] }, ["frank", "fred", "sam", "frost"]); // ["fred", "frost"]
table.query({ $regex: "^f", $options: "i", $nin: ["frank"] }, ["frank", "fred", "sam", "frost"]); // ["fred", "frost"]

$where

Matches based on some javascript comparison

table.query({ $where: "this.name === 'frank'" }, [{name:'frank'},{name:'joe'}]); // ["frank"]
table.query({
	$where: function() {
		return this.name === "frank"
	}
}, [{name:'frank'},{name:'joe'}]); // ["frank"]

$elemMatch

Matches elements of array

var bills = [{
    month: 'july',
    casts: [{
        id: 1,
        value: 200
    },{
        id: 2,
        value: 1000
    }]
},
{
    month: 'august',
    casts: [{
        id: 3,
        value: 1000,
    }, {
        id: 4,
        value: 4000
    }]
}];

var result = table.query({
    casts: {$elemMatch:{
        value: {$gt: 1000}
    }}
}, bills); // {month:'august', casts:[{id:2, value: 1000},{id: 4, value: 4000}]}

$not

Not expression:

table.query({$not:{$in:['craig','tim']}}, ['craig','tim','jake']); //['jake']
table.query({$not:{$size:5}}, ['craig','tim','jake']); //['tim','jake']

sub object Searching

var people = [{
	name: 'craig',
	address: {
		city: 'Minneapolis'
	}
},
{
	name: 'tim',
	address: {
		city: 'St. Paul'
	}
}];

var queried = table.query({ address: { city: 'Minneapolis' }}, people); // count = 1

//or
var queried = table.query({'address.city': 'minneapolis'}, people);//count = 1
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].