Coder Social home page Coder Social logo

instapp / storagedb Goto Github PK

View Code? Open in Web Editor NEW
17.0 17.0 4.0 48 KB

MongoDB-like API for HTML5 Storage (localStorage and sessionStorage)

Home Page: https://instapp.github.io/storagedb

License: MIT License

JavaScript 100.00%
library localstorage sessionstorage storagedb

storagedb's People

Contributors

acathur avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

storagedb's Issues

Library un-usable on Typescript projects

Not sure if this project is still maintained, but I tried using it on a typescript project and it throws a TypeError: storagedb2_1.default is not a constructor which causes compilation to fail. Maybe a .d.ts definitions file would be needed.

How to check the existence of DB and Collection

Hi,

I want to check whether DB and Collection already exists before I create them. Please advise how to achieve.

I want to check whether DB exists before I create it

const localStorageObj = new StorageDB({
    storage: window.localStorage,     // storage object, default is window.localStorage. If you want to store data in memory only, you can set it null
    database: localStorage.getItem('appkey'),               // database name, default is 'db'
    primaryKey: 'id'                  // primary key of collection, default is '_id'
});

I want to check whether the collection is exists before create it
const UsercommentsTable = localStorageObj.get('UsercommentsTable');

Error in React Web

Hi, I have been using this for my web projects. Recently, I have started one of my web application using React web framework. As I try to use the storagedb2, I'm getting the following error.

"storagedb2__WEBPACK_IMPORTED_MODULE_1___default.a is not a constructor"

Here is the detailed error.

"TypeError: storagedb2__WEBPACK_IMPORTED_MODULE_1___default.a is not a constructor
    at Storage.returnDatabase (http://localhost:3000/static/js/main.chunk.js:321:16)
    at HTMLUnknownElement.callCallback (http://localhost:3000/static/js/0.chunk.js:7715:18)
    at Object.invokeGuardedCallbackDev (http://localhost:3000/static/js/0.chunk.js:7764:20)
    at invokeGuardedCallback (http://localhost:3000/static/js/0.chunk.js:7817:35)
    at invokeGuardedCallbackAndCatchFirstError (http://localhost:3000/static/js/0.chunk.js:7832:29)
    at executeDispatch (http://localhost:3000/static/js/0.chunk.js:7963:7)
    at executeDispatchesInOrder (http://localhost:3000/static/js/0.chunk.js:7988:9)
    at executeDispatchesAndRelease (http://localhost:3000/static/js/0.chunk.js:8091:9)
    at executeDispatchesAndReleaseTopLevel (http://localhost:3000/static/js/0.chunk.js:8100:14)
    at forEachAccumulated (http://localhost:3000/static/js/0.chunk.js:8072:12)
    at runEventsInBatch (http://localhost:3000/static/js/0.chunk.js:8117:7)
    at runExtractedPluginEventsInBatch (http://localhost:3000/static/js/0.chunk.js:8259:7)
    at handleTopLevel (http://localhost:3000/static/js/0.chunk.js:13212:9)
    at batchedEventUpdates$1 (http://localhost:3000/static/js/0.chunk.js:31720:16)
    at batchedEventUpdates (http://localhost:3000/static/js/0.chunk.js:8795:16)
    at dispatchEventForPluginEventSystem (http://localhost:3000/static/js/0.chunk.js:13308:9)
    at attemptToDispatchEvent (http://localhost:3000/static/js/0.chunk.js:13425:9)
    at dispatchEvent (http://localhost:3000/static/js/0.chunk.js:13328:23)
    at unstable_runWithPriority (http://localhost:3000/static/js/0.chunk.js:42699:16)
    at runWithPriority$2 (http://localhost:3000/static/js/0.chunk.js:19587:14)
    at discreteUpdates$1 (http://localhost:3000/static/js/0.chunk.js:31737:16)
    at discreteUpdates (http://localhost:3000/static/js/0.chunk.js:8820:16)
    at dispatchDiscreteEvent (http://localhost:3000/static/js/0.chunk.js:13295:7)"

Here is my React component

import React from "react";
import StorageDB from 'storagedb2'



class Storage extends React.Component{
    constructor(props, context) {
        super(props, context);
        this.state = {
            name:'John'
        }
    this.returnDatabase = this.returnDatabase.bind(this);
    };

    returnDatabase()
    {
        const db = new StorageDB({
            storage: window.localStorage,     // storage object, default is window.localStorage. If you want to store data in memory only, you can set it null
            database: 'testdb',               // database name, default is 'db'
            primaryKey: 'id'                  // primary key of collection, default is '_id'
        });
        const Users = db.get("Users");
        Users.insert({'a':1});
    }
    render(){
        return <div>Storage <button onClick={this.returnDatabase}>Click me</button></div>
    }
}
export default Storage;

Please advise how to solve this issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.