# sweet-local-storage-db

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

Latest version **1.0.2** (published 2023-01-09) · ISC license · 0 weekly downloads

## Install

```sh
npm install sweet-local-storage-db
pnpm add sweet-local-storage-db
yarn add sweet-local-storage-db
bun add sweet-local-storage-db
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.2 |
| Published | 2023-01-09 |
| First published | 2023-01-09 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 201 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | crisrochadev |
| Maintainers | crisrochadev |
| Keywords | database, localStorage |

## Links

- npm: https://www.npmjs.com/package/sweet-local-storage-db
- Repository: https://github.com/crisrochadev/sweet-local-storage-db
- Homepage: https://crisrochadev.github.io/sweet-local-storage-db
- Issues: https://github.com/crisrochadev/sweet-local-storage-db/issues
- npm.io page: https://npm.io/package/sweet-local-storage-db

## Alternatives

- [localforage](https://npm.io/package/localforage.md) — 6.2M weekly downloads
- [localforage-observable](https://npm.io/package/localforage-observable.md) — 30.8K weekly downloads
- [@y/y](https://npm.io/package/@y/y.md) — 30.1K weekly downloads
- [@metaobjectsdev/render](https://npm.io/package/@metaobjectsdev/render.md) — 3.5K weekly downloads
- [@ledgerhq/coin-algorand](https://npm.io/package/@ledgerhq/coin-algorand.md) — 1.1K weekly downloads

## Recent versions

- 1.0.2 (latest) — 2023-01-09
- 1.0.1 — 2023-01-09
- 1.0.0 — 2023-01-09

## README

# Local Storage DB

<table>
  <tbody>
    <tr>
      <td><img src="./assets/images/logo.png" alt="Local Storage DB" title="Local Storage DB"/></td>
      <td><b>A database system in Javascript, which uses localStorage to store data, in order to facilitate their persistence in processes and creation.</b></td>
    </tr>
  </tbody>
</table>
<br/>
<hr/>
<br/>

## Inicialize

```javascript
const db = new SweetLocalDB(<dbName>);
```

### Check if the database has been initialized

```javascript
const isInit = db.dbHasBeenInitialized();
```

### Create Table

```javascript

bd.createTable(<tableName>,<arrayColumnsName>);

```

### Get all Tables

```javascript
const tables = db.getAllTables();
```

### get table by name

```javascript

const table = db.getTable(<table-name>);

```

### update the table

```javascript
  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>
    }
  });
```

```javascript
const table = db.updateTable("users", {
  name: "clients",
  updateCols: {
    remove: ["last_name", "first_name"],
    add: ["full_name"],
    update: {
      password: "pass",
    },
  },
});
```

### delete the table

```javascript

const table = db.removeTable(<table-name>);

```

## CRUD

### Insert

```javascript
const data = db.insert("<table-name>", {
  name: "John Doe",
  email: "jhon@doe.com",
  password: "123456",
});
```

or

```javascript
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

```javascript

const data = db.update('<table-name>',{<data>},'<find>','<condition>','<where>');

const data = db.update('users',{password:'654321'},'$id','=',3);

```

<a href="#conditions"> Conditions </a>

### Read (Get)

#### Get all items

```javascript
const data = db.get("users");
```

#### Find by

```javascript
const data1 = db.find("<table-name>", "<find>", "<condition>", "<where>");

const data1 = db.find("users", "full-name", "start", "John");
```

About the Conditions see the list <a href="#conditions"> Conditions </a>

### Delete

```javascript
const data1 = db.find("<table-name>", "<$id>", "<id>");

const data = db.delete("clients", "$id", 2);
```

## Contitions

<div id='conditions'>
<table>
  <thead>
    <tr>
      <th>Condition</th>
      <th>type</th>
      <th>Description</th>
    </tr>
  <thead>
  <tbody>
    <tr>
      <td>start</td>
      <td style="color:blue">String</td>
      <td>value starts with:</td>
    </tr>
     <tr>
      <td>end</td>
      <td style="color:blue">String</td>
      <td>value ends with:</td>
    </tr>
     <tr>
      <td>contain</td>
      <td style="color:blue">String</td>
      <td>value conatain {caractere}</td>
    </tr>
    <tr>
      <td>></td>
      <td style="color:blue">String</td>
      <td>value greater than</td>
    </tr>
    <tr>
      <td>>=</td>
      <td style="color:blue">String</td>
      <td>value greater than or equal to</td>
    </tr>
    <tr>
      <td><</td>
      <td style="color:blue">String</td>
      <td>value less than </td>
    </tr>
    <tr>
      <td><=</td>
      <td style="color:blue">String</td>
      <td>value less than or equal to</td>
    </tr>
    <tr>
      <td>=</td>
      <td style="color:blue">String</td>
      <td>value equal to</td>
    </tr>
  </tbody>
</table>

</div>

---
_Source: https://npm.io/package/sweet-local-storage-db · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
