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

hold-this

v1.2.2

Published

A simple key-value datastore that holds your data until you need it.

Downloads

335

Readme

Hold This

A simple key-value store that uses SQLite as the backend. It is designed to be used in a single-threaded synchronous environment.

Getting Started

npm install --save hold-this

Use in-memory store

import hold from 'hold-this'

const holder = hold()
holder.set('accounts', 'account-123:user-123:name', 'Alice')
holder.set('accounts', 'account-123:user-456:name', 'Bob')

console.log(holder.get('accounts', 'account-123:*:name'))
// => [['account-123:user-123:name', 'Alice'], ['account-123:user-456:name', 'Bob']]

Other Examples

File based store

Pass an object with a key location and a path to a file. This will be the filepath that hold-this utilizes to write to disk.

import hold from 'hold-this'

const holder = holder({ location: './holder.sqlite' })
holder.set('accounts', 'account-123:user-123:name', 'Alice')
holder.set('accounts', 'account-123:user-456:name', 'Bob')

console.log(holder.get('accounts', 'account-123:*:name'))
// => [['account-123:user-123:name', 'Alice'], ['account-123:user-456:name', 'Bob']]

File based store defaults to using WAL for performance purposes. This can be disabled by setting { enableWAL: false} when creating the instance.

[!CAUTION] This will severely decrease write performance for File based storage.

import hold from 'hold-this'

const holder = holder({ location: './holder.sqlite', enableWAL: false })

[!TIP] You can benchmark by running npm run test:bench

| Task Name | ops/sec | Average Time (ns) | Margin | Samples | |-----------|----------|--------------------|----------|---------| | 'memory' | '64,429' | 15520.905412115228 | '±0.68%' | 32224 | | 'disk' | '3,999' | 250002.6559999995 | '±0.73%' | 2000 | | 'diskWAL' | '40,473' | 24707.3802935224 | '±0.77%' | 20237 |

Performed on Macbook Pro M1 with 16 GB Memory

Bind Topic / Shorthand

Calling .bind('myTopic') on your hold-this instance, will return a modified instance that has topic already defined on set/get methods.

import hold from 'hold-this'

const holder = holder().bind('accounts')
holder.set('account-123:user-123:name', 'Alice')
holder.get('account-123:user-456:name', 'Bob')

console.log(holder.get('account-123:*:name'))
// => [['account-123:user-123:name', 'Alice'], ['account-123:user-456:name', 'Bob']]

Serialization

When passing the value with .set, if the value is not a string, the data will be serialized with serialize-javascript and then stored. Passing an options object like { isJSON: true }, with a proper JSON object, will signal to the serializer to use a faster mechanism.

import hold from 'hold-this'

const holder = holder().bind('accounts')
holder.set('account-123:user-123:name', { firstName: 'Alice' }, { isJSON: true })
holder.get('account-123:user-456:name', 'Bob')

console.log(holder.get('account-123:*:name'))
// => [['account-123:user-123:name', { firstName: 'Alice' }], ['account-123:user-456:name', 'Bob']]

TTTL / Expiring Records

When setting a record, specifying in a options object { ttl: 1000 } will set a date in the future where the record will no longer be retrievable. Note: TTL value is set in milliseconds.

import hold from 'hold-this'

const holder = hold()
holder.set('accounts', 'account-123:user-123:name', 'Alice', { ttl: 1000 })
holder.set('accounts', 'account-123:user-456:name', 'Bob', { ttl: 0 })

console.log(holder.get('accounts', 'account-123:*:name'))
// => [['account-123:user-123:name', 'Alice']]

After a period of time, it is recommended to clean out expired records from the store. This can be achieved by calling .clean() on the instance which will remove all expired records from all topics. If a topic parameter is provided .clean('myTopic'), only this topic's expired records will be removed.

import hold from 'hold-this'

const holder = hold()
holder.set('accounts', 'account-123:user-123:name', 'Alice', { ttl:  })

holder.clean()