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

indexdb-prisma

v1.0.4

Published

a promise based library which uses prisma syntax to query indexdb database on the browser

Downloads

10

Readme

Prisma for IndexDB

Primsa for IndexDB is a promise based library with close resemblance to the well documented prisma query library.

Purpose

Given the major advantage IndexDB possess in storage space, along with the non serialisation benefit. About 60Gb or more allowed from one source, compared to 5-10MB max storage space for local storage, the next/closest competitor, there were only few-easy to use library that tackles the use of IndexDb. So i took it upon myself to build this library.

Comparison

| | | | --- | --- | | Local Storage | IndexDB | | 5-10MB max storage | 20GB - 100GB max storage (depends on system drive) | | No key/auto increment indexes | Can use auto increment index, search query | | Stores only string | Can store anything from array, object, string, number and more.. | | No structure | Well structured like a typical relational database | | For simple use cases | For advanced use cases & speed |

Usage

Database Initialisation

1. import database instance to your project file

import { IndexedDatabase } from 'indexdb-prisma';

const initialise  = async () => {
   const db = await IndexedDatabase('pos', { schema: schemaMockup });
}

2. Schema Database schema is required in order to initialise indexdb database. It must be an object with object properties/keys representing a database table, and the value of each key/property must be an object with each properties/keys value of type  DBTypes

3. DBTypes

A DBType represent the type for each tables column in a schema object. Available types include  StringType, NumberType, ArrayType, ObjectType, BooleanType, BigIntType, SymbolType, DateType, AutoIncrement

These types can be imported for use in your schema file.

4. Example schema object and explanation

import { AutoIncrement, StringType, DateType } from 'indexdb-prisma';

const schemaMockup = {
  users: {
    id: AutoIncrement,
    email: StringType,
    first_name: StringType,
    last_name: StringType,
    password: StringType,
    created_at: DateType,
  },
  posts: {
    id: AutoIncrement,
    title: StringType,
    summary: StringType,
    article: StringType,
    created_at: DateType
  },
  comments: {
    id: AutoIncrement,
    userId: NumberType,
    summary: StringType,
    postId: NumberType,
    created_at: DateType
  }
}

This created a database with three tables users, posts, comments. users, with columns id of type AutoIncrement, email of type string ........... , posts table with columns id, title , summary etc.

5. Querying the database Promise base query (much like prisma) makes using IndexDb much easier and straighforward

6. To create new user

import { IndexedDatabase } from 'indexdb-prisma';

const initialise  = async () => {
   const db = await IndexedDatabase('pos', { schema: schemaMockup });
    const create = await db.users.createOne({
      created_at: new Date(),
      email: '[email protected]',
      first_name: 'Leeroy',
      last_name: 'Johnson',
      password: 'qwerty',
    })
    console.log(create.password)
}

7. To get a user

import { IndexedDatabase } from 'indexdb-prisma';

const initialise  = async () => {
   const db = await IndexedDatabase('pos', { schema: schemaMockup });
   let get = await db.users.getOne('email', '[email protected]');
   // OR
   let get = await db.users.getOne(1);
   console.log(get.email)
}

8. To update a user

import { IndexedDatabase } from 'indexdb-prisma';

const initialise  = async () => {
   const db = await IndexedDatabase('pos', { schema: schemaMockup });
   const update = await db.users.updateOne(1, { email: '[email protected]' })
   // OR
   const update = await db.users.updateOne({column: 'email', value: '[email protected]'}, { email: '[email protected]' })
   console.log(update)
}

9. To delete one or all user

import { IndexedDatabase } from 'indexdb-prisma';

const initialise  = async () => {
   const db = await IndexedDatabase('pos', { schema: schemaMockup });
   const del =  const del = await db.users.deleteOne(1);
   // OR
   const del =  const del = await db.users.deleteMany();
   const del = await db.users.deleteOne({column: 'email', value: '[email protected]'})
   console.log(del)
}

6. To delete, add new tables a table **To delete a table you must ensure you do two things.

  • Update your schema file by adding/removing new table names
  • Increase your database version to a higher number. Must be a whole number for this to work
import { IndexedDatabase, AutoIncrement , StringType, DateType } from 'indexdb-prisma';


const schemaMockup = {
  users: {
    id: AutoIncrement,
    email: StringType,
    first_name: StringType,
    last_name: StringType,
    password: StringType,
    created_at: DateType,
  },
  posts: {
    id: AutoIncrement,
    title: StringType,
    summary: StringType,
    article: StringType,
    created_at: DateType
  }
}

const initialise  = async () => {
   const db = await IndexedDatabase('pos', { schema: schemaMockup , version: 2)
}

11. To delete database

import { IndexedDatabase } from 'indexdb-prisma';

const initialise  = async () => {
   const db = await IndexedDatabase('pos', { schema: schemaMockup });
   const delDB =  await db.$transaction.deleteDatabase()
   console.log(delDB)
}

I have so much i am doing right now. PR is welcomed