Mojo::Pg in full Mojolicious applications

411 views
Skip to first unread message

sri

unread,
Mar 12, 2015, 9:15:44 PM3/12/15
to mojol...@googlegroups.com
This seems to have become kind of an FAQ. What is the right way to integrate Mojo::Pg into full Mojolicious applications? And how do we separate concerns properly? When i recently mentioned on IRC that Minion is actually a good example, that caused some confusion, since many folks don't see it as a Model.

So i've tried to make a much more generic example. It is super minimalistic, and its only purpose will be to illustrate what i think a clean Mojolicious application should look like.


Please let me know if anything is still not clear enough.

--
sebastian

sri

unread,
Mar 12, 2015, 9:28:47 PM3/12/15
to mojol...@googlegroups.com
Already changed a few things, latest version can always be found in the examples directory.


--
sebastian

sri

unread,
Mar 13, 2015, 1:47:56 AM3/13/15
to mojol...@googlegroups.com
It also occurred to me that we have not yet chosen a default convention for naming CRUD methods in controllers, so here's a proposal.

    package MyApp::Controller::Posts;
    use Mojo::Base 'Mojolicious::Controller';

    # Render a form to create a new post (submitted to "store")
    sub create {...}

    # Delete a post
    sub destroy {...}

    # Render a form to edit a post (submitted to "update")
    sub edit {...}

    # Render a list of posts
    sub index {...}

    # Render a sepcific post
    sub show {...}

    # Store newly created post (submitted by "create")
    sub store {...}

    # Store updated post (submitted by "edit")
    sub update {...}

    1;

--
sebastian

Joel Berger

unread,
Mar 13, 2015, 8:46:46 AM3/13/15
to mojol...@googlegroups.com
I would propose a different name than than destroy. DESTROY has meaning in Perl and I'd rather not add confusion. Sadly delete does to, so I propose "remove".

Paul Durden

unread,
Mar 13, 2015, 4:53:14 PM3/13/15
to mojol...@googlegroups.com
I have used remove instead of destroy or delete

On Fri, Mar 13, 2015 at 7:46 AM, Joel Berger <joel.a...@gmail.com> wrote:
I would propose a different name than than destroy. DESTROY has meaning in Perl and I'd rather not add confusion. Sadly delete does to, so I propose "remove".

--
You received this message because you are subscribed to the Google Groups "Mojolicious" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mojolicious...@googlegroups.com.
To post to this group, send email to mojol...@googlegroups.com.
Visit this group at http://groups.google.com/group/mojolicious.
For more options, visit https://groups.google.com/d/optout.

sri

unread,
Mar 13, 2015, 5:38:58 PM3/13/15
to mojol...@googlegroups.com
I would propose a different name than than destroy. DESTROY has meaning in Perl and I'd rather not add confusion. Sadly delete does to, so I propose "remove".

Seems reasonable.

    package MyApp::Controller::Posts;
    use Mojo::Base 'Mojolicious::Controller';

    # Render a form to create a new post (submitted to "store")
    sub create {...}

    # Render a form to edit a post (submitted to "update")
    sub edit {...}

    # Render a list of posts
    sub index {...}
  
    # Remove a post
    sub remove {...}

    # Render a specific post
    sub show {...}

    # Store newly created post (submitted by "create")
    sub store {...}

    # Store updated post (submitted by "edit")
    sub update {...}

    1;

--
sebastian

sri

unread,
Mar 14, 2015, 2:26:34 AM3/14/15
to mojol...@googlegroups.com
Seems reasonable.

The list has now also made it into a reworked section of the rendering guide.


--
sebastian 

sri

unread,
Apr 1, 2015, 1:26:10 PM4/1/15
to mojol...@googlegroups.com
The list has now also made it into a reworked section of the rendering guide.

The Mojo::Pg blog example has also been updated with full CRUD.


--
sebastian 

Eugene Toropov

unread,
Apr 17, 2015, 3:29:22 PM4/17/15
to mojol...@googlegroups.com
I probably miss something but shouldn't every model has access to DB inside it's code with no explicit "pg => shift->pg" argument? Do you suggest passing pg handler to every model as an additional parameter? Doesn't it look weird? I'm asking because I have the same issue with application structure now (relatively new to Mojo). It seems to me there must DB package which one can use where they need and find dbh singleton there. Looking forward to your thoughts on it.

Cheers
Eugene
Reply all
Reply to author
Forward
0 new messages