modules/search/query.js
function _getTripsFromStop(db, stop, tripSearchDate, callback) {

  // List of trips to return
  let rtn = [];

  // Set counters
  let done = 0;
  let count = 0;

  // Build Service ID String
  let serviceIdString = "'" + tripSearchDate.serviceIds.join("', '") + "'";

  // Get Trip IDs
  let select = "SELECT gtfs_stop_times.trip_id " +
    "FROM gtfs_stop_times " +
    "INNER JOIN gtfs_trips ON gtfs_stop_times.trip_id=gtfs_trips.trip_id " +
    "WHERE stop_id='" + stop.id + "' AND " +
    "departure_time_seconds >= " + tripSearchDate.preSeconds + " AND departure_time_seconds <= " + tripSearchDate.postSeconds + " AND " +
    "pickup_type <> " + StopTime.PICKUP_TYPE_NONE + " AND " +
    "gtfs_trips.service_id IN (" + serviceIdString + ")";

  // Select the Trip IDs
  db.select(select, function(err, results) {

    // Database Query Error
    if ( err ) {
      return callback(
        new Error('Could not get Trip(s) from database')
      );
    }

    // No Results
    if ( results.length === 0 ) {
      return callback(null, rtn);
    }

    // Set the counter
    count = results.length;

    // Build the Trips
    for ( let i = 0; i < results.length; i++ ) {
      TripsTable.getTrip(db, results[i].trip_id, tripSearchDate.date, function(err, trip) {

        // Database Query Error
        if ( err ) {
          return callback(err);
        }

        // Add trip to list
        rtn.push(trip);

        // Finish Process the Trip
        _finish();

      });
    }

  });


  /**
   * Finished Processing Trip
   * @private
   */
  function _finish() {
    done++;
    if ( done === count ) {
      return callback(null, rtn);
    }
  }

}
function _getTripsFromStop(db, stop, tripSearchDate, callback) {

  // List of trips to return
  let rtn = [];

  // Set counters
  let done = 0;
  let count = 0;

  // Build Service ID String
  let serviceIdString = "'" + tripSearchDate.serviceIds.join("', '") + "'";

  // Get Trip IDs
  let select = "SELECT gtfs_stop_times.trip_id " +
    "FROM gtfs_stop_times " +
    "INNER JOIN gtfs_trips ON gtfs_stop_times.trip_id=gtfs_trips.trip_id " +
    "WHERE stop_id='" + stop.id + "' AND " +
    "departure_time_seconds >= " + tripSearchDate.preSeconds + " AND departure_time_seconds <= " + tripSearchDate.postSeconds + " AND " +
    "pickup_type <> " + StopTime.PICKUP_TYPE_NONE + " AND " +
    "gtfs_trips.service_id IN (" + serviceIdString + ")";

  // Select the Trip IDs
  db.select(select, function(err, results) {

    // Database Query Error
    if ( err ) {
      return callback(
        new Error('Could not get Trip(s) from database')
      );
    }

    // No Results
    if ( results.length === 0 ) {
      return callback(null, rtn);
    }

    // Set the counter
    count = results.length;

    // Build the Trips
    for ( let i = 0; i < results.length; i++ ) {
      TripsTable.getTrip(db, results[i].trip_id, tripSearchDate.date, function(err, trip) {

        // Database Query Error
        if ( err ) {
          return callback(err);
        }

        // Add trip to list
        rtn.push(trip);

        // Finish Process the Trip
        _finish();

      });
    }

  });


  /**
   * Finished Processing Trip
   * @private
   */
  function _finish() {
    done++;
    if ( done === count ) {
      return callback(null, rtn);
    }
  }

}
function _getTripsFromStop ( db , stop , tripSearchDate , callback ) { // List of trips to return let rtn = [ ] ; // Set counters let done = 0 ; let count = 0 ; // Build Service ID String let serviceIdString = "'" + tripSearchDate . serviceIds . join ( "', '" ) + "'" ; // Get Trip IDs let select = "SELECT gtfs_stop_times.trip_id " + "FROM gtfs_stop_times " + "INNER JOIN gtfs_trips ON gtfs_stop_times.trip_id=gtfs_trips.trip_id " + "WHERE stop_id='" + stop . id + "' AND " + "departure_time_seconds >= " + tripSearchDate . preSeconds + " AND departure_time_seconds <= " + tripSearchDate . postSeconds + " AND " + "pickup_type <> " + StopTime . PICKUP_TYPE_NONE + " AND " + "gtfs_trips.service_id IN (" + serviceIdString + ")" ; // Select the Trip IDs db . select ( select , function ( err , results ) { // Database Query Error if ( err ) { return callback ( new Error ( 'Could not get Trip(s) from database' ) ) ; } // No Results if ( results . length === 0 ) { return callback ( null , rtn ) ; } // Set the counter count = results . length ; // Build the Trips for ( let i = 0 ; i < results . length ; i ++ ) { TripsTable . getTrip ( db , results [ i ] . trip_id , tripSearchDate . date , function ( err , trip ) { // Database Query Error if ( err ) { return callback ( err ) ; } // Add trip to list rtn . push ( trip ) ; // Finish Process the Trip _finish ( ) ; } ) ; } } ) ; /**
   * Finished Processing Trip
   * @private
   */ function _finish ( ) { done ++ ; if ( done === count ) { return callback ( null , rtn ) ; } } }
Get the Trips within the TripSearchDate range from the specified Stop
@param {RightTrackDB} db The Right Track DB to query
@param {Stop} stop The reference Stop
@param {TripSearchDate} tripSearchDate The Trip Search Date
@param {function} callback Callback function(err, trips)
@private
Get the Trips within the TripSearchDate range from the specified Stop