Skip to content

Commit

Permalink
toDbQuery()?
Browse files Browse the repository at this point in the history
  • Loading branch information
forrest79 committed Nov 14, 2024
1 parent 0e9e2d2 commit ce744ca
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 138 deletions.
2 changes: 1 addition & 1 deletion docs/db.md
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ dump($cnt); // (integer) 7
```php
$departmentsQuery = Forrest79\PhPgSql\Db\Sql\DefaultQuery::createArgs('SELECT id FROM departments WHERE id = ?', [1]);

$query = $departmentsQuery->createDbQuery();
$query = $departmentsQuery->toDbQuery();

dump($query->sql); // (string) 'SELECT id FROM departments WHERE id = $1'
dump($query->params); // (array) [1]
Expand Down
2 changes: 1 addition & 1 deletion docs/fluent.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ $query = $fluent
->select(['*'])
->from('users')
->where('id', 1)
->createDbQuery();
->toDbQuery();

dump($query->sql); // (string) 'SELECT * FROM users WHERE id = $1'
dump($query->params); // (array) [1]
Expand Down
2 changes: 1 addition & 1 deletion phpcs-ignores.neon
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ ignoreErrors:

-
sniff: Squiz.Scope.MethodScope.Missing
message: Visibility must be declared on method "createDbQuery"
message: Visibility must be declared on method "toDbQuery"
count: 1
path: src/Db/Sql/Query.php

Expand Down
2 changes: 1 addition & 1 deletion src/Db/Sql/DefaultQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class DefaultQuery extends Expression implements Query
private Db\Query|NULL $dbQuery = NULL;


public function createDbQuery(): Db\Query
public function toDbQuery(): Db\Query
{
if ($this->dbQuery === NULL) {
$this->dbQuery = Db\SqlDefinition::createQuery($this->getSqlDefinition());
Expand Down
2 changes: 1 addition & 1 deletion src/Db/Sql/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@
interface Query extends Db\Sql
{

function createDbQuery(): Db\Query;
function toDbQuery(): Db\Query;

}
2 changes: 1 addition & 1 deletion src/Fluent/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ public function getSqlDefinition(): Db\SqlDefinition
}


public function createDbQuery(): Db\Query
public function toDbQuery(): Db\Query
{
if ($this->dbQuery === NULL) {
$this->dbQuery = Db\SqlDefinition::createQuery($this->getSqlDefinition());
Expand Down
2 changes: 1 addition & 1 deletion tests/Integration/DocsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static function dump(mixed $var): string

return \sprintf('(%s) [%s]', $type, \implode(', ', $isList ? $list : $array));
} else if ($var instanceof Fluent\Query) {
$query = $var->createDbQuery();
$query = $var->toDbQuery();
return '(Query) ' . $query->sql . ($query->params === [] ? '' : \sprintf(' [Params: %s]', self::dump($query->params)));
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Unit/FluentConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testCreateQuery(): void
->createQuery()
->select(['column'])
->from('table')
->createDbQuery();
->toDbQuery();

Tester\Assert::same('SELECT column FROM table', $query->sql);
Tester\Assert::same([], $query->params);
Expand Down Expand Up @@ -58,7 +58,7 @@ protected function prepareSql(string $sql, array $params): Db\SqlDefinition
->createQuery()
->select(['column'])
->from('table')
->createDbQuery();
->toDbQuery();

Tester\Assert::same('SELECT custom_column FROM $1', $query->sql);
Tester\Assert::same(['custom_table'], $query->params);
Expand Down
Loading

0 comments on commit ce744ca

Please sign in to comment.