neo4j-php / php-cypher-dsl

A low-level query builder for Cypher written in PHP
MIT License
18 stars 5 forks source link

Support comparison of dates #49

Closed wgevaert closed 2 years ago

wgevaert commented 2 years ago

Trying to make a query like

MATCH (n:Article) WHERE n.creation > datetime({year: 2020, month: 12, day: 11, hour: 10, minute: 9}) AND n.creation < datetime({year: 2021, month: 12, day: 11, hour: 10, minute: 9}) RETURN n.title

is difficult. For example, doing this does not work:

include_once __DIR__ . '/vendor/autoload.php';

use WikibaseSolutions\CypherDSL\Query;
use WikibaseSolutions\CypherDSL\AndOperator;

$n = Query::variable('n');
$query = Query::new()->match(
    Query::node('Article')->named($n)
)->where(
    new AndOperator(
        $n->property('creation')->gt(
            Query::literal()::dateTimeYMD(2020,12,11,10,9)
        ),
        $n->property('creation')->lt(
            Query::literal()::dateTimeYMD(2021,12,11,10,9)
        )
    )
)->returning($n->property('title'))->build();

echo $query;

because one gets the following error:

PHP Fatal error:  Uncaught TypeError: Argument 1 passed to WikibaseSolutions\CypherDSL\Property::gt() must implement interface WikibaseSolutions\CypherDSL\Types\PropertyTypes\NumeralType, instance of WikibaseSolutions\CypherDSL\Functions\DateTime given, called in /path/to/php-cypher-dsl/test.php on line 13 and defined in /path/to/php-cypher-dsl/src/Traits/NumeralTypeTrait.php:88
Stack trace:
#0 /path/to/php-cypher-dsl/test.php(13): WikibaseSolutions\CypherDSL\Property->gt(Object(WikibaseSolutions\CypherDSL\Functions\DateTime))
#1 {main}
  thrown in /path/to/php-cypher-dsl/src/Traits/NumeralTypeTrait.php on line 88

Can this be fixed?

wgevaert commented 2 years ago

Closed by https://github.com/WikibaseSolutions/php-cypher-dsl/pull/50