Considering that I will need to use this connection for my Models, what is the best practice to use it?
Hello Sebastian,
Thanks for answering again, I think I missed your post in the IRC channel.
I guess the example that we are talking about would be:
# Model in Blog package
$self->helper(pg => sub { state $pg =
Mojo::Pg->new(shift->config('pg')) });
$self->helper(
posts => sub { state $posts = Blog::Model::Posts->new(pg
=> shift->pg) });
In the model (which uses Mojo::Base, which I understand is not a requirement, but useful), I just pass the reference stored by the pg (DB) helper.
And looks like that's it... the model doesn't have to do anything
else. It seems the DB handle is implicit managed by Mojo::Pg::Database (including the connection), so
it does look like what DBIx::Controller does under the hood. And
probably that's why I wasn't being able to use it with Mysql.
So, my guess is that if I need to use a different DB supported by DBI, I would need to make sure the equivalent of Mojo::Pg::Database would need to implement a DESTROY block and wrap a instance of it around with the a helper.
Did I get it correctly?
Thanks!
Alceu
--
You received this message because you are subscribed to a topic in the Google Groups "Mojolicious" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/mojolicious/LgXKq2KA_HE/unsubscribe.
To unsubscribe from this group and all its topics, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at https://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.