Thanks to visit codestin.com
Credit goes to github.com

Skip to content

mlaanderson/database-js-localstorage

Repository files navigation

database-js-localstorage

Build Status

Database-js interface for Web Browser Local Storage

About

Database-js-localstorage is a database-js driver which uses the web browser local storage as the backend. It supports table creation, selects, inserts, deletes, and updates. Selects can use inner, left and right joins. Outer joins are not yet supported by the SQL parser. It supports schemas, the default schema is called "public".

Database-js-localstorage includes a very basic localstorage implementation for NodeJS. It saves to and reads from a file called "localstorage.json";

Install

npm install database-js database-js-localstorage

Usage:

var Connection = require('database-js').Connection;

(async () => {
    let connection, statement, rows;
    connection = new Connection('localstorage:///[database-name]');
    
    try {
        statement = await connection.prepareStatement("SELECT * FROM users WHERE username = ?");
        rows = await statement.query('dduck');
        console.log(rows);
    } catch (error) {
        console.log(error);
    } finally {
        await connection.close();
    }
})();

In the browser, you have to load the database-js-localstorage driver yourself and pass it to the Connection class:

var Connection = require('database-js').Connection;
var Driver = require('database-js-localstorage');

(async () => {
    let connection, statement, rows;
    connection = new Connection('localstorage:///[database-name]', Driver);
    
    try {
        statement = await connection.prepareStatement("SELECT * FROM users WHERE username = ?");
        rows = await statement.query('dduck');
        console.log(rows);
    } catch (error) {
        console.log(error);
    } finally {
        await connection.close();
    }
})();

License

MIT (c) mlaanderson

About

Database driver that uses localstorage as a table storage mechanism

Resources

License

Stars

Watchers

Forks

Packages

No packages published