Measure the queries execution time and show in console

@param  array  $queries  CI Database queries
@param  array  $times    CI Database query execution times
@return array            Returns a set of total exec time and the amount of queries.
485356
protected function measureQueries(array $queries, array $times)
    {
        $query_exec_time = 0;
        $exec_queries    = 0;

        $this->newLine();

        for ($i = 0; $i < count($queries); $i++)
        {
            $this->text(sprintf('<comment>-></comment> %s', $queries[$i]));
            $query_exec_time += $times[$i];
            $exec_queries += 1;
        }
        return array($query_exec_time, $exec_queries);
    }
355332
public function select($query, $bindings = array()) {
        return $this->run($query, $bindings, function(self $me, $query, array $bindings) {
                    if ($me->pretending())
                        return array();
                    // For select statements, we'll simply execute the query and return an array
                    // of the database result set. Each element in the array will be a single
                    // node from the database, and will either be an array or objects.
                     $statement = $me->getBatchQuery($query, $bindings);
                    return $statement->getResultSet();
                    
                    // $statement = $me->getCypherQuery($query, $bindings);
                    // return $statement->getResultSet();

                });
    }
676141
public static function minOf(LocalDateTime ...$times) : LocalDateTime
    {
        if (! $times) {
            throw new DateTimeException(__METHOD__ . ' does not accept less than 1 parameter.');
        }

        $min = LocalDateTime::max();

        foreach ($times as $time) {
            if ($time->isBefore($min)) {
                $min = $time;
            }
        }

        return $min;
    }
791202
public function log($query, $bindings, $time)
    {
        static $queryNr = 0;

        ++$queryNr;

        try {
            list($sqlQuery, $execTime) =
                $this->getSqlQuery($query, $bindings, $time);
        } catch (\Exception $e) {
            $this->app->log->notice("SQL query {$queryNr} cannot be bound: " .
                $query);

            return;
        }

        $logData = $this->getLogData($queryNr, $sqlQuery, $execTime);

        $this->save($logData, $execTime, $queryNr);
    }
53712
public function logQuery( string $query, array $bindings, $time = null )
	{
		$this->queries ++;
		if( $time )
		{
			$this->timing += $time;
		}
		if( isset( $this->events ) )
		{
			$this->events->dispatch( new Events\QueryExecutedEvent( $this, $query, $bindings, $time ?? 0 ) );
		}
		if( $this->loggingQueries )
		{
			$this->queryLog[] = compact( 'query', 'bindings', 'time' );
		}
	}
1295023
public static function sort(array $timeSlots) {

        // Initialize a Qucik sort.
        $sorter = new QuickSort($timeSlots, new TimeSlotFunctor());
        $sorter->sort();

        // Return the time slots.
        return $sorter->getValues();
    }
1014270
public function statements($query, $statements)
    {
        try {
            $query = $this->conn->prepare($query);

            foreach ($statements as $key => $value) {
                $param = $statements[$key][0];
                $value = $statements[$key][1];
                $ifExists = (isset($statements[$key][2]));
                $dataType = $ifExists ? $statements[$key][2] : false;

                switch ($dataType) {
                    case 'bool':
                        $query->bindValue($param, $value, \PDO::PARAM_BOOL);
                        continue;
                    case 'null':
                        $query->bindValue($param, $value, \PDO::PARAM_NULL);
                        continue;
                    case 'int':
                        $query->bindValue($param, $value, \PDO::PARAM_INT);
                        continue;
                    case 'str':
                        $query->bindValue($param, $value, \PDO::PARAM_STR);
                        continue;
                }

                $query->bindValue($param, $value);
            }

            $query->execute();

            return $query;
        } catch (\PDOException $e) {
            $this->error = $e->getMessage();

            return null;
        }
    }
233882
private function getElements(array $queries, StorageInterface $storage)
    {
        $elements = [];
        foreach ($queries as $query) {
            $elements[] = $this->getInterpreter($query)->visit($query, $storage);
        }

        return $elements;
    }
770209
private function prepareTime(string $times)
    {
        foreach (preg_split('/\W/i', $times) as $time) {
            $this->getDatePart($time);
        }
    }
1106947
public function prepareArguments(array $queries)
    {
        $arguments = [];

        foreach ($queries as $key => $value) {
            $arguments[$key] = $this->prepareQuery($value);
        }

        return $arguments;
    }
185132
public function addQueries($queries) {
        if(is_array($queries)) {
            foreach($queries as $query) {
                $this->addQuery($query);
            }

            new Logger('Queries added to the queue.', Logger::DEBUG, __CLASS__, __LINE__);
            return $this;
        }

        new Logger('Failed to add to the queue.', Logger::ERROR, __CLASS__, __LINE__);
        return $this;
    }
1029647
public function addQueries(array $queries = array()) {
	    foreach($queries as $queryInfo) {
	        $batchAction = (isset($queryInfo[1])) ? $queryInfo[1] : null;
	        $this->addQuery($queryInfo[0], $batchAction);
	    }
	}
1098028
protected function execute($sql, $bindings = array())
		{
			$bindings = (array) $bindings;

			// Since expressions are injected into the query as strings, we need to
			// remove them from the array of bindings. After we have removed them,
			// we'll reset the array so there aren't gaps in the keys.
			$bindings = array_values(array_filter($bindings, function($binding) {
				return ! $binding instanceof Expression;
			}));

			$sql = $this->grammar()->shortcut($sql, $bindings);

			$statement = $this->pdo->prepare($sql);

			// Every query is timed so that we can log the executinon time along
			// with the query SQL and array of bindings. This should be make it
			// convenient for the developer to profile performance.
			$time = microtime(true);

			$result = $statement->execute($bindings);

			$time = number_format((microtime(true) - $time) * 1000, 2);

			// Once we have execute the query, we log the SQL, bindings, and
			// execution time in a static array that is accessed by all of
			// the connections used by the application.
			$this->log($sql, $bindings, $time);

			return array($statement, $result);
		}
1190916
protected function _appendQuery(array $vals = NULL, string $sql, int $totalTime)
	{
		$evals = \is_array($vals) ? $vals : [];
		$esql = str_replace('?', "%s", $sql);

		// Quote string values
		foreach($evals as &$v)
		{
			$v = ( ! is_numeric($v))
				? htmlentities($this->driver->quote($v), ENT_NOQUOTES, 'utf-8')
				: $v;
		}

		// Add the query onto the array of values to pass
		// as arguments to sprintf
		array_unshift($evals, $esql);

		// Add the interpreted query to the list of executed queries
		$this->queries[] = [
			'time' => $totalTime,
			'sql' => sprintf(...$evals)
		];

		$this->queries['total_time'] += $totalTime;

		// Set the last query to get rowcounts properly
		$this->driver->setLastQuery($sql);
	}
243861
public function getQueryTimes($execute = false)
    {
        return $execute ? Db::$queryTimes + Db::$executeTimes : Db::$queryTimes;
    }
396812
public function query(string $sql, array $values = []): int
    {
        return $this->dbConnection->prepare($sql)
                ->execute($values)
                ->count();
    }
220587
protected function filterQueries($queries)
    {
        $app = Application::getFacadeApplication();
        $config = $app->make('config');

        $textIndexDrops = [];
        foreach ($config->get('database.text_indexes') as $indexTable => $indexDefinition) {
            foreach (array_keys($indexDefinition) as $indexName) {
                $textIndexDrops[] = strtolower("DROP INDEX {$indexName} ON {$indexTable}");
            }
        }

        $returnQueries = [];
        foreach ($queries as $query) {
            $queryLowerCase = strtolower($query);
            if (!in_array($queryLowerCase, $textIndexDrops, true)) {
                $returnQueries[] = $query;
            }
        }

        return $returnQueries;
    }