Skip to content

Commit

Permalink
Rename QueryResult to MysqlResult
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonFrings committed Nov 24, 2023
1 parent 9e01898 commit 1cd32d4
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 49 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ require __DIR__ . '/vendor/autoload.php';
$mysql = new React\MySQL\MysqlClient('user:pass@localhost/bookstore');

$mysql->query('SELECT * FROM book')->then(
function (React\MySQL\QueryResult $command) {
function (React\MySQL\MysqlResult $command) {
print_r($command->resultFields);
print_r($command->resultRows);
echo count($command->resultRows) . ' row(s) in set' . PHP_EOL;
Expand Down Expand Up @@ -202,10 +202,10 @@ given event loop instance.

#### query()

The `query(string $query, array $params = []): PromiseInterface<QueryResult>` method can be used to
The `query(string $query, array $params = []): PromiseInterface<MysqlResult>` method can be used to
perform an async query.

This method returns a promise that will resolve with a `QueryResult` on
This method returns a promise that will resolve with a `MysqlResult` on
success or will reject with an `Exception` on error. The MySQL protocol
is inherently sequential, so that all queries will be performed in order
and outstanding queries will be put into a queue to be executed once the
Expand All @@ -225,7 +225,7 @@ unknown or known to be too large to fit into memory, you should use the
[`queryStream()`](#querystream) method instead.

```php
$mysql->query($query)->then(function (QueryResult $command) {
$mysql->query($query)->then(function (React\MySQL\MysqlResult $command) {
if (isset($command->resultRows)) {
// this is a response to a SELECT etc. with some rows (0+)
print_r($command->resultFields);
Expand Down
2 changes: 1 addition & 1 deletion examples/01-query.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
$mysql = new React\MySQL\MysqlClient(getenv('MYSQL_URI') ?: 'test:test@localhost/test');

$query = isset($argv[1]) ? $argv[1] : 'select * from book';
$mysql->query($query)->then(function (React\MySQL\QueryResult $command) {
$mysql->query($query)->then(function (React\MySQL\MysqlResult $command) {
if (isset($command->resultRows)) {
// this is a response to a SELECT etc. with some rows (0+)
print_r($command->resultFields);
Expand Down
2 changes: 1 addition & 1 deletion examples/11-interactive.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

$time = microtime(true);
$mysql->query($query)->then(function (React\MySQL\QueryResult $command) use ($time) {
$mysql->query($query)->then(function (React\MySQL\MysqlResult $command) use ($time) {
if (isset($command->resultRows)) {
// this is a response to a SELECT etc. with some rows (0+)
echo implode("\t", array_column($command->resultFields, 'name')) . PHP_EOL;
Expand Down
6 changes: 3 additions & 3 deletions src/Io/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use React\MySQL\Commands\QueryCommand;
use React\MySQL\Commands\QuitCommand;
use React\MySQL\Exception;
use React\MySQL\QueryResult;
use React\MySQL\MysqlResult;
use React\Promise\Deferred;
use React\Promise\Promise;
use React\Socket\ConnectionInterface as SocketConnectionInterface;
Expand Down Expand Up @@ -79,7 +79,7 @@ public function query($sql, array $params = [])
$rows[] = $row;
});
$command->on('end', function () use ($command, $deferred, &$rows) {
$result = new QueryResult();
$result = new MysqlResult();
$result->resultFields = $command->fields;
$result->resultRows = $rows;
$result->warningCount = $command->warningCount;
Expand All @@ -94,7 +94,7 @@ public function query($sql, array $params = [])
$deferred->reject($error);
});
$command->on('success', function () use ($command, $deferred) {
$result = new QueryResult();
$result = new MysqlResult();
$result->affectedRows = $command->affectedRows;
$result->insertId = $command->insertId;
$result->warningCount = $command->warningCount;
Expand Down
10 changes: 5 additions & 5 deletions src/MysqlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ function () use ($connection) {
/**
* Performs an async query.
*
* This method returns a promise that will resolve with a `QueryResult` on
* This method returns a promise that will resolve with a `MysqlResult` on
* success or will reject with an `Exception` on error. The MySQL protocol
* is inherently sequential, so that all queries will be performed in order
* and outstanding queries will be put into a queue to be executed once the
Expand All @@ -171,7 +171,7 @@ function () use ($connection) {
* [`queryStream()`](#querystream) method instead.
*
* ```php
* $mysql->query($query)->then(function (QueryResult $command) {
* $mysql->query($query)->then(function (React\MySQL\MysqlResult $command) {
* if (isset($command->resultRows)) {
* // this is a response to a SELECT etc. with some rows (0+)
* print_r($command->resultFields);
Expand Down Expand Up @@ -204,8 +204,8 @@ function () use ($connection) {
*
* @param string $sql SQL statement
* @param array $params Parameters which should be bound to query
* @return PromiseInterface<QueryResult>
* Resolves with a `QueryResult` on success or rejects with an `Exception` on error.
* @return PromiseInterface<MysqlResult>
* Resolves with a `MysqlResult` on success or rejects with an `Exception` on error.
*/
public function query($sql, array $params = [])
{
Expand All @@ -216,7 +216,7 @@ public function query($sql, array $params = [])
return $this->connecting()->then(function (Connection $connection) use ($sql, $params) {
$this->awake();
return $connection->query($sql, $params)->then(
function (QueryResult $result) {
function (MysqlResult $result) {
$this->idle();
return $result;
},
Expand Down
2 changes: 1 addition & 1 deletion src/QueryResult.php → src/MysqlResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace React\MySQL;

class QueryResult
class MysqlResult
{
/**
* last inserted ID (if any)
Expand Down
10 changes: 5 additions & 5 deletions tests/MysqlClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use React\MySQL\Io\Connection;
use React\MySQL\MysqlClient;
use React\MySQL\QueryResult;
use React\MySQL\MysqlResult;
use React\Promise\Deferred;
use React\Promise\Promise;
use React\Promise\PromiseInterface;
Expand Down Expand Up @@ -308,7 +308,7 @@ public function testQueryWillQueryUnderlyingConnectionWhenResolved()

public function testQueryWillResolveAndStartTimerWithDefaultIntervalWhenQueryFromUnderlyingConnectionResolves()
{
$result = new QueryResult();
$result = new MysqlResult();

$base = $this->getMockBuilder('React\MySQL\Io\Connection')->disableOriginalConstructor()->getMock();
$base->expects($this->once())->method('query')->with('SELECT 1')->willReturn(\React\Promise\resolve($result));
Expand All @@ -331,7 +331,7 @@ public function testQueryWillResolveAndStartTimerWithDefaultIntervalWhenQueryFro

public function testQueryWillResolveAndStartTimerWithIntervalFromIdleParameterWhenQueryFromUnderlyingConnectionResolves()
{
$result = new QueryResult();
$result = new MysqlResult();

$base = $this->getMockBuilder('React\MySQL\Io\Connection')->disableOriginalConstructor()->getMock();
$base->expects($this->once())->method('query')->with('SELECT 1')->willReturn(\React\Promise\resolve($result));
Expand All @@ -354,7 +354,7 @@ public function testQueryWillResolveAndStartTimerWithIntervalFromIdleParameterWh

public function testQueryWillResolveWithoutStartingTimerWhenQueryFromUnderlyingConnectionResolvesAndIdleParameterIsNegative()
{
$result = new QueryResult();
$result = new MysqlResult();

$base = $this->getMockBuilder('React\MySQL\Io\Connection')->disableOriginalConstructor()->getMock();
$base->expects($this->once())->method('query')->with('SELECT 1')->willReturn(\React\Promise\resolve($result));
Expand All @@ -377,7 +377,7 @@ public function testQueryWillResolveWithoutStartingTimerWhenQueryFromUnderlyingC

public function testQueryBeforePingWillResolveWithoutStartingTimerWhenQueryFromUnderlyingConnectionResolvesBecausePingIsStillPending()
{
$result = new QueryResult();
$result = new MysqlResult();
$deferred = new Deferred();

$base = $this->getMockBuilder('React\MySQL\Io\Connection')->disableOriginalConstructor()->getMock();
Expand Down
10 changes: 5 additions & 5 deletions tests/NoResultQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

use React\EventLoop\Loop;
use React\MySQL\MysqlClient;
use React\MySQL\QueryResult;
use React\MySQL\MysqlResult;

class NoResultQueryTest extends BaseTestCase
{
Expand All @@ -27,7 +27,7 @@ public function testUpdateSimpleNonExistentReportsNoAffectedRows()
{
$connection = $this->createConnection(Loop::get());

$connection->query('update book set created=999 where id=999')->then(function (QueryResult $command) {
$connection->query('update book set created=999 where id=999')->then(function (MysqlResult $command) {
$this->assertEquals(0, $command->affectedRows);
});

Expand All @@ -39,7 +39,7 @@ public function testInsertSimpleReportsFirstInsertId()
{
$connection = $this->createConnection(Loop::get());

$connection->query("insert into book (`name`) values ('foo')")->then(function (QueryResult $command) {
$connection->query("insert into book (`name`) values ('foo')")->then(function (MysqlResult $command) {
$this->assertEquals(1, $command->affectedRows);
$this->assertEquals(1, $command->insertId);
});
Expand All @@ -53,7 +53,7 @@ public function testUpdateSimpleReportsAffectedRow()
$connection = $this->createConnection(Loop::get());

$connection->query("insert into book (`name`) values ('foo')");
$connection->query('update book set created=999 where id=1')->then(function (QueryResult $command) {
$connection->query('update book set created=999 where id=1')->then(function (MysqlResult $command) {
$this->assertEquals(1, $command->affectedRows);
});

Expand All @@ -75,7 +75,7 @@ public function testCreateTableAgainWillAddWarning()
PRIMARY KEY (`id`)
)';

$connection->query($sql)->then(function (QueryResult $command) {
$connection->query($sql)->then(function (MysqlResult $command) {
$this->assertEquals(1, $command->warningCount);
});

Expand Down
Loading

0 comments on commit 1cd32d4

Please sign in to comment.