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

azul-tracker

v0.1.0

Published

Azul.js Query Tracker

Downloads

2

Readme

Azul.js Tracker

NPM version Build status Code Climate Coverage Status Dependencies devDependencies

A query tracking utility for Azul.js that reports un-executed queries to help catch mistakes during development.

Overhead

There is significant overhead when using this tool, and it is strongly advised to never enable it in production. You may want to disable it when testing as well if you have a large test suite.

Examples

require('azul-tracker')(db.query);

// executed query will not generate a warning
Article.objects.insert().execute();

// pinned query will not generate a warning
var publishedArticles = Article.objects.where({ published: true }).pin();

// un-pinned query will generate a warning
var publishedArticles = Article.objects.where({ published: true });

Multiple methods in Azul.js execute a query. These include:

  • execute
  • fetch
  • fetchOne
  • find
  • findOrCreate
  • then

Sometimes you'll still want to create queries that are not executed immediately (before the next event loop iteration). This may be useful when promises are built across multiple asynchronous events:

var articles = Article.objects.pin();
var promise = Promise.resolve(); // empty promise to start things off

if (req.session.userId) {
  // if the user is logged in, look up the user from the database
  promise = promise.then(function() {
    return User.objects.find(req.session.userId);
  })
  .then(function(user) {
    // if the user isn't an administrator, show them just their articles
    if (!user.isAdmin) {
      articles = articles.where({ author: user }).pin();
    }
  });
}
else {
  // when the user is not logged in, just show public articles
  articles = articles.where({ public: true }).pin();
}

// resolve any promises made up until this point & continue
promise.then(function() {
  return articles.fetch();
})
.then(function(articles) {
  res.send({ articles: articles });
})

API

azulTracker(query, [options])

query

Type: Query

An Azul.js query object. The query and all queries that are derived from it will be tracked to ensure they are executed. Usually you'll want this to be your main query instance, db.query. Additionally, this will add new track and pin methods to all queries.

options.start

Type: Boolean
Default: true in development & test environments

Whether the tracking is automatically started or not. If you use pinned queries in development, you can simply not start the tracker in production. The pin method has very low overhead, and tracking (which has high overhead) will never begin.

The environment is determined from process.env.NODE_ENV and assumed to be development if this environment variable is not set.

options.log

Type: Function
Default: console.log

The function that will be called with logging output. This should function the same way that console.log does.

Query.track([options])

Enable tracking for a specific query object & all derived queries. This may be useful to only track queries in a specific section of your code base.

Usually you will not need to call this directly since tracking will automatically begin when calling azulTracker.

options.log

Same as azulTracker.options.log.

Query.pin()

Mark a query as pinned, that is it's known to be un-executed at this time. You'll likely do this for base queries that you will build other queries from at a later time.

This does not disable tracking for derived queries, just for this one query.

License

This project is distributed under the MIT license.