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

indexed-db-async

v0.0.2

Published

opera indexed-db with promise

Downloads

3

Readme

indexed-db-async

oprea indexed-db with promise.

NPM version NPM downloads

install

npm install --save indexed-db-async

or

yarn add indexed-db-async

usage

  1. open db
// a filter.js
import IndexedDBAsync from 'indexed-db-async';

const db = new IndexedDBAsync('indexed-db-test', 1, [
  {
    name: 'table1',
    key: 'url',
    // autoIncrement: true,
    indexes: [
      { name: 'timestamp', unique: false }
    ]
  }
]);

// add/update data
db.put('table1', { url: 'url1', timestamp: (new Date()).now()  });
  1. add/update data
for (let i = 1; i < 10; i++) {
  const count = await db.put<DBItem[]>('table1', { url: `url${i}`, data: 'data' + i, timestamp: Date.now() });
  console.log('put count: ' +  count);
}

const count = await db.add(
  'table1', 
  [
    { url: `url1`, data: 'data1', timestamp: Date.now() },
    { url: `url2`, data: 'data2', timestamp: Date.now() },
    { url: `url3`, data: 'data3', timestamp: Date.now() }
  ]
);

const count = await db.put(
  'table1', 
  [
    { url: `url1`, data: 'data1', timestamp: Date.now() },
    { url: `url2`, data: 'data2', timestamp: Date.now() },
    { url: `url3`, data: 'data3', timestamp: Date.now() }
  ]
);
  1. get data
const item = await db.get('table1', `url1`);
console.log(`get item`, item);

// get all data
const itemList = await db.all('table1');
console.log(`get itemList`, itemList);
  1. query data
// query data by key
const itemList = await db.query('table1', `url1`);
console.log(`query item list `, itemList);

// query keys
const keys = await db.queryKeys('table1', '> "url1"');
console.log(`query keys `, keys);

// query data by index
const itemList = await db.query('table1', 'timestamp > 12314234234');
console.log(`query item list `, itemList);

// query data by index using IDBKeyRange
const itemList = await db.query('table1', IDBKeyRange.lowerBound(0));
console.log(`query item list `, itemList);
  1. query table count
const count = await db.count('table1');
console.log(`table count`, count);
  1. clear table
await db.clear('table1');
console.log(`table cleared, current count:`, await db.count(table1));
  1. delete table item
await db.delete('table1', 'url1');

// delete datas
await db.delete('table1', ['url1', 'url2', 'url3']);

// delete data using IDBKeyRange
await db.deleteRange('table1', '> "url1"');

// delete data by index
await db.deleteRange('table1', 'timestamp = 12314234234');

// delete data by index using IDBKeyRange
await db.deleteRange('table1', 'timestamp > 0');

await db.deleteRange('table1', `timestamp >= 0 && < ${new Date().now()}`);
  1. create IDBKeyRange by text
db.range('<= x')          // => IDBKeyRange.upperBound('x')
db.range('< x')           // => IDBKeyRange.upperBound('x', true)
db.range('>= x')          // => IDBKeyRange.lowerBound('x')
db.range('> x')           // => IDBKeyRange.lowerBound('x', true)
db.range('>= x && <= y')  // => IDBKeyRange.bound('x', 'y')
db.range('> x && < y')    // => IDBKeyRange.bound('x', 'y', true, true)
db.range('> x && <= y')   // => IDBKeyRange.bound('x', 'y', true)
db.range('>= x && < y')   // => IDBKeyRange.bound('x', 'y', false, true)
db.range('= x')           // => IDBKeyRange.only('x')

range text format: [indexName] >|<|>=|<= value1 [&& >|<|>=|<= value2]