Mojo::Pg in full Mojolicious applications

瀏覽次數:405 次
跳到第一則未讀訊息

sri

未讀,
2015年3月12日 晚上9:15:442015/3/12
收件者: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

未讀,
2015年3月12日 晚上9:28:472015/3/12
收件者:mojol...@googlegroups.com
Already changed a few things, latest version can always be found in the examples directory.


--
sebastian

sri

未讀,
2015年3月13日 凌晨1:47:562015/3/13
收件者: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

未讀,
2015年3月13日 上午8:46:462015/3/13
收件者: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

未讀,
2015年3月13日 下午4:53:142015/3/13
收件者: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

未讀,
2015年3月13日 下午5:38:582015/3/13
收件者: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

未讀,
2015年3月14日 凌晨2:26:342015/3/14
收件者:mojol...@googlegroups.com
Seems reasonable.

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


--
sebastian 

sri

未讀,
2015年4月1日 下午1:26:102015/4/1
收件者: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

未讀,
2015年4月17日 下午3:29:222015/4/17
收件者: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
回覆所有人
回覆作者
轉寄
0 則新訊息