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

@bampich.ok/data

v1.0.1

Published

provides data access for redis and cockroachdb

Downloads

6

Readme

About

provides data access for redis and cockroachdb

Install

npm install @bampich.ok/data

Usage

const {
  RunWithClient,
  RedisClient,
  ConnectionPool
} = require('@bampich.ok/data');
const runWithClient = RunWithClient.RunWithClient;
const format = require('pg-format');

//use RedisClient the same way you would use ioredis
//check https://github.com/luin/ioredis
let redisClient = new RedisClient();
let storeUserLocation = new Promise(async (resolve, reject) => {
  redisClient.geoadd(
    "users",//data set
    0.0, //longitude
    0.0, //latitude
    "userId", //user key
    (error, result) => {
      try {
        if (error) {
          return reject(error);
        }
        return resolve("ok");
      } finally {
        redisClient.quit();
      }
    });
})
.then(result=>console.log(result))
.catch(error=> throw error);

//use RunWithClient to execute SQL statements
let readUserProfiles = return new Promise(async (resolve, reject) => {
  runWithClient(async (client) => {
    let command = format.withArray(
      'SELECT * FROM PROFILES WHERE ID = %L LIMIT 10 offset %L',
      [id, optionalOffset || 0]);
    let profiles = await client.query(command);
    await new ConnectionPool().getInstance().end(); // release the connection
    return resolve(profiles);
  }, reject);
})
.then(resultSet=>{
  resultSet.rows.map(profile=>{handleProfile(profile)});
  //release the connection if you are no longer using it
  RedisClient.instance.disconnect();
  RedisClient.instance = null;
  (new ConnectionPool()).getInstance().end();
})
.catch(error=>throw error);

Configure

The following environment variables control the configuration for cockroachDB:

  • ROACH_CERTS_FOLDER: where to find ca.crt,client.roach.key,client.roach.crt.
  • ROACH_USERNAME: (optional) user name for the roach user.
  • ROACH_SERVICE_HOST: IP address for connecting to cockroachDB.
  • ROACH_SERVICE_PORT_GRPC: port number for connecting to cockroachDB.
  • ROACH_DB_NAME: the name of the database to use within cockroachDB.

The following environment variables control the configuration for Redis:

  • STAGE_NAME: use production to provide server host and port. Otherwise localhost and 6379 are used.
  • REDIS_HOST: IP address for connecting with a redis cluster.
  • REDIS_PORT: port to establish a connection.

To run tests or run locally:

# run cockroachdb on minikube
minikube start & \
kubectl port-forward \
  service/cockroachdb-public \
  26257 \
  -n default

# run redis on your workstation
redis-server ./redis.conf