How to efficiently store a DBIx::Class object in session ? #2163
-
I don't know if this is possible at all, I suspect it is not, but I'm asking to be sure.
Is there a way to store directly the DBIx::Class user object as I can do within the stash, in the session? Or is this the only available solution to get information about the logged in user? |
Beta Was this translation helpful? Give feedback.
Replies: 5 comments
-
I'm learning and others likely know best/better, so more asking questions to provoke thought: I don't know if the query might become outdated if stuff in the database changes during a session, and otherwise you could simply run this once when authentication is successful, and then stash the user object in the stash? Is it possible to directly write a ResultSet that takes/expects a username param, and then just call that from the database object, after setting up a db plugin that becomes your glue between mojolicious and dbix class? Hm. There's a very basic example here, This other example app uses Mojo::Pg instead of DBIX::Class and is also super simple - a blog app with only posts, and no actual users. Ah well. I found it useful for how they setup a database helper. I've heard users of DBIx::Class do something similar to provide a thin layer of "glue" between Mojolicious and DBIx::Class, and beyond that I'd have to defer you to others that do this more often - yourself included. You've obviously been using both together yourself, whereas I've only used Mojo::SQLite |
Beta Was this translation helpful? Give feedback.
-
Oh - your profile says you're Perl and PostgreSQL passionate. You probably know Mojo::Pg and all that already, ^_^. I'd be curious to learn more about DBIx::Class with Mojolicious, if you've tips in that regard. |
Beta Was this translation helpful? Give feedback.
-
I wouldn't recommend trying to store an object in the session for a few reasons:
What you have there is the best option, just store a PK in the session + pull it in during an |
Beta Was this translation helpful? Give feedback.
-
I don't have any tips, that's why I was asking. So far I've created only an helper method |
Beta Was this translation helpful? Give feedback.
-
Ok thanks, at least I guessed the right approach! |
Beta Was this translation helpful? Give feedback.
I wouldn't recommend trying to store an object in the session for a few reasons:
TO_JSON
method, which you'd still have to make back into a proper object on your sideWhat you have there is the best option, just store a PK in the session…