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

micro-analytics-adapter-postgres

v0.0.1

Published

Postgres adapter for Micro-Analytics

Downloads

3

Readme

micro-analytics-adapter-postgres

Use postgres to store your micro-analytics data! Huge thanks to @vitaly-t for the pg-promise library, making postgres a pleasure to work with in node.

Usage

Requires node version 8.x or later. Might consider backwards capability but I assume anyone using micro-analytics is likely relying on the latest versions of node available on Zeit's now.

npm install micro-analytics-adapter-postgres
DB_ADAPTER=postgres micro-analytics

Options

Options are set via environment variables. These are the possible options for this adapter:

POSTGRES_ANALYTICS    # fully formed postgres connection string URI starting with postgres://

Be sure to include the database name for where we will be reading/writing the analytics data.

E.g. postgres://username:password@host:port/database?ssl=false&application_name=name &fallback_application_name=name&client_encoding=encoding. All query params on the string are optional but some managed postgres providers might require ssl=true

A note on the PUT method

This was previously implemented to accept multiple views coming in on the same request i.e. a batch request.

However, it seems that this isn't the case for the current micro-analytics library. Instead, it is sending all of the old data from a prior GET request along with the new request at the end. Whilst I don't like this implementation as it will scalability issues when we only really need to append data, I'll keep it for compability with the raw code base.

Should performance issues arise, we'll raise such issues in the core micro-analytics codebase.

Testing

  1. Create a test database and table. In this example we'll call it 'analytics' see setup.sql for an example.
  2. Run test using your test database credentials as the POSTGRES_ANALYTICS env variable, e.g

POSTGRES_ANALYTICS='postgres://Todd:@localhost:5432/analytics' npm test

In this case, my localhost user is Todd and I have no password. Use your own username:password and update the database from analytics if you choose something different to test.

Note that I've not used the tests in the micro-analytics-adapter-utils library for a couple of reasons:

  • Jest wasn't working nicely and I suspect there could be additional configuration that wasn't documented
  • There seems some inconsistencies with the expected return values that don't match the docs
  • Along a similar line, it seems these aren't being actively maintained so I've decided on one less dependency
  • Because I was only tearing down the table at the end of all tests, I needed to rename unique paths to set absolute return values
  • I want to add specific tests for the postgres implementation

If micro-analytics continues to be maintained, including the test utils for consistency across adapters (great idea), we'll change the tests to use the common utils and contribute towards that package. As it stands right now, the lack of maintenance makes the scope of delivering this project larger than was needed.

License

Copyright ©️ 2018 Todd Heslin, licensed under the MIT license. See LICENSE for more information.