martin-georgiev / postgresql-for-doctrine

PostgreSQL enhancements for Doctrine. Provides support for advanced data types (json, jssnb, arrays), text search, array operators and jsonb specific functions.

Home Page:https://packagist.org/packages/martin-georgiev/postgresql-for-doctrine

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Help with setup

isaackearl opened this issue · comments

Hello!

First off I want to say this package looks really awesome. I am trying out postgres for the first time because I want to be able to store and query json for a particular use case I have... However I'm having some issues figuring out how to actually use the tools provided in this package. A few examples would be really great, though I am grateful for your time putting the package together either way.

Thanks again!

What is your use case? Can you share pseudo code of what you are doing? Also, are you integrating with a specific framework?

@martin-georgiev

So I've been looking around and your package seems to be exactly what I need. I essentially want to be able to store json objects and then query them in dql etc being able to filter by keys or values etc in the json.

However after trying to get things installed last night, I'm thinking now that this package may have been written and tested against an older version of Laravel Doctrine. I couldn't get it to work. Here are a few of the issues:

        'guid' => VoucherCodes\GUID\Doctrine\DBAL\Types\Guid::class,
        'guid[]' => VoucherCodes\GUID\Doctrine\DBAL\Types\GuidArray::class,

These guid types are not found and I can't find the package on github that they are supposed to be from.

So I tried removing the mapping_types for guid to see if I could do without it

            'mapping_types' => [
                //'enum' => 'string'
                'jsonb' => 'jsonb',
                '_jsonb' => 'jsonb[]',
                'jsonb[]' => 'jsonb[]',
//                'guid' => 'guid',
//                '_guid' => 'guid[]',
//                'guid[]' => 'guid[]',
                '_int2' => 'smallint[]',
                'smallint[]' => 'smallint[]',
                '_int4' => 'integer[]',
                'integer[]' => 'integer[]',
                '_int8' => 'bigint',
                'bigint[]' => 'bigint[]',
                '_text' => 'text[]',
                'text[]' => 'text[]',
            ]

However I still get errors trying to do database operations or generate migrations from a diff etc.

 [Illuminate\Contracts\Container\BindingResolutionException]
  Unresolvable dependency resolving [Parameter #0 [ <required> $app ]] in class Illuminate\Supp
  ort\Manager

Another thing is that the Readme says to add to the "type_mappings", but in the most recent stable laravel doctrine package they are called "mapping_types".

Because of that change I assumed in my new DoctrineServiceProvider that I would need to change the entity manager key to "mapping_types" as well...

I set the new Service Provider in my app.php, but it still doesn't work.

I've spent more time trying to figure out how to install things... and I found this post: (from you it looks like)

https://stackoverflow.com/questions/31272850/register-custom-doctrine-dbal-types-in-laravel

I'm wondering if this is more accurate then the current readme... I'm wondering if I actually need to make the event subscriber and doctrine service provider etc...

in the doctrine.php config file for laravel doctrine there is this section:

  'events' => [
                'listeners' => [],
                'subscribers' => []
            ],

which makes me believe I should be putting something there...

Sorry, my questions are just sorta random now but I would like to get this working. I will be using the package heavily if I can get it to work and will probably try and contribute etc. I'm thinking a good pull request would be a service provider that comes with the package that can just be added to the app.php etc. I will try and work on that if I can figure out how things work.

I worked on it most the day today...

I think I sort of got things working, at least for using the custom type to create my migrations etc.

Now I want to do soemthing simple, like query a field that contains json values so it filters it by a particular field. I can usually do this with laravel eloquent by doing something like this:

$users = DB::table('users')
                ->where('options->language', 'en')
                ->get();

where the options field contains json and the 'language' is a key....

I'm thinking if you can help me get that far just to do this simple type of query using doctrine then I will be very grateful. but I can't figure out how to use any of the custom_string_functions... in DQL or anywhere for that matter..

Thanks.

Thanks for pointing out the outdated Laravel instructions in the README. They were written some time ago both LaravelDoctrine and Laravel have moved forward since then. I'll revise the README to reflect the latest LaravelDoctrine release and will come back to you with more examples.

Wow thanks martin!

That sounds amazing.

Hey Isaack,
Sorry I couldn't get back to you sooner.

Do you still need help with this?

@martin-georgiev It's ok! I understand you are probably very busy with other projects etc. If you have time I would really appreciate it, I am still planning on using your package, but for now have started creating some workarounds using native queries. Thanks!