npm.io
1.0.2 • Published 3 years ago

sweet-local-storage-db

Licence
ISC
Version
1.0.2
Deps
0
Size
201 kB
Vulns
0
Weekly
0

Local Storage DB

Local Storage DB A database system in Javascript, which uses localStorage to store data, in order to facilitate their persistence in processes and creation.



Inicialize

const db = new SweetLocalDB(<dbName>);

Check if the database has been initialized

const isInit = db.dbHasBeenInitialized();
Create Table

bd.createTable(<tableName>,<arrayColumnsName>);
Get all Tables
const tables = db.getAllTables();
get table by name

const table = db.getTable(<table-name>);
update the table
  const table = db.updateTable(<table-name>,{
    name:<new-table-name><optional>,
    updateCols:{
        remove:[<remove-items-list>]<optional>,
        add:[<add-items-list>']<optional>,
        update:{
            <new-column>:<old-column>
        }<optional>
    }
  });
const table = db.updateTable("users", {
  name: "clients",
  updateCols: {
    remove: ["last_name", "first_name"],
    add: ["full_name"],
    update: {
      password: "pass",
    },
  },
});
delete the table

const table = db.removeTable(<table-name>);

CRUD

Insert
const data = db.insert("<table-name>", {
  name: "John Doe",
  email: "jhon@doe.com",
  password: "123456",
});

or

const data = db.insert("<table-name>", [
  {
    name: "John Doe",
    email: "jhon@doe.com",
    password: "123456",
  },
  {
    name: "Doe John",
    email: "email@email.com",
    password: "654321",
  },
]);
Update

const data = db.update('<table-name>',{<data>},'<find>','<condition>','<where>');

const data = db.update('users',{password:'654321'},'$id','=',3);

Conditions

Read (Get)
Get all items
const data = db.get("users");
Find by
const data1 = db.find("<table-name>", "<find>", "<condition>", "<where>");

const data1 = db.find("users", "full-name", "start", "John");

About the Conditions see the list Conditions

Delete
const data1 = db.find("<table-name>", "<$id>", "<id>");

const data = db.delete("clients", "$id", 2);

Contitions

Condition type Description
start String value starts with:
end String value ends with:
contain String value conatain {caractere}
> String value greater than
>= String value greater than or equal to
< String value less than
<= String value less than or equal to
= String value equal to

Keywords