diff --git a/docs/db.md b/docs/db.md index 2853098..f9f21be 100644 --- a/docs/db.md +++ b/docs/db.md @@ -179,8 +179,8 @@ table($rowsAny); To pass another query, we need to prepare one and then use it: ```php -$query = Forrest79\PhPgSql\Db\Sql\DefaultQuery::create('SELECT id FROM users WHERE inserted_datetime::date > ?', '2020-01-02'); -$queryArgs = Forrest79\PhPgSql\Db\Sql\DefaultQuery::createArgs('SELECT id FROM users WHERE inserted_datetime::date > ?', ['2020-01-02']); +$query = Forrest79\PhPgSql\Db\Sql\Query::create('SELECT id FROM users WHERE inserted_datetime::date > ?', '2020-01-02'); +$queryArgs = Forrest79\PhPgSql\Db\Sql\Query::createArgs('SELECT id FROM users WHERE inserted_datetime::date > ?', ['2020-01-02']); $result = $connection->query('SELECT d.id, d.name FROM user_departments ud JOIN departments d ON d.id = ud.department_id WHERE ud.user_id IN (?) AND d.active ORDER BY ?', $query, Forrest79\PhPgSql\Db\Sql\Literal::create('d.id')); @@ -474,7 +474,7 @@ $connection->query('INSERT INTO users (nick) VALUES(?)', Forrest79\PhPgSql\Db\Sq Query example: ```php -$activeDepartmentsQuery = Forrest79\PhPgSql\Db\Sql\DefaultQuery::create('SELECT id FROM departments WHERE active = ?', TRUE); +$activeDepartmentsQuery = Forrest79\PhPgSql\Db\Sql\Query::create('SELECT id FROM departments WHERE active = ?', TRUE); $cnt = $connection->query('SELECT COUNT(*) FROM user_departments WHERE department_id IN (?)', $activeDepartmentsQuery)->fetchSingle(); dump($cnt); // (integer) 7 @@ -483,7 +483,7 @@ dump($cnt); // (integer) 7 `Query` has also method `createQuery()` that prepare query in the format, that can be used in `pg_*` functions. ```php -$departmentsQuery = Forrest79\PhPgSql\Db\Sql\DefaultQuery::createArgs('SELECT id FROM departments WHERE id = ?', [1]); +$departmentsQuery = Forrest79\PhPgSql\Db\Sql\Query::createArgs('SELECT id FROM departments WHERE id = ?', [1]); $query = $departmentsQuery->toDbQuery(); diff --git a/docs/fluent.md b/docs/fluent.md index 101be7a..3059a5f 100644 --- a/docs/fluent.md +++ b/docs/fluent.md @@ -294,7 +294,7 @@ $query = $connection ->add('column2', [2, 3]) // this is also add to OR ->addAndBranch() // this is also add to OR and can contains more ANDs ->add('column', $connection->createQuery()->select([1])) // this is add to AND - ->add('column2 = ANY(?)', Forrest79\PhPgSql\Db\Sql\DefaultQuery::create('SELECT 2')) // this is add to AND + ->add('column2 = ANY(?)', Forrest79\PhPgSql\Db\Sql\Query::create('SELECT 2')) // this is add to AND ->parent() // get original OR ->add('column3 IS NOT NULL') // and add to OR new condition ->query() // back to original query object @@ -824,11 +824,11 @@ You can use `WITH` with a simple string query, or defined it with `Db\Sql\Query` $query = $connection ->createQuery() ->with('active_users', 'SELECT id, nick, age, height_cm FROM users WHERE active = TRUE') - ->with('active_departments', Forrest79\PhPgSql\Db\Sql\DefaultQuery::create('SELECT id FROM departments WHERE active = ?', TRUE)) + ->with('active_departments', Forrest79\PhPgSql\Db\Sql\Query::create('SELECT id FROM departments WHERE active = ?', TRUE)) ->select(['au.id', 'au.nick', 'au.age', 'au.height_cm']) ->from('active_users', 'au') ->join('user_departments', 'ud', 'ud.department_id = au.id') - ->where('ud.department_id IN (?)', Forrest79\PhPgSql\Db\Sql\DefaultQuery::create('SELECT id FROM active_departments')); + ->where('ud.department_id IN (?)', Forrest79\PhPgSql\Db\Sql\Query::create('SELECT id FROM active_departments')); dump($query); // (Query) WITH active_users AS (SELECT id, nick, age, height_cm FROM users WHERE active = TRUE), active_departments AS (SELECT id FROM departments WHERE active = TRUE) SELECT au.id, au.nick, au.age, au.height_cm FROM active_users AS au INNER JOIN user_departments AS ud ON ud.department_id = au.id WHERE ud.department_id IN (SELECT id FROM active_departments) diff --git a/phpcs-ignores.neon b/phpcs-ignores.neon index c9e79ba..cb2d3d9 100644 --- a/phpcs-ignores.neon +++ b/phpcs-ignores.neon @@ -281,12 +281,6 @@ ignoreErrors: count: 1 path: src/Db/Sql.php - - - sniff: SlevomatCodingStandard.Classes.RequireAbstractOrFinal.ClassNeitherAbstractNorFinal - message: All classes should be declared using either the "abstract" or "final" keyword. - count: 1 - path: src/Db/Sql/DefaultQuery.php - - sniff: SlevomatCodingStandard.Classes.RequireAbstractOrFinal.ClassNeitherAbstractNorFinal message: All classes should be declared using either the "abstract" or "final" keyword. @@ -300,8 +294,8 @@ ignoreErrors: path: src/Db/Sql/Literal.php - - sniff: Squiz.Scope.MethodScope.Missing - message: Visibility must be declared on method "toDbQuery" + sniff: SlevomatCodingStandard.Classes.RequireAbstractOrFinal.ClassNeitherAbstractNorFinal + message: All classes should be declared using either the "abstract" or "final" keyword. count: 1 path: src/Db/Sql/Query.php diff --git a/src/Db/Query.php b/src/Db/Query.php index 3125760..56c1767 100644 --- a/src/Db/Query.php +++ b/src/Db/Query.php @@ -26,7 +26,7 @@ public function __construct(string $sql, array $params) public static function from(string|self|Sql $query, array $params = []): self { if (is_string($query)) { - $query = new Sql\DefaultQuery($query, $params); + $query = new Sql\Query($query, $params); } else if ($params !== []) { throw Exceptions\QueryException::cantPassParams(); } diff --git a/src/Db/Sql/DefaultQuery.php b/src/Db/Sql/DefaultQuery.php deleted file mode 100644 index 640f756..0000000 --- a/src/Db/Sql/DefaultQuery.php +++ /dev/null @@ -1,21 +0,0 @@ -dbQuery === NULL) { - $this->dbQuery = Db\SqlDefinition::createQuery($this->getSqlDefinition()); - } - - return $this->dbQuery; - } - -} diff --git a/src/Db/Sql/Query.php b/src/Db/Sql/Query.php index bc9116d..578d880 100644 --- a/src/Db/Sql/Query.php +++ b/src/Db/Sql/Query.php @@ -4,9 +4,18 @@ use Forrest79\PhPgSql\Db; -interface Query extends Db\Sql +class Query extends Expression { + private Db\Query|NULL $dbQuery = NULL; - function toDbQuery(): Db\Query; + + public function toDbQuery(): Db\Query + { + if ($this->dbQuery === NULL) { + $this->dbQuery = Db\SqlDefinition::createQuery($this->getSqlDefinition()); + } + + return $this->dbQuery; + } } diff --git a/src/Fluent/Query.php b/src/Fluent/Query.php index e966fa3..4fa6ee0 100644 --- a/src/Fluent/Query.php +++ b/src/Fluent/Query.php @@ -7,7 +7,7 @@ /** * @phpstan-import-type QueryParams from QueryBuilder */ -class Query implements Db\Sql\Query +class Query implements Db\Sql { public const QUERY_SELECT = 'select'; public const QUERY_INSERT = 'insert'; diff --git a/src/Fluent/QueryBuilder.php b/src/Fluent/QueryBuilder.php index 41f7dbd..735f989 100644 --- a/src/Fluent/QueryBuilder.php +++ b/src/Fluent/QueryBuilder.php @@ -813,9 +813,9 @@ private function processCondition(Condition $condition, array &$params): string } - private static function areParenthesisNeeded(Db\Sql $sql): bool + protected static function areParenthesisNeeded(Db\Sql $sql): bool { - return $sql instanceof Db\Sql\Query; + return $sql instanceof Db\Sql\Query || $sql instanceof Query; } } diff --git a/tests/Integration/BasicTest.php b/tests/Integration/BasicTest.php index f731fcc..3473778 100644 --- a/tests/Integration/BasicTest.php +++ b/tests/Integration/BasicTest.php @@ -214,7 +214,7 @@ public function testFailedQuery(): void public function testPassParamToQuery(): void { Tester\Assert::exception(function (): void { - $query = Db\Sql\DefaultQuery::create('SELECT 1'); + $query = Db\Sql\Query::create('SELECT 1'); $this->connection->query($query, 1); }, Db\Exceptions\QueryException::class, NULL, Db\Exceptions\QueryException::CANT_PASS_PARAMS); } diff --git a/tests/Unit/FluentQueryTest.php b/tests/Unit/FluentQueryTest.php index b0190c8..09d2a5f 100644 --- a/tests/Unit/FluentQueryTest.php +++ b/tests/Unit/FluentQueryTest.php @@ -74,7 +74,7 @@ public function testSelectWithFluentQuery(): void public function testSelectWithQuery(): void { $query = $this->query() - ->select(['column' => Db\Sql\DefaultQuery::create('SELECT 1')]) + ->select(['column' => Db\Sql\Query::create('SELECT 1')]) ->toDbQuery(); Tester\Assert::same('SELECT (SELECT 1) AS "column"', $query->sql); @@ -131,7 +131,7 @@ public function testFromWithQuery(): void { $query = $this->query() ->select(['x.column']) - ->from(Db\Sql\DefaultQuery::create('SELECT 1 AS column'), 'x') + ->from(Db\Sql\Query::create('SELECT 1 AS column'), 'x') ->toDbQuery(); Tester\Assert::same('SELECT x.column FROM (SELECT 1 AS column) AS x', $query->sql); @@ -469,7 +469,7 @@ public function testJoinWithQuery(): void $query = $this->query() ->select(['x.column']) ->from('table', 't') - ->join(Db\Sql\DefaultQuery::create('SELECT 1 AS column'), 'x', 'x.column = t.id') + ->join(Db\Sql\Query::create('SELECT 1 AS column'), 'x', 'x.column = t.id') ->toDbQuery(); Tester\Assert::same('SELECT x.column FROM table AS t INNER JOIN (SELECT 1 AS column) AS x ON x.column = t.id', $query->sql); @@ -580,7 +580,7 @@ public function testLateralJoinWithSqlQuery(): void $query = $this->query() ->select(['column1' => 't1.column', 'column2' => 't2.column']) ->from('table1', 't1') - ->join(Db\Sql\DefaultQuery::create('SELECT column FROM table2'), 't2', 't2.column = t1.column') + ->join(Db\Sql\Query::create('SELECT column FROM table2'), 't2', 't2.column = t1.column') ->lateral('t2') ->toDbQuery(); @@ -638,7 +638,7 @@ public function testSelectCombineQuery(): void $query = $this->query() ->from('table', 't') ->select(['column']) - ->union(Db\Sql\DefaultQuery::create('SELECT column FROM table2 AS t2')) + ->union(Db\Sql\Query::create('SELECT column FROM table2 AS t2')) ->toDbQuery(); Tester\Assert::same('(SELECT column FROM table AS t) UNION (SELECT column FROM table2 AS t2)', $query->sql); @@ -689,7 +689,7 @@ public function testInsertRow(): void 'column' => 1, 'column_from' => Db\Sql\Literal::create('3'), 'column_fluent_query' => $this->query()->select(['\'test_fluent\''])->where('4', 4), - 'column_query' => Db\Sql\DefaultQuery::create('SELECT \'test\' WHERE 5 = ?', 5), + 'column_query' => Db\Sql\Query::create('SELECT \'test\' WHERE 5 = ?', 5), ]) ->insert('table') ->returning(['column']) @@ -728,7 +728,7 @@ public function testInsertRows(): void ['column' => 3], ['column' => Db\Sql\Literal::create('4')], ['column' => $this->query()->select(['\'test_fluent\''])->where('6', 6)], - ['column' => Db\Sql\DefaultQuery::create('SELECT \'test\' WHERE 7 = ?', 7)], + ['column' => Db\Sql\Query::create('SELECT \'test\' WHERE 7 = ?', 7)], ]) ->insert('table') ->returning(['column']) @@ -1093,7 +1093,7 @@ public function testUpdate(): void 'column' => 1, 'column_from' => Db\Sql\Literal::create('t2.id'), 'column_fluent_query' => $this->query()->select(['\'test_fluent\''])->where('2', 2), - 'column_query' => Db\Sql\DefaultQuery::create('SELECT \'test\' WHERE 3 = ?', 3), + 'column_query' => Db\Sql\Query::create('SELECT \'test\' WHERE 3 = ?', 3), ]) ->from('table2', 't2') ->where('t2.column', 100) @@ -1229,7 +1229,7 @@ public function testMergeUsingSql(): void { $query = $this->query() ->merge('customer_account', 'ca') - ->using(Db\Sql\DefaultQuery::create('SELECT customer_id, transaction_value FROM recent_transactions WHERE customer_id > ?', 10), 't', 't.customer_id = ca.customer_id') + ->using(Db\Sql\Query::create('SELECT customer_id, transaction_value FROM recent_transactions WHERE customer_id > ?', 10), 't', 't.customer_id = ca.customer_id') ->whenMatched('UPDATE SET balance = balance + transaction_value') ->whenNotMatched('INSERT (customer_id, balance) VALUES (t.customer_id, t.transaction_value)') ->toDbQuery(); @@ -1288,7 +1288,7 @@ public function testMergeCommonUpsert(): void $query = $this->query() ->merge('wines', 'w') ->using('(SELECT 1)', 's', 'w.winename = $1') - ->whenNotMatched(Db\Sql\DefaultQuery::create('INSERT (winename, balance) VALUES($1, $2)', 'Red wine', 10)) + ->whenNotMatched(Db\Sql\Query::create('INSERT (winename, balance) VALUES($1, $2)', 'Red wine', 10)) ->whenMatched('UPDATE SET balance = $2') ->toDbQuery(); @@ -1374,10 +1374,10 @@ public function testWith(): void { $query = $this->query() ->with('regional_sales', 'SELECT region, SUM(amount) AS total_sales FROM orders GROUP BY region') - ->with('top_regions', Db\Sql\DefaultQuery::create('SELECT region FROM regional_sales WHERE total_sales > (?) AND total_sales < ?', Db\Sql\Expression::create('SELECT SUM(total_sales) / 10 FROM regional_sales'), 10000)) + ->with('top_regions', Db\Sql\Query::create('SELECT region FROM regional_sales WHERE total_sales > (?) AND total_sales < ?', Db\Sql\Expression::create('SELECT SUM(total_sales) / 10 FROM regional_sales'), 10000)) ->select(['region', 'product', 'product_units' => 'SUM(quantity)', 'product_sales' => 'SUM(amount)']) ->from('orders') - ->where('region', Db\Sql\DefaultQuery::create('SELECT region FROM top_regions')) + ->where('region', Db\Sql\Query::create('SELECT region FROM top_regions')) ->where('region != ?', 'Prague') ->groupBy('region', 'product') ->toDbQuery(); @@ -1590,7 +1590,7 @@ public function testConditionWhere(): void $conditionOr->add('column2', [2, 3]); $conditionAnd = $conditionOr->addAndBranch(); $conditionAnd->add('column', $this->query()->select([1])); - $conditionAnd->add('column2 = ANY(?)', Db\Sql\DefaultQuery::create('SELECT 2')); + $conditionAnd->add('column2 = ANY(?)', Db\Sql\Query::create('SELECT 2')); $conditionOr->add('column3 IS NOT NULL'); $query = $conditionOr->query() @@ -1610,7 +1610,7 @@ public function testConditionHaving(): void $conditionOr->add('column2', [2, 3]); $conditionAnd = $conditionOr->addAndBranch(); $conditionAnd->add('column', $this->query()->select([1])); - $conditionAnd->add('column2 = ANY(?)', Db\Sql\DefaultQuery::create('SELECT 2')); + $conditionAnd->add('column2 = ANY(?)', Db\Sql\Query::create('SELECT 2')); $conditionOr->add('column3 IS NOT NULL'); $query = $conditionOr->query() diff --git a/tests/Unit/QueryTest.php b/tests/Unit/QueryTest.php index 3ca2913..51f8a1c 100644 --- a/tests/Unit/QueryTest.php +++ b/tests/Unit/QueryTest.php @@ -16,7 +16,7 @@ final class QueryTest extends Tests\TestCase public function testPrepareQuery(): void { - $query = Db\Sql\DefaultQuery::create('SELECT * FROM table')->toDbQuery(); + $query = Db\Sql\Query::create('SELECT * FROM table')->toDbQuery(); Tester\Assert::same('SELECT * FROM table', $query->sql); Tester\Assert::same([], $query->params); } @@ -24,19 +24,19 @@ public function testPrepareQuery(): void public function testPrepareQueryWithParams(): void { - $query = Db\Sql\DefaultQuery::create('SELECT * FROM table WHERE column = $1', 1)->toDbQuery(); + $query = Db\Sql\Query::create('SELECT * FROM table WHERE column = $1', 1)->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE column = $1', $query->sql); Tester\Assert::same([1], $query->params); - $query = Db\Sql\DefaultQuery::createArgs('SELECT * FROM table WHERE column = $1', [1])->toDbQuery(); + $query = Db\Sql\Query::createArgs('SELECT * FROM table WHERE column = $1', [1])->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE column = $1', $query->sql); Tester\Assert::same([1], $query->params); - $query = Db\Sql\DefaultQuery::create('SELECT * FROM table WHERE column = ?', 1)->toDbQuery(); + $query = Db\Sql\Query::create('SELECT * FROM table WHERE column = ?', 1)->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE column = $1', $query->sql); Tester\Assert::same([1], $query->params); - $query = Db\Sql\DefaultQuery::createArgs('SELECT * FROM table WHERE column = ?', [1])->toDbQuery(); + $query = Db\Sql\Query::createArgs('SELECT * FROM table WHERE column = ?', [1])->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE column = $1', $query->sql); Tester\Assert::same([1], $query->params); } @@ -45,7 +45,7 @@ public function testPrepareQueryWithParams(): void public function testPrepareQueryWithMissingParam(): void { Tester\Assert::exception(static function (): void { - Db\Sql\DefaultQuery::create('SELECT * FROM table WHERE column = ? AND column2 = ?', 1)->toDbQuery(); + Db\Sql\Query::create('SELECT * FROM table WHERE column = ? AND column2 = ?', 1)->toDbQuery(); }, Db\Exceptions\QueryException::class, NULL, Db\Exceptions\QueryException::MISSING_PARAM); } @@ -53,14 +53,14 @@ public function testPrepareQueryWithMissingParam(): void public function testPrepareQueryWithExtraParam(): void { Tester\Assert::exception(static function (): void { - Db\Sql\DefaultQuery::create('SELECT * FROM table WHERE column = ?', 1, 2)->toDbQuery(); + Db\Sql\Query::create('SELECT * FROM table WHERE column = ?', 1, 2)->toDbQuery(); }, Db\Exceptions\QueryException::class, NULL, Db\Exceptions\QueryException::EXTRA_PARAM); } public function testPrepareQueryWithLiteral(): void { - $query = Db\Sql\DefaultQuery::create('SELECT * FROM ? WHERE column = ?', Db\Sql\Literal::create('table'), 1)->toDbQuery(); + $query = Db\Sql\Query::create('SELECT * FROM ? WHERE column = ?', Db\Sql\Literal::create('table'), 1)->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE column = $1', $query->sql); Tester\Assert::same([1], $query->params); } @@ -68,7 +68,7 @@ public function testPrepareQueryWithLiteral(): void public function testPrepareQueryWithLiteralWithParams(): void { - $query = Db\Sql\DefaultQuery::create('SELECT * FROM ? WHERE column = ?', Db\Sql\Expression::create('function(?, ?)', 'param1', 2), 1)->toDbQuery(); + $query = Db\Sql\Query::create('SELECT * FROM ? WHERE column = ?', Db\Sql\Expression::create('function(?, ?)', 'param1', 2), 1)->toDbQuery(); Tester\Assert::same('SELECT * FROM function($1, $2) WHERE column = $3', $query->sql); Tester\Assert::same(['param1', 2, 1], $query->params); } @@ -76,7 +76,7 @@ public function testPrepareQueryWithLiteralWithParams(): void public function testPrepareQueryWithArray(): void { - $query = Db\Sql\DefaultQuery::create('SELECT * FROM table WHERE column IN (?)', [1, 2])->toDbQuery(); + $query = Db\Sql\Query::create('SELECT * FROM table WHERE column IN (?)', [1, 2])->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE column IN ($1, $2)', $query->sql); Tester\Assert::same([1, 2], $query->params); } @@ -84,7 +84,7 @@ public function testPrepareQueryWithArray(): void public function testPrepareQueryWithArrayNotList(): void { - $query = Db\Sql\DefaultQuery::create('SELECT * FROM table WHERE column1 = ? AND column2 IN (?)', 3, [10 => 2, 20 => 1])->toDbQuery(); + $query = Db\Sql\Query::create('SELECT * FROM table WHERE column1 = ? AND column2 IN (?)', 3, [10 => 2, 20 => 1])->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE column1 = $1 AND column2 IN ($2, $3)', $query->sql); Tester\Assert::same([3, 2, 1], $query->params); } @@ -92,7 +92,7 @@ public function testPrepareQueryWithArrayNotList(): void public function testPrepareQueryWithBlankArray(): void { - $query = Db\Sql\DefaultQuery::create('SELECT * FROM table WHERE column IN (?)', [])->toDbQuery(); + $query = Db\Sql\Query::create('SELECT * FROM table WHERE column IN (?)', [])->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE column IN ()', $query->sql); Tester\Assert::same([], $query->params); } @@ -100,7 +100,7 @@ public function testPrepareQueryWithBlankArray(): void public function testPrepareQueryWithArrayAsOneAnyParameter(): void { - $query = Db\Sql\DefaultQuery::create('SELECT * FROM table WHERE column = ANY(?)', Db\Helper::createPgArray([1, 2]))->toDbQuery(); + $query = Db\Sql\Query::create('SELECT * FROM table WHERE column = ANY(?)', Db\Helper::createPgArray([1, 2]))->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE column = ANY($1)', $query->sql); Tester\Assert::same(['{1,2}'], $query->params); } @@ -108,8 +108,8 @@ public function testPrepareQueryWithArrayAsOneAnyParameter(): void public function testPrepareQueryWithQuery(): void { - $subquery = Db\Sql\DefaultQuery::create('SELECT id FROM subtable WHERE column = ?', 1); - $query = Db\Sql\DefaultQuery::create('SELECT * FROM table WHERE id IN (?)', $subquery)->toDbQuery(); + $subquery = Db\Sql\Query::create('SELECT id FROM subtable WHERE column = ?', 1); + $query = Db\Sql\Query::create('SELECT * FROM table WHERE id IN (?)', $subquery)->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE id IN (SELECT id FROM subtable WHERE column = $1)', $query->sql); Tester\Assert::same([1], $query->params); } @@ -117,7 +117,7 @@ public function testPrepareQueryWithQuery(): void public function testPrepareQueryWithEnum(): void { - $query = Db\Sql\DefaultQuery::create('SELECT * FROM table WHERE column = ?', Tests\TestEnum::One)->toDbQuery(); + $query = Db\Sql\Query::create('SELECT * FROM table WHERE column = ?', Tests\TestEnum::One)->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE column = $1', $query->sql); Tester\Assert::same([Tests\TestEnum::One->value], $query->params); } @@ -125,7 +125,7 @@ public function testPrepareQueryWithEnum(): void public function testPrepareQueryWithArrayOfEnums(): void { - $query = Db\Sql\DefaultQuery::create('SELECT * FROM table WHERE column IN (?)', [Tests\TestEnum::Two, Tests\TestEnum::One])->toDbQuery(); + $query = Db\Sql\Query::create('SELECT * FROM table WHERE column IN (?)', [Tests\TestEnum::Two, Tests\TestEnum::One])->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE column IN ($1, $2)', $query->sql); Tester\Assert::same([Tests\TestEnum::Two->value, Tests\TestEnum::One->value], $query->params); } @@ -133,7 +133,7 @@ public function testPrepareQueryWithArrayOfEnums(): void public function testPrepareQueryEscapeQuestionmark(): void { - $query = Db\Sql\DefaultQuery::create('SELECT * FROM table WHERE column = ? AND text ILIKE \'What\?\'', 1)->toDbQuery(); + $query = Db\Sql\Query::create('SELECT * FROM table WHERE column = ? AND text ILIKE \'What\?\'', 1)->toDbQuery(); Tester\Assert::same('SELECT * FROM table WHERE column = $1 AND text ILIKE \'What?\'', $query->sql); Tester\Assert::same([1], $query->params); } @@ -141,13 +141,13 @@ public function testPrepareQueryEscapeQuestionmark(): void public function testPrepareQueryCondition(): void { - $subquery = Db\Sql\DefaultQuery::create( + $subquery = Db\Sql\Query::create( 'SELECT id FROM subtable WHERE when = ? AND text ILIKE \'When\?\' AND year > ?', Db\Sql\Literal::create('now()'), 2005, ); - $query = Db\Sql\DefaultQuery::create( + $query = Db\Sql\Query::create( 'SELECT * FROM table WHERE column = ? OR id IN (?) OR type IN (?)', 'yes', $subquery,