Add ORDER BY support
- Update deps
This commit is contained in:
@@ -82,7 +82,7 @@ class FieldTest extends TestCase
|
||||
}
|
||||
|
||||
#[TestDox('path() succeeds for simple SQL path for PostgreSQL')]
|
||||
public function testPathSucceedsForSimpleSqlPathForPostgreSQL()
|
||||
public function testPathSucceedsForSimpleSqlPathForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
@@ -94,7 +94,7 @@ class FieldTest extends TestCase
|
||||
}
|
||||
|
||||
#[TestDox('path() succeeds for simple SQL path for SQLite')]
|
||||
public function testPathSucceedsForSimpleSqlPathForSQLite()
|
||||
public function testPathSucceedsForSimpleSqlPathForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
@@ -106,7 +106,7 @@ class FieldTest extends TestCase
|
||||
}
|
||||
|
||||
#[TestDox('path() succeeds for nested SQL path for PostgreSQL')]
|
||||
public function testPathSucceedsForNestedSqlPathForPostgreSQL()
|
||||
public function testPathSucceedsForNestedSqlPathForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
@@ -118,7 +118,7 @@ class FieldTest extends TestCase
|
||||
}
|
||||
|
||||
#[TestDox('path() succeeds for nested SQL path for SQLite')]
|
||||
public function testPathSucceedsForNestedSqlPathForSQLite()
|
||||
public function testPathSucceedsForNestedSqlPathForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
@@ -130,7 +130,7 @@ class FieldTest extends TestCase
|
||||
}
|
||||
|
||||
#[TestDox('path() succeeds for simple JSON path for PostgreSQL')]
|
||||
public function testPathSucceedsForSimpleJsonPathForPostgreSQL()
|
||||
public function testPathSucceedsForSimpleJsonPathForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
@@ -142,7 +142,7 @@ class FieldTest extends TestCase
|
||||
}
|
||||
|
||||
#[TestDox('path() succeeds for simple JSON path for SQLite')]
|
||||
public function testPathSucceedsForSimpleJsonPathForSQLite()
|
||||
public function testPathSucceedsForSimpleJsonPathForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
@@ -154,7 +154,7 @@ class FieldTest extends TestCase
|
||||
}
|
||||
|
||||
#[TestDox('path() succeeds for nested JSON path for PostgreSQL')]
|
||||
public function testPathSucceedsForNestedJsonPathForPostgreSQL()
|
||||
public function testPathSucceedsForNestedJsonPathForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
try {
|
||||
@@ -166,7 +166,7 @@ class FieldTest extends TestCase
|
||||
}
|
||||
|
||||
#[TestDox('path() succeeds for nested JSON path for SQLite')]
|
||||
public function testPathSucceedsForNestedJsonPathForSQLite()
|
||||
public function testPathSucceedsForNestedJsonPathForSQLite(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::SQLite);
|
||||
try {
|
||||
@@ -669,4 +669,15 @@ class FieldTest extends TestCase
|
||||
$this->assertEquals('', $field->value, 'Value should have been blank');
|
||||
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
||||
}
|
||||
|
||||
#[TestDox('named() succeeds')]
|
||||
public function testNamedSucceeds(): void
|
||||
{
|
||||
$field = Field::named('the_field');
|
||||
$this->assertNotNull($field, 'The field should not have been null');
|
||||
$this->assertEquals('the_field', $field->fieldName, 'Field name not filled correctly');
|
||||
$this->assertEquals(Op::Equal, $field->op, 'Operation not filled correctly');
|
||||
$this->assertEquals('', $field->value, 'Value should have been blank');
|
||||
$this->assertEquals('', $field->paramName, 'Parameter name should have been blank');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,4 +224,81 @@ class QueryTest extends TestCase
|
||||
$this->assertEquals("UPDATE testing SET data = :data WHERE data->>'id' = :id", Query::update('testing'),
|
||||
'UPDATE statement not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with no fields for PostgreSQL')]
|
||||
public function testOrderBySucceedsWithNoFieldsForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals('', Query::orderBy([]), 'ORDER BY should have been blank');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with no fields for SQLite')]
|
||||
public function testOrderBySucceedsWithNoFieldsForSQLite(): void
|
||||
{
|
||||
$this->assertEquals('', Query::orderBy([]), 'ORDER BY should have been blank');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with one field and no direction for PostgreSQL')]
|
||||
public function testOrderBySucceedsWithOneFieldAndNoDirectionForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals(" ORDER BY data->>'TestField'", Query::orderBy([Field::named('TestField')]),
|
||||
'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with one field and no direction for SQLite')]
|
||||
public function testOrderBySucceedsWithOneFieldAndNoDirectionForSQLite(): void
|
||||
{
|
||||
$this->assertEquals(" ORDER BY data->>'TestField'", Query::orderBy([Field::named('TestField')]),
|
||||
'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with multiple fields and direction for PostgreSQL')]
|
||||
public function testOrderBySucceedsWithMultipleFieldsAndDirectionForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals(" ORDER BY data#>>'{Nested,Test,Field}' DESC, data->>'AnotherField', data->>'It' DESC",
|
||||
Query::orderBy(
|
||||
[Field::named('Nested.Test.Field DESC'), Field::named('AnotherField'), Field::named('It DESC')]),
|
||||
'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with multiple fields and direction for SQLite')]
|
||||
public function testOrderBySucceedsWithMultipleFieldsAndDirectionForSQLite(): void
|
||||
{
|
||||
$this->assertEquals(" ORDER BY data->'Nested'->'Test'->>'Field' DESC, data->>'AnotherField', data->>'It' DESC",
|
||||
Query::orderBy(
|
||||
[Field::named('Nested.Test.Field DESC'), Field::named('AnotherField'), Field::named('It DESC')]),
|
||||
'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with numeric field for PostgreSQL')]
|
||||
public function testOrderBySucceedsWithNumericFieldForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals(" ORDER BY (data->>'Test')::numeric", Query::orderBy([Field::named('n:Test')]),
|
||||
'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with numeric field for SQLite')]
|
||||
public function testOrderBySucceedsWithNumericFieldForSQLite(): void
|
||||
{
|
||||
$this->assertEquals(" ORDER BY data->>'Test'", Query::orderBy([Field::named('n:Test')]),
|
||||
'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with case-insensitive ordering for PostgreSQL')]
|
||||
public function testOrderBySucceedsWithCaseInsensitiveOrderingForPostgreSQL(): void
|
||||
{
|
||||
Configuration::overrideMode(Mode::PgSQL);
|
||||
$this->assertEquals(" ORDER BY LOWER(data#>>'{Test,Field}') DESC NULLS FIRST",
|
||||
Query::orderBy([Field::named('i:Test.Field DESC NULLS FIRST')]), 'ORDER BY not constructed correctly');
|
||||
}
|
||||
|
||||
#[TestDox('orderBy() succeeds with case-insensitive ordering for SQLite')]
|
||||
public function testOrderBySucceedsWithCaseInsensitiveOrderingForSQLite(): void
|
||||
{
|
||||
$this->assertEquals(" ORDER BY data->'Test'->>'Field' COLLATE NOCASE ASC NULLS LAST",
|
||||
Query::orderBy([Field::named('i:Test.Field ASC NULLS LAST')]), 'ORDER BY not constructed correctly');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user