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

@fvlab/postgresqlconfigurationstore

v1.0.3

Published

Configuration Store wrapper for PostgreSQL.

Downloads

6

Readme

PostgreSQLConfigurationStore

Simple application settings or document storage using PostgreSQL. Global configurations will be stored under /internal/global/ and user-specific configurations will be stored under /internal/user/<userId>. The paths can be configured by passing optional arguments to the constructor.

NPM Package

Usage

Building

To build the project run the command below.

npm run build

Testing

Testing is done via test.ts which is currently a scratchpad for various operations.

npm run test

Initialization

Before anything can be read or written to PostgreSQL the library must be initialized. This is a necessary step to setup the Firebase configuration. There are two types of initialization available.

Initialize with Options

The first type of initialization available allows the library to be initialized with connection information. The bare minimum to include is

{
	host: "localhost", // PostgreSQL host.
	port: 5432, // PostgreSQL host.
	database: "config_store", // PostgreSQL database to store configuration.
	user: "username", // Username to connect with.
	password: "password" // Password to connect with.
}

If you'd like to overwrite the default table the configuration is written to, config, supply the tableName property with the configuration.

Connections are made with pg, for more options see their documentation.

public init(config?: PostgreSqlConfiguration): this

Initialize with a JSON File

Coming Soon

The second type of initialization available allows the library to be initialized with an preexisting JSON file that contains the configuration. The format is the same as a above,

{
	"host": "localhost", // PostgreSQL host.
	"port": 5432, // PostgreSQL host.
	"database": "config_store", // PostgreSQL database to store configuration.
	"user": "username", // Username to connect with.
	"password": "password" // Password to connect with.
}

If you'd like to overwrite the default table the configuration is written to, config, supply the tableName property with the configuration.

Connections are made with pg, for more options see their documentation.

public init(): this

Create and initialize the object.

const currentUserId = '1234';
const settings = new PostgreSqlConfigurationStore(
	currentUserId,
	'/custom/pathToGlobalConfig/',
	'/custom/pathToUserConfig'
);
return settings.init();

Retrieve values by key or get it's default value if a value doesn't exist for the key.

return settings.getGlobalData('someKey', 'default value')
.then(globalValue => ...);
return settings.getUserData('someOtherKey', 'default value')
.then(userValue => ...);

Set the key-value pair.

return settings.setGlobalData('someKey', 'some value')
.then(globalValue => ...);
return settings.setUserData('someOtherKey', 'some value')
.then(userValue => ...);

Update the Data Stored in the Specified Path

return settings.updateGlobalData('somePath', 'some value')
.then(globalValue => ...);
return settings.updateGlobalData('someOtherPath', 'some value')
.then(userValue => ...);

Supported operations

  1. Forward-slash separated path

    return settings.setGlobalData('some/other/path', 'some value')
    .then(globalValue => ...);
  2. Object / Array value

    return settings
     .updateGlobalData('somePath', { child1: "value1", child2: 42})
     .then(globalValue => ...);
    return settings
     .setGlobalData('somePath', [4, 2])
     .then(globalValue => ...);
  3. set operations only create. update operations overwrite existing data at the path.

    // Current Config Store
    "apiKeys": {
      "someService": "some-api-key"
    }
    settings.updateGlobalData('apiKeys', { someOtherService: 'some-other-api-key' });
    
    // Expected Config Store
    "apiKeys": {
      "someService": "some-api-key",
      "someOtherService": "some-other-api-key"
    }
    settings.setGlobalData('apiKeys', { anotherService: 'another-api-key' });
    
    // Expected Config Store
    "apiKeys": {
      "anotherService": "another-api-key"
    }