1.0.2 • Published 3 years ago
sweet-local-storage-db v1.0.2
Local Storage DB
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);