preaction / Yancy

The Best Web Framework Deserves the Best Content Management System
http://preaction.me/yancy/
Other
54 stars 21 forks source link

accept connected schema as parameter for DBIC backend #33

Closed mario-minati closed 5 years ago

mario-minati commented 5 years ago

Hello Doug,

I'd like to extend Dbic backend class to accept a connected dbic instance (weakend) to bind to. Would that be acceptable for your goals?

Best greets,

Mario

preaction commented 5 years ago

It already should. Second example here in the synopsis: http://preaction.me/yancy/perldoc/Yancy/Backend/Dbic/#SYNOPSIS If that doesn't work, then it's a bug.

Or are you saying the backend should weaken the schema attribute? Because that's not really appropriate for the situation. What'd be the reason for needing the backend not to hang on to the schema object strongly?

mario-minati commented 5 years ago

In our code we have already a connected schema from a separate class holding a database role, so we can easily access it with my $db = $app->database;

So we'd like to do like this as we decouple db config from api (yancy) config:

plugin Yancy => {
    backend => { Dbic => $app->database },
    read_schema => 1,
};

As we use an existing instance I'd thought we need to weaken that reference.

preaction commented 5 years ago

Weak references are mainly for avoiding memory leaks when circular references are inevitable, which can end up happening when using event handlers / async callbacks. Since this configuration isn't that, but also since this configuration absolutely requires there be a connection to use, you don't need to weaken the reference here (weakrefs can get collected, turning all instances to undef, you don't want that to happen).

So, what happens when you try that to give Yancy the schema instance?

mario-minati commented 5 years ago

Seems to work, but currently leads to a different problem (#35), as Yancy to have trouble with virtual tables.

preaction commented 5 years ago

Alright, if this part is working, then I'll close this.

mario-minati commented 5 years ago

Works :-) 👍