server/drivers/index.js
function runQuery(query, connection, user) {
  const driver = drivers[connection.driver];

  const queryResult = {
    id: uuid.v4(),
    cacheKey: null,
    startTime: new Date(),
    stopTime: null,
    queryRunTime: null,
    fields: [],
    incomplete: false,
    meta: {},
    rows: []
  };

  return driver.runQuery(query, connection).then(results => {
    const { rows, incomplete } = results;
    if (!Array.isArray(rows)) {
      throw new Error(`${connection.driver}.runQuery() must return rows array`);
    }

    queryResult.incomplete = incomplete || false;
    queryResult.rows = rows;
    queryResult.stopTime = new Date();
    queryResult.queryRunTime = queryResult.stopTime - queryResult.startTime;
    queryResult.meta = getMeta(rows);
    queryResult.fields = Object.keys(queryResult.meta);

    if (debug) {
      const connectionName = connection.name;
      const rowCount = rows.length;
      const { startTime, stopTime, queryRunTime } = queryResult;

      console.log(
        JSON.stringify({
          userId: user && user._id,
          userEmail: user && user.email,
          connectionName,
          startTime,
          stopTime,
          queryRunTime,
          rowCount,
          query
        })
      );
    }

    return queryResult;
  });
}
function runQuery(query, connection, user) {
  const driver = drivers[connection.driver];

  const queryResult = {
    id: uuid.v4(),
    cacheKey: null,
    startTime: new Date(),
    stopTime: null,
    queryRunTime: null,
    fields: [],
    incomplete: false,
    meta: {},
    rows: []
  };

  return driver.runQuery(query, connection).then(results => {
    const { rows, incomplete } = results;
    if (!Array.isArray(rows)) {
      throw new Error(`${connection.driver}.runQuery() must return rows array`);
    }

    queryResult.incomplete = incomplete || false;
    queryResult.rows = rows;
    queryResult.stopTime = new Date();
    queryResult.queryRunTime = queryResult.stopTime - queryResult.startTime;
    queryResult.meta = getMeta(rows);
    queryResult.fields = Object.keys(queryResult.meta);

    if (debug) {
      const connectionName = connection.name;
      const rowCount = rows.length;
      const { startTime, stopTime, queryRunTime } = queryResult;

      console.log(
        JSON.stringify({
          userId: user && user._id,
          userEmail: user && user.email,
          connectionName,
          startTime,
          stopTime,
          queryRunTime,
          rowCount,
          query
        })
      );
    }

    return queryResult;
  });
}
function runQuery ( query , connection , user ) { const driver = drivers [ connection . driver ] ; const queryResult = { id : uuid . v4 ( ) , cacheKey : null , startTime : new Date ( ) , stopTime : null , queryRunTime : null , fields : [ ] , incomplete : false , meta : { } , rows : [ ] } ; return driver . runQuery ( query , connection ) . then ( results => { const { rows , incomplete } = results ; if ( ! Array . isArray ( rows ) ) { throw new Error ( ` ${ connection . driver } ` ) ; } queryResult . incomplete = incomplete || false ; queryResult . rows = rows ; queryResult . stopTime = new Date ( ) ; queryResult . queryRunTime = queryResult . stopTime - queryResult . startTime ; queryResult . meta = getMeta ( rows ) ; queryResult . fields = Object . keys ( queryResult . meta ) ; if ( debug ) { const connectionName = connection . name ; const rowCount = rows . length ; const { startTime , stopTime , queryRunTime } = queryResult ; console . log ( JSON . stringify ( { userId : user && user . _id , userEmail : user && user . email , connectionName , startTime , stopTime , queryRunTime , rowCount , query } ) ) ; } return queryResult ; } ) ; }
Run query using driver implementation of connection
@param {*} query
@param {*} connection
@param {object} [user] user may not be provided if chart links turned on
@returns {Promise}
Run query using driver implementation of connection