Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP Fix #3071. Add sql:fetch command #3258

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/Drupal/Commands/sql/SqlCommands.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

namespace Drush\Drupal\Commands\sql;

use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Drush\Commands\DrushCommands;

class SqlCommands extends DrushCommands
{
/**
* Fetch data via a SQL query.
*
* @command sql:fetch
* @aliases sqlf
* @usage drush sql:fetch --format=json
* Retrieve data in JSON format.
*
* @return RowsOfFields
*/
public function fetch()
{
$data = db_query('SELECT * FROM users')->fetchAll();
return new RowsOfFields($data);
}
}
5 changes: 5 additions & 0 deletions src/Drupal/Commands/sql/drush.services.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
services:
sql.commands:
class: \Drush\Drupal\Commands\sql\SqlCommands
arguments: []
tags:
- { name: drush.command }
sanitize.commands:
class: \Drush\Drupal\Commands\sql\SanitizeCommands
arguments: []
Expand Down