Add byContains and byJsonPath throughout

- Change to JSON Path function to work around PDO syntax quirk
This commit is contained in:
2024-06-13 21:39:16 -04:00
parent 9ecabbe39f
commit 7de39a41fc
26 changed files with 569 additions and 22 deletions

View File

@@ -37,7 +37,7 @@ class CountTest extends TestCase
public function testByContainsSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
$this->assertEquals("SELECT COUNT(*) FROM the_table WHERE data @> :criteria", Count::byContains('the_table'),
$this->assertEquals('SELECT COUNT(*) FROM the_table WHERE data @> :criteria', Count::byContains('the_table'),
'SELECT statement not generated correctly');
}
@@ -52,8 +52,8 @@ class CountTest extends TestCase
public function testByJsonPathSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
$this->assertEquals("SELECT COUNT(*) FROM a_table WHERE data @? :path::jsonpath", Count::byJsonPath('a_table'),
'SELECT statement not generated correctly');
$this->assertEquals('SELECT COUNT(*) FROM a_table WHERE jsonb_path_exists(data, :path::jsonpath)',
Count::byJsonPath('a_table'), 'SELECT statement not generated correctly');
}
#[TestDox('By JSON Path fails for non PostgreSQL')]

View File

@@ -53,8 +53,8 @@ class DeleteTest extends TestCase
public function testByJsonPathSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
$this->assertEquals('DELETE FROM here WHERE data @? :path::jsonpath', Delete::byJsonPath('here'),
'DELETE statement not constructed correctly');
$this->assertEquals('DELETE FROM here WHERE jsonb_path_exists(data, :path::jsonpath)',
Delete::byJsonPath('here'), 'DELETE statement not constructed correctly');
}
#[TestDox('By JSON Path fails for non PostgreSQL')]

View File

@@ -60,7 +60,7 @@ class ExistsTest extends TestCase
public function testByJsonPathSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
$this->assertEquals('SELECT EXISTS (SELECT 1 FROM lint WHERE data @? :path::jsonpath)',
$this->assertEquals('SELECT EXISTS (SELECT 1 FROM lint WHERE jsonb_path_exists(data, :path::jsonpath))',
Exists::byJsonPath('lint'), 'Existence query not generated correctly');
}

View File

@@ -54,8 +54,8 @@ class FindTest extends TestCase
public function testByJsonPathSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
$this->assertEquals('SELECT data FROM light WHERE data @? :path::jsonpath', Find::byJsonPath('light'),
'SELECT query not generated correctly');
$this->assertEquals('SELECT data FROM light WHERE jsonb_path_exists(data, :path::jsonpath)',
Find::byJsonPath('light'), 'SELECT query not generated correctly');
}
#[TestDox('By JSON Path fails for non PostgreSQL')]

View File

@@ -83,7 +83,7 @@ class PatchTest extends TestCase
public function testByJsonPathSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
$this->assertEquals('UPDATE that SET data = data || :data WHERE data @? :path::jsonpath',
$this->assertEquals('UPDATE that SET data = data || :data WHERE jsonb_path_exists(data, :path::jsonpath)',
Patch::byJsonPath('that'), 'Patch UPDATE statement is not correct');
}

View File

@@ -112,7 +112,8 @@ class RemoveFieldsTest extends TestCase
public function testByJsonPathSucceedsForPostgreSQL(): void
{
Configuration::$mode = Mode::PgSQL;
$this->assertEquals('UPDATE dessert SET data = data - :cake::text[] WHERE data @? :path::jsonpath',
$this->assertEquals(
'UPDATE dessert SET data = data - :cake::text[] WHERE jsonb_path_exists(data, :path::jsonpath)',
RemoveFields::byJsonPath('dessert', Parameters::fieldNames(':cake', ['b', 'c'])),
'UPDATE statement not correct');
}

View File

@@ -96,7 +96,7 @@ class QueryTest extends TestCase
{
Configuration::$mode = Mode::PgSQL;
try {
$this->assertEquals('data @? :path::jsonpath', Query::whereJsonPathMatches(),
$this->assertEquals('jsonb_path_exists(data, :path::jsonpath)', Query::whereJsonPathMatches(),
'WHERE fragment not constructed correctly');
} finally {
Configuration::$mode = null;
@@ -108,7 +108,7 @@ class QueryTest extends TestCase
{
Configuration::$mode = Mode::PgSQL;
try {
$this->assertEquals('data @? :road::jsonpath', Query::whereJsonPathMatches(':road'),
$this->assertEquals('jsonb_path_exists(data, :road::jsonpath)', Query::whereJsonPathMatches(':road'),
'WHERE fragment not constructed correctly');
} finally {
Configuration::$mode = null;