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

gtfsdb

v0.1.3

Published

High-performance GTFS database

Downloads

10

Readme

The challenge with GTFS

GTFS files can be huge. Relations between files are handled with strings which adds to even worse performance if used as it is. Usually it is more useful only to parse the relevant information from the files to a custom format but what if you need all of the files? The NoSQL based solutions work well with custom data structure but generally they don't scale when the same data is used multiple ways.

GTFS file format works well with relational database as it is structed in such way. Then why not use it the way it is?

GTFSdb

GTFSdb is a database abstraction that deals with GTFS files. It is designed to support huge GTFS files with minimal memory overhead. GTFSdb was inspired by node-GTFS and should be a drop-in-replacement only with some minor changes to the code.

For GTFSdb to work it needs Knex.js with the underlying database (PostgreSQL, MariaDB, MySQL, SQLite). So far GTFSdb has only been tested with PostgreSQL.

Example application

An example application can be found here: gtfsdb-example

Installation

Instructions are updated here once the package hits npm. In the meantime GTFSdb can be either copied to your project or used as a submodule.

Configuration

GTFSdb needs to be configured with an instance of Knex.js to enable the database connection. For more information on how to make Knex.js work, please refer to its guide. In your Node.js application you can configure GTFSdb in the following way:

// First get an instance of Knex.
var knex = require('knex')({
  client: 'pg',
  connection: process.env.PG_CONNECTION_STRING,
  searchPath: 'knex,public'
});
// Then load the library
var gtfsdb = require('gtfsdb')(knex);

Schema migrations

For schema creation GTFSdb includes migration scripts. To get the latest schema specify a knexfile.js with a following key:

    migrations: {
        directory: './path/to/gtfsdb/migrations'
    }

And then run:

knex migrate:latest

Data import

For data import GTFSdb provides a download utility to deal with different kinds of sources. You can use the utility directly:

var knex = /*...*/
var config = require('./config.js');
var download = require('../path/to/gtfsdb/lib/download');
/* ... */
download(knex, config).then( /* Handle the promise */ );

Or through the GTFSdb API.

GTFSdb configuration file has the same format as with its sibling. The configuration has the same format as with node-GTFS. Here's an example of config.js:

module.exports = {
  agencies: [
    /*
     * You can specify agencies in the following ways:
     * * Put agency_key names from gtfs-data-exchange.com:
     * 'bay-area-rapid-transit'
     *
     * * Specify a download URL:
     * {agency_key: 'caltrain', url: 'http://www.gtfs-data-exchange.com/agency/caltrain/latest.zip'}
     *
     * * Specify a path to a zipped GTFS file:
     * {agency_key: 'localAgency', path: '/path/to/the/gtfs.zip'}
     *
     * * Specify a path to an unzipped GTFS file:
     * {agency_key: 'localAgency', path: '/path/to/the/unzipped/gtfs/'}
     */
  ]
};

What you need to know

  • The API is still in flux; to be honest it isn't even complete yet.
  • There are no tests. None, nil, zip. There will be, however, some beautiful day.

Planned features

  • Compare the GTFS file date to avoid redundant imports.
  • Decent test coverage.
  • An example project to demonstrate the use better.