dbix-class

How can I select only specific columns when using prefetch in DBIx-Class?

橙三吉。 提交于 2019-12-07 17:53:32
问题 I'm struggling with fairly fundamental DBIx-Class prefetch usage. I want to limit the columns that are returned from joined tables when prefetch is used. This: my $rs = $schema->resultset('CD')->search( {}, # No searching restrictions through WHERE clause { prefetch => [qw/ artist /], columns => [qw/ title artist.name /], } ); Generates this SQL: SELECT cd.title, artist.* FROM cd JOIN artist ON cd.artist = artist.id But I don't want to haul down all of the artist columns, just the cd.title

Can Perl DBIx::Class override the way a column is retrieved from the database?

穿精又带淫゛_ 提交于 2019-12-07 07:47:35
问题 I have never used DBIx::Class until today, so I'm completely new at it. I'm not sure if this is possible or not, but basically I have a table in my SQLite database that has a timestamp column in it. The default value for the timestamp column is "CURRENT_TIMESTAMP". SQLite stores this in the GMT timezone, but my server is in the CDT timeszone. My SQLite query to get the the timestamp in the correct timezone is this: select datetime(timestamp, 'localtime') from mytable where id=1; I am

How to avoid race conditions when using the find_or_create method of DBIx::Class::ResultSet?

亡梦爱人 提交于 2019-12-07 06:15:41
问题 From the documentation for find_or_create: Note: Because find_or_create() reads from the database and then possibly inserts based on the result, this method is subject to a race condition. Another process could create a record in the table after the find has completed and before the create has started. To avoid this problem, use find_or_create() inside a transaction. Is it enough to just use find_or_create() inside a transaction in PostgreSQL? 回答1: No, the documentation is incorrect. Using a

Formatting timestamp field for output in TemplateToolkit

独自空忆成欢 提交于 2019-12-06 09:50:54
问题 I'm using Perl with Catalyst framework, DBIx class as ORM, TT for views, Postgresql as DB. I have a column with 'timestamp without timezone' type, and if I do manual query in Postgres the column value is in such format 2012-08-30 21:30:14 , but when I print the value in TT view file I get it like this 2012-08-30T15:03:13 , so obviously it gets formatted but by what exactly I can't tell. I want to use Template::Plugin::Date to format output timestamps, but I get Catalyst error: Couldn't render

How can I select only specific columns when using prefetch in DBIx-Class?

社会主义新天地 提交于 2019-12-06 03:01:16
I'm struggling with fairly fundamental DBIx-Class prefetch usage. I want to limit the columns that are returned from joined tables when prefetch is used. This: my $rs = $schema->resultset('CD')->search( {}, # No searching restrictions through WHERE clause { prefetch => [qw/ artist /], columns => [qw/ title artist.name /], } ); Generates this SQL: SELECT cd.title, artist.* FROM cd JOIN artist ON cd.artist = artist.id But I don't want to haul down all of the artist columns, just the cd.title and artist.name columns (in this example, my real use case is more complex). The columns feature seems to

How to avoid race conditions when using the find_or_create method of DBIx::Class::ResultSet?

萝らか妹 提交于 2019-12-05 09:01:19
From the documentation for find_or_create : Note: Because find_or_create() reads from the database and then possibly inserts based on the result, this method is subject to a race condition. Another process could create a record in the table after the find has completed and before the create has started. To avoid this problem, use find_or_create() inside a transaction. Is it enough to just use find_or_create() inside a transaction in PostgreSQL? No, the documentation is incorrect. Using a transaction alone does not avoid this problem. It only guarantees that the whole transaction is rolled back

Formatting timestamp field for output in TemplateToolkit

荒凉一梦 提交于 2019-12-04 15:14:37
I'm using Perl with Catalyst framework, DBIx class as ORM, TT for views, Postgresql as DB. I have a column with 'timestamp without timezone' type, and if I do manual query in Postgres the column value is in such format 2012-08-30 21:30:14 , but when I print the value in TT view file I get it like this 2012-08-30T15:03:13 , so obviously it gets formatted but by what exactly I can't tell. I want to use Template::Plugin::Date to format output timestamps, but I get Catalyst error: Couldn't render template "xxx/list.tt2: date error - bad time/date string: expects 'h:m:s d:m:y' got: '2012-08-30T21

Can I pretty-print the DBIC_TRACE output in DBIx::Class?

家住魔仙堡 提交于 2019-12-03 04:00:27
问题 Setting the DBIC_TRACE environment variable to true: BEGIN { $ENV{DBIC_TRACE} = 1 } generates very helpful output, especially showing the SQL query that is being executed, but the SQL query is all on one line. Is there a way to push it through some kinda "sql tidy" routine to format it better, perhaps breaking it up over multiple lines? Failing that, could anyone give me a nudge into where in the code I'd need to hack to add such a hook? And what the best tool is to accept a badly formatted

How do I handle errors in methods chains in Perl?

寵の児 提交于 2019-12-02 23:57:12
What is the best way to deal with exceptions threw in a method chaining in Perl? I want to assign a value of 0 or undef if any of the methods chained throw an exception Code sample: my $x = $obj->get_obj->get_other_obj->get_another_obj->do_something; What the best way to do it? Do I have to wrap in a try/catch/finally statement everytime? The context I want to apply this is: Im working in web development using Catalyst and DBIC and I do a lot of chained resultsets and if some of this resultset throw an exception I just want to assign a value of 0 or undef and then treat this error in the

Can I pretty-print the DBIC_TRACE output in DBIx::Class?

别说谁变了你拦得住时间么 提交于 2019-12-02 16:20:57
Setting the DBIC_TRACE environment variable to true: BEGIN { $ENV{DBIC_TRACE} = 1 } generates very helpful output, especially showing the SQL query that is being executed, but the SQL query is all on one line. Is there a way to push it through some kinda "sql tidy" routine to format it better, perhaps breaking it up over multiple lines? Failing that, could anyone give me a nudge into where in the code I'd need to hack to add such a hook? And what the best tool is to accept a badly formatted SQL query and push out a nicely formatted one? "nice formatting" in this context simply means better