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

database-flow

v1.2.0

Published

Fast access database implementation: redis and postgres

Downloads

8

Readme

database-flow

Fast access implementation with redis and postgres

Feel free to open new issues here!

Installation:

npm install --save database-flow

Initialization Examples:

  1. Logging with console.log
const flow = require('database-flow')({
  modelsDir: `${__dirname}/database/models`,
  logging: console.log,
  redis: { url: process.env.REDISCLOUD_URL, helloMessage: true },
  sequelize: {
    username: 'user',
    password: '12234',
    database: 'database',
    host: '127.0.0.1',
    dialect: 'postgres',
    timezone: 'America/Argentina/Buenos_aires',
    dialectOptions: {
      useUTC: false
      ssl: {
        rejectUnauthorized: false,
      }
    },
    logging: console.log
  }
});
  1. You can log with rollbar-grouping if you want to group all the logs of an event.
const rollbar = require('rollbar-grouping')(...);
const flow = require('database-flow')({
  modelsDir: `${__dirname}/database/models`,
  logging: rollbar,
  redis: { url: process.env.REDISCLOUD_URL, helloMessage: true },
  sequelize: {
    username: 'user',
    password: '12234',
    database: 'database',
    host: '127.0.0.1',
    dialect: 'postgres',
    timezone: 'America/Argentina/Buenos_aires',
    dialectOptions: {
      useUTC: false
      ssl: {
        rejectUnauthorized: false,
      }
    },
    logging: console.log
  }
});

Usage Example:

const example = async () => {
  await flow.save('user', {
    name: 'username',
    pass: '1234',
    email: '[email protected]',
    followers: 15000,
    famous: false
  });
  //                MODEL        UPDATE                   WHERE                   
  await flow.update('user', { famous: true }, { followers: { $gt: 10000 } });
  const famousUsers = await flow.get('user', { famous: true }, ['name', 'email']);
  console.log(`These are the famous users:\nJSON.stringify(famousUsers, null, 2)`);
};
example();

Available options for WHERE value:

const where = {
  $exists: true, // The value must exist
  $eq: 3, // The value must be equal to 3
  $gt: 2, // The value must be greater than 2
  $gte: 3, // The value must be greater or equal to 2
  $lt: 5, // The value must be less than 5
  $lte: 3, // The value must be less or equal to 3
  $in: [1, 2, 3, 'hello'], // The value must be 1, 2, 3 or 'hello'
  $nin: [4, 5, 6], // The value must not be 4, 5 or 6
};
flow.get('user', { someField: where });
// where can also be an exact value like 1, 'hello', null...

Available options for UPDATE object:

Sum and subtract specified numbers

const update = {
  $sum: 5, // Will sum 5 to the field value
  $subtract: 6, // Will subtract 6 to the field value
};
flow.update('user', { someField: update }, {});
// update can also be an exact value like 1, 'hello', null...

Sum and subtract numbers from other fields

const update = {
  $sum: 'field1', // Will sum the value of the field 'field1'
  $subtract: 'field2', // Will subtract the value of the field 'field1'
};
flow.update('user', { someField: update }, {});

Dates: Sum and subtract specified time

const moment = require('moment');
const update = {
  $sumDate: { date: moment(), number: 15, unit: 'day' }, // Will sum 15 days to current date
};
flow.update('user', { someField: update }, {});

Dates: Sum and subtract time from other field

const moment = require('moment');
const update = {
  $sumDate: { date: 'someField', number: 'field1', unit: 'day' }, // Will sum the time of the field 'field1' in field 'someField'
};
flow.update('user', { someField: update }, {});