[Catalyst] Objects and persistence
Hi, I am approching in those days the Catalyst framework. I am also quite new to persistence of Objects, and therefore before start building my application I need some clarifications, because I don't want to get myself in the wrong direction in the middle of the work. The point is: let's say that I have a good amount of logic of my application coded in a Object oriented way with moose (thus I have all the goodness of a OO approach: so inheritance, moose rooles, moose checks of attributes' types and all what OO gives). Well from what I've read all I have to do to plug-in my code is just use my Objects and methods in some controller: now the problem is that I obviously need persistence. Now, always reading tutorials on the topic,seems that DBIx::Class is the common approach to map Objects to and from rdbms, but from what I've read from the code of this module I think there's slightly abuse of notation: the overmentioned module gives me a OO API to query my RDBM (as also class::DBI gives)hiding all the SQL operations from me(at least partially).Now I could be horribly wrong here... The problem is, how to really maps my (moose) objects to rdbm tables ? DBIx gives me his objects...to use my objects after have retrieved them I need some sort of casting or even re-create(bless) them from the retrieved informations of DBIx every time. Probably I should specify here that I am thinking at the problem after have seen how an OR mapper as Java's Hibernate approaches the Objects -- RDBM problems...that is, strongly map your plain old java classes attributes to table fields, and after some cast I've back my POJOS. Again I could miss the whole point of DBIx:Class and his overall approach: casting or blessing again a lot of objects to apply them my classes methods is worth the overhead that this produce? Or it's better to play just with objectified retrieved informations and re-implement my objects roles (methodes) as controller subroutines and pass them DBIX objects? Thank you -- Marco Vittorini Orgeas ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Objects and persistence
On Fri, January 30, 2009 7:43 am, Marco Vittorini Orgeas wrote: Hi, I am approching in those days the Catalyst framework. I am also quite new to persistence of Objects, and therefore before start building my application I need some clarifications, because I don't want to get myself in the wrong direction in the middle of the work. The point is: let's say that I have a good amount of logic of my application coded in a Object oriented way with moose (thus I have all the goodness of a OO approach: so inheritance, moose rooles, moose checks of attributes' types and all what OO gives). Well from what I've read all I have to do to plug-in my code is just use my Objects and methods in some controller: now the problem is that I obviously need persistence. Now, always reading tutorials on the topic,seems that DBIx::Class is the common approach to map Objects to and from rdbms, but from what I've read from the code of this module I think there's slightly abuse of notation: the overmentioned module gives me a OO API to query my RDBM (as also class::DBI gives)hiding all the SQL operations from me(at least partially).Now I could be horribly wrong here... The problem is, how to really maps my (moose) objects to rdbm tables ? DBIx gives me his objects...to use my objects after have retrieved them I need some sort of casting or even re-create(bless) them from the retrieved informations of DBIx every time. Probably I should specify here that I am thinking at the problem after have seen how an OR mapper as Java's Hibernate approaches the Objects -- RDBM problems...that is, strongly map your plain old java classes attributes to table fields, and after some cast I've back my POJOS. Again I could miss the whole point of DBIx:Class and his overall approach: casting or blessing again a lot of objects to apply them my classes methods is worth the overhead that this produce? Or it's better to play just with objectified retrieved informations and re-implement my objects roles (methodes) as controller subroutines and pass them DBIX objects? Thank you -- Marco Vittorini Orgeas Hi Marco, I don't think this is a Catalyst/DBIx::Class issue as much as an object serialization issue. Once you have serialized your objects, certainly you can store in the DB. Check out this tutorial on Perlmonks: http://www.perlmonks.org/?node_id=8070 Christopher Taranto ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] Objects and persistence
* On Fri, Jan 30 2009, Christopher Taranto wrote: On Fri, January 30, 2009 7:43 am, Marco Vittorini Orgeas wrote: Hi, I am approching in those days the Catalyst framework. I am also quite new to persistence of Objects, and therefore before start building my application I need some clarifications, because I don't want I don't think this is a Catalyst/DBIx::Class issue as much as an object serialization issue. Once you have serialized your objects, certainly you can store in the DB. Check out this tutorial on Perlmonks: http://www.perlmonks.org/?node_id=8070 Things have changed in the 10 years since that article was written. The best serializers are now YAML::XS and Data::Dump::Streamer. Also, if you want a real object database, you want KiokuDB: http://www.iinteractive.com/kiokudb/ It handles object graphs, which means that if you can express it in memory in Perl, you can persist it and query it. It also has a DBI backend (though we use the BDB backend) for storing objects in a DBI-supported relational database, and you can even use the Search::GIN indexer to extract fields from objects into database columns, for fast object lookups. (It is not, however, an ORM -- most of the data is opaque and only makes sense when viewed through KiokuDB.) We are using KiokuDB for some very high-profile applications now, and it works great for us. It is fast, easily scalable (with BDB replication), and saves us the tedium of dealing with a RDBMS (and ORM) that we don't even need. YMMV. Regards, Jonathan Rockway -- print just = another = perl = hacker = if $,=$ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] create model
Hi, I am using Catalyst, DBIx and postrges. My tables have primary keys. When you create a primary key in postres a unique index is implicitly created as well. So the majority of my tables have a constraint that looks like this: CONSTRAINT table_pkey PRIMARY KEY (id) I use catalyst to create my DBIx table definitions like this: create.pl model MyModel The resulting DBIx table definitions reflect the primary key as well as the unique constraint like this: __PACKAGE__-set_primary_key(id); __PACKAGE__-add_unique_constraint(table_pkey, [id]); So if I write a query like this: my $result = $c-model('Schema::Table')-find( 'x' ); it results in the following SQL: SELECT x,y,z FROM table me WHERE ( ( me.id = 'x' ) OR ( me.id = 'x' ) ); This is happening because the 'find' function checks all the unique constraints on the table, and in this case there are 2 ('primary' : 'id' and 'table_pkey' : 'id') I can get around this by writing my query like this: my $result = $c-model('Schema::Table')-find( { 'id'= 'x' }, { 'key'='primary' } ); But that is a pain. Does anyone know a way that I can stop the 2nd unique constraint: __PACKAGE__-add_unique_constraint(table_pkey, [id]); from being generated in my table definition files? -- View this message in context: http://www.nabble.com/create-model-tp21503833p21503833.html Sent from the Catalyst Web Framework mailing list archive at Nabble.com. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
RE: [Catalyst] Re: Supressing passwords in debug messages
Tomas Doran wrote on 2009-01-29: On 29 Jan 2009, at 18:53, Byron Young wrote: Hi - I'm not sure what the repost policy on patches, but I have the feeling this one slipped through the cracks. Let me know if it's generally annoying to repost stuff. No, reposting if things get dropped on the floor good :) If you have time, then arriving on #catalyst-dev and making noise also gets stuff done. This is a patch that allows you to suppress printing the value of certain query or body parameters when running Catalyst in debug mode - For example, if you want to hide passwords sent from the login page, you can put this in your app config (yaml): Having been discussed in #catalyst-dev, we think that the patch could be made both more generic, and more elegant. The key thing is to split the table drawing, and the data filtering into separate methods (maybe filter_debug_data?). This would then allow you to filter per-type, and support things such as redact_parameters (all), redact_body_parameters, redact_query_parameters, and even potentially to add support for filtering things like the URI (I can see use-cases where that'd be significant - e.g. not wanting to log session IDs which are in URIs).. Have a look at the way the debug screen stuff works (in Catalyst::Engine), this is more elegant and would also benefit from being able to have things redacted I guess - as with the current patch, you're going to display the things you're redacting in the logs to the end user... Cheers t0m Tom, Thanks for the feedback. I think you're referring to $c-dump_these() and it's usage in finalize_error(). I'll refactor log_parameters() to call a separate method that will return the params to log, akin to dump_these(). Not sure when I'll have time for it since my current solution is working for me and I have some big deadlines coming up. Hopefully within the next month. Thanks byron ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] create model
On 30 Jan 2009, at 21:40, gdewitt wrote: Hi, I am using Catalyst, DBIx and postrges. My tables have primary keys. When you create a primary key in postres a unique index is implicitly created as well. So the majority of my tables have a constraint that looks like this: CONSTRAINT table_pkey PRIMARY KEY (id) I use catalyst to create my DBIx table definitions like this: create.pl model MyModel The resulting DBIx table definitions reflect the primary key as well as the unique constraint like this: __PACKAGE__-set_primary_key(id); __PACKAGE__-add_unique_constraint(table_pkey, [id]); So if I write a query like this: my $result = $c-model('Schema::Table')-find( 'x' ); it results in the following SQL: SELECT x,y,z FROM table me WHERE ( ( me.id = 'x' ) OR ( me.id = 'x' ) ); This is happening because the 'find' function checks all the unique constraints on the table, and in this case there are 2 ('primary' : 'id' and 'table_pkey' : 'id') I can get around this by writing my query like this: my $result = $c-model('Schema::Table')-find( { 'id'= 'x' }, { 'key'='primary' } ); But that is a pain. Does anyone know a way that I can stop the 2nd unique constraint: __PACKAGE__-add_unique_constraint(table_pkey, [id]); from being generated in my table definition files? simple. Ignore the fact that Pg created a unique index to go with the primary key - you created just a primary key, what Pg does is irrelevant. i.e. get rid of the add_unique_constraint. That is only needed if you explicitly create (and want to search on) a subsequent unique constraint. -ash ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
[Catalyst] Re: decoding in core (Was: [Announce] Catalyst-Runtime-5.8000_05)
* Bill Moseley mose...@hank.org [2009-01-29 17:05]: Neither of the existing plugins do it correctly (IMO), as they only decode parameters leaving body_parameters as octets, and don't look at the request for the charset, IIRC. […] uri_for() rightly encodes to octets before escaping, but it always encodes to utf-8. Is it assumed that query parameters are always utf-8 or should they be decoded with the charset specified in the request? The URI should always be assumed to be UTF-8 encoded octets. The body should be decoded according to the charset declared in the header by the browser. Regards, -- Aristotle Pagaltzis // http://plasmasturm.org/ ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/
Re: [Catalyst] create model
On Fri, Jan 30, 2009 at 01:40:40PM -0800, gdewitt wrote: my $result = $c-model('Schema::Table')-find( 'x' ); Does this stop it from using _all_ unique constraints? my $result = $c-model('Schema::Table')-find( 'x', { key = 'primary' } ); -- Chisel Wright e: chi...@herlpacker.co.uk w: http://www.herlpacker.co.uk/ Stop pedanting. All nouns can be verbed. ___ List: Catalyst@lists.scsys.co.uk Listinfo: http://lists.scsys.co.uk/cgi-bin/mailman/listinfo/catalyst Searchable archive: http://www.mail-archive.com/catalyst@lists.scsys.co.uk/ Dev site: http://dev.catalyst.perl.org/