Giter Site home page Giter Site logo

Comments (4)

tacman avatar tacman commented on August 9, 2024

I attempted to customize a function, but couldn't figure out how to handle the ? since doctrine uses ? for placeholders.

What about creating a custom function that "wraps" the ? and ?| operators, then creating a custom doctrine function that calls those custom functions? It's hackish, but the ? and ?| operators are the one I think I need for my data.

There is also a json_exists function in postgres 15 (https://www.depesz.com/2022/04/01/waiting-for-postgresql-15-sql-json-query-functions/) maybe simply writing a function what calls it would be easier.

from postgresql-for-doctrine.

tacman avatar tacman commented on August 9, 2024

I thought the solution was going to be to use json_exists, but it appears that the functions don't use the GIN indexes, only the operators. That seems crazy, and I hope I'm wrong on that. Details at https://dba.stackexchange.com/questions/90002/postgresql-operator-uses-index-but-underlying-function-does-not

If so, though, a solution is also offered there, to create a custom function that wraps the operator call:

CREATE OR REPLACE FUNCTION jb_contains(jsonb, text)
  RETURNS bool AS
'SELECT $1 ? $2' LANGUAGE sql IMMUTABLE;

Then I guess add a doctrine function using this library that calls jb_contains. It feels hackish, I'll do some testing to see if this is even necessary and if the solution proposed here works.

from postgresql-for-doctrine.

ellmout avatar ellmout commented on August 9, 2024

Hey,
I was having the same problem with "?|".
Just found out, you can escape a question mark by adding another one "??|".
My class "JsonAnyOf" is working great now :

<?php

declare(strict_types=1);

namespace App\ORM;

use MartinGeorgiev\Doctrine\ORM\Query\AST\Functions\BaseFunction;

class JsonAnyOf extends BaseFunction
{
    protected function customiseFunction(): void
    {
        $this->setFunctionPrototype('(%s ??| %s)');
        $this->addNodeMapping('StringPrimary');
        $this->addNodeMapping('StringPrimary');
    }
}

from postgresql-for-doctrine.

martin-georgiev avatar martin-georgiev commented on August 9, 2024

Support for ?, ?| and some other operators got added with #170

from postgresql-for-doctrine.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.