modules/query/StopsTable.js
function getStopByName(db, name, callback) {

  // Check cache for Stop
  let cacheKey = db.id + "-" + name;
  let cache = cache_stopByName.get(cacheKey);
  if ( cache !== null ) {
    return callback(null, cache);
  }

  // Different queries to lookup stop by name
  let queries = [
    "SELECT stop_id FROM gtfs_stops WHERE stop_name='" + name + "' COLLATE NOCASE;",
    "SELECT stop_id FROM rt_alt_stop_names WHERE alt_stop_name='" + name + "' COLLATE NOCASE;",
    "SELECT stop_id FROM rt_stops_extra WHERE display_name='" + name + "' COLLATE NOCASE;"
  ];

  // Test each query for the stop name
  let found = false;
  let count = 0;
  for ( let i = 0; i < queries.length; i++ ) {

    // Perform the specified query
    _queryForStopByName(db, queries[i], function(stop) {

      // Return the result: if not already found and the query was successful
      if ( !found && stop !== undefined ) {
        found = true;
        cache_stopByName.put(cacheKey, stop);
        return callback(null, stop);
      }

      // Return after all queries have finished
      count ++;
      if ( count === queries.length ) {
        return callback(null, undefined);
      }

    });
  }

}
function getStopByName(db, name, callback) {

  // Check cache for Stop
  let cacheKey = db.id + "-" + name;
  let cache = cache_stopByName.get(cacheKey);
  if ( cache !== null ) {
    return callback(null, cache);
  }

  // Different queries to lookup stop by name
  let queries = [
    "SELECT stop_id FROM gtfs_stops WHERE stop_name='" + name + "' COLLATE NOCASE;",
    "SELECT stop_id FROM rt_alt_stop_names WHERE alt_stop_name='" + name + "' COLLATE NOCASE;",
    "SELECT stop_id FROM rt_stops_extra WHERE display_name='" + name + "' COLLATE NOCASE;"
  ];

  // Test each query for the stop name
  let found = false;
  let count = 0;
  for ( let i = 0; i < queries.length; i++ ) {

    // Perform the specified query
    _queryForStopByName(db, queries[i], function(stop) {

      // Return the result: if not already found and the query was successful
      if ( !found && stop !== undefined ) {
        found = true;
        cache_stopByName.put(cacheKey, stop);
        return callback(null, stop);
      }

      // Return after all queries have finished
      count ++;
      if ( count === queries.length ) {
        return callback(null, undefined);
      }

    });
  }

}
function getStopByName ( db , name , callback ) { // Check cache for Stop let cacheKey = db . id + "-" + name ; let cache = cache_stopByName . get ( cacheKey ) ; if ( cache !== null ) { return callback ( null , cache ) ; } // Different queries to lookup stop by name let queries = [ "SELECT stop_id FROM gtfs_stops WHERE stop_name='" + name + "' COLLATE NOCASE;" , "SELECT stop_id FROM rt_alt_stop_names WHERE alt_stop_name='" + name + "' COLLATE NOCASE;" , "SELECT stop_id FROM rt_stops_extra WHERE display_name='" + name + "' COLLATE NOCASE;" ] ; // Test each query for the stop name let found = false ; let count = 0 ; for ( let i = 0 ; i < queries . length ; i ++ ) { // Perform the specified query _queryForStopByName ( db , queries [ i ] , function ( stop ) { // Return the result: if not already found and the query was successful if ( ! found && stop !== undefined ) { found = true ; cache_stopByName . put ( cacheKey , stop ) ; return callback ( null , stop ) ; } // Return after all queries have finished count ++ ; if ( count === queries . length ) { return callback ( null , undefined ) ; } } ) ; } }
Get the Stop specified by name from the passed database

@param {RightTrackDB} db The Right Track Database to query
@param {string} name Stop Name (found in either gtfs_stops, rt_alt_stop_names or rt_stops_extra tables)
@param {function} callback Callback function
@param {Error} callback.error Database Query Error
@param {Stop} [callback.stop] The selected Stop
Get the Stop specified by name from the passed database