npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

crud-indexeddb

v1.0.12

Published

Base para persistir datos en el exporador

Downloads

15

Readme

Crud Indexeddb

Usar indexeddb con operaciones CRUD.

DEMO

Install

npm i crud-indexeddb

Setup

Ejemplo de uso:

import {CrudIndexeddb} from 'crud-indexeddb';

function onError(e) {
    console.log(e);
}

const tablas = {
    persona: {
        //id de la tabla
        id: 'id'
    }
};

/**
 * Version de indexedDb, se cambia con cada cambio de las tablas.
 */
const version = 1;

let db = new CrudIndexeddb();

await db.init('test', version, tablas, onError);

cdn

Uso con unpkg:

import {CrudIndexeddb} from 'https://unpkg.com/crud-indexeddb';

Changelog

version 1.0.12

  • se arreglo problema para compilar version build con proyectos vite

Crear datos (post)

Para agregar datos a una tabla necesitamos hacer un post:

db.post(tabla: string, datos: Object, autoid: booblean): Promise<Object>;

donde:

| Opcion | tipo | Description | | -------------- | ------ | ----------------------------------------- | | tabla | string | Nombre de la tabla | | datos | Object | Datos que se guardaran | | autoid | boolean | Indica si se genera el id automaticamente, por defecto es true|

Nota: Por defecto el id que se crea es un timestamp(Date.now).

Ejemplo guardar persona con auto id:

db.post('persona',{nombre: 'Juan'}).then(response => {
    console.log('persona guardada', response);
}).catch(error => {
    console.log('ocurrio algo malo');
});

Crear persona con id personalizado

db.post('table1',{nombre: 'Juan', id: 1}, false).then(response => {
    console.log('save something', response);
}).catch(error => {
    console.log('bad something happened');
});

Leer datos

Contamos con dos opciones: get and list.

Get

Regresa un item que concuerda con el id dado.

db.get(tabla: string, id: any): Promise<Object>;

donde: | Opcion | tipo | Description | | -------------- | ------ | -----------------------------------------| | tabla | string | Nombre de la tabla | | id | any | Id que identificara al campo | Ejemplo

db.get('persona', 142563652).then(response => {
    console.log('la persona', response);
}).catch(error => {
    console.log('no existe la persona');
});

List

Regresa la lista de todos los items de la tabla

db.list(tabla: string): Promise<[Object]>;

donde: | Opcion | tipo | Description | | -------------- | ------ | -----------------------------------------| | tabla | string | Nombre de la tabla |

db.list('persona').then(response => {
    console.log('Todas las personas', response);
}).catch(error => {
    console.log('');
});

Actualizar datos

Para actualizar los registro de la tabla usamos

db.put(tabla: string, datos: Object): Promise<Object>;

donde | Opcion | tipo | Description | | -------------- | ------ | ------------------------------------------------------------------------------------| | tabla | string | Nombre de la tabla | | datos | Object | Es un objecto que contiene los datos, debe incluir el id con el que se identifica.|

Nota: Si no existe el id, creara automaticamente el registro.

db.put('persona',{id: 142563652, nombre: 'Juana'}).then(response => {
    console.log('persona actualizada', response);
});

Delete

All items have a id, so when we delete a item use the id of item for delete it.

db.delete(tabla: string, id: any): Promise<Boolean>;

donde: | Opcion | tipo | Description | | -------------- | ------ | -----------------------------------------| | tabla | string | Nombre de la tabla | | id | any | Id que identificara al campo |

db.delete('persona', 142563652).then(response => {
    console.log('delete the item', response);
});