neo4j-php / php-cypher-dsl

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

How to use labels(n)[0] in where? #98

Open beshoo opened 8 months ago

beshoo commented 8 months ago

I have this code, but am confused about how to convert it! even ChatGPT doesn't know LOL BTW: the documentation does not cover all aspects of this great lib, is there another doc? Thank you

 MATCH (n)
                where (n.status=0 or n.status="0") and (n.lableb is null)  
                and (labels(n)[0]="CharactourM" or labels(n)[0]="CompanyM" )
                RETURN distinct labels(n)[0] as label,count(n) as count 
marijnvanwezel commented 8 months ago

Hi Beshoo! Unfortunately, this syntax is not yet supported, but you can use a raw expression to emulate it:

use function WikibaseSolutions\CypherDSL\node;
use function WikibaseSolutions\CypherDSL\procedure;
use function WikibaseSolutions\CypherDSL\query;
use function WikibaseSolutions\CypherDSL\raw;

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

$n = node();
$query = query()
    ->match($n)
    ->where(
        $n->property('status')->equals(0)->or($n->property('status')->equals('0'))
            ->and($n->property('lableb')->isNull())
            ->and(
                raw(procedure()::raw('labels', $n)->toQuery() . '[0]')->equals("CharactourM")
             ->or(
                raw(procedure()::raw('labels', $n)->toQuery() . '[0]')->equals("CompanyM"))))
    ->returning([
        raw(procedure()::raw('labels', $n)->toQuery() . '[0]')
            ->alias('label'),
        procedure()::raw('count', $n)
            ->alias('count')
    ], distinct: true)
    ->toQuery();

The syntax for raw queries and procedures is rather ugly. I'll see if I can make some improvements.

beshoo commented 8 months ago

@marijnvanwezel Thank you for your reply.

However, my manager finds this raw difficult to understand, as you already said it is ugly . even chatGpt don't like it, LOL

Can we expect any updates in the upcoming days?

marijnvanwezel commented 8 months ago

Hi @beshoo, I would not expect an update that fixes this in the coming days. The project this library was initially developed for is no longer being worked on, which put this library on the backburner as well.

I am willing to spend some time reviewing potential pull requests! :)

beshoo commented 8 months ago

I did my best to understand the HowItWorks library, but unfortunately, shame on me, I don't think I have the skills to create a pull request for it.

However, I believe it's crucial to support the 'label' feature in this case since neo4J is all about labels! Right?

Could you please add this support to the library since you know where and how to do it? I Do understand that you put this library on the backburner, But , this update will make the DSL more up-to-date and beneficial for the open-source community!

I am kindly requesting an exception and a big favor for both me and the community.

Thank you so much!

marijnvanwezel commented 8 months ago

I will see if I can get some hours to work on this.