dbix-class

DBIx::Class and overloading accessors

老子叫甜甜 提交于 2021-02-11 10:46:57
问题 (Similar to, but with more concrete details that, #11526999) My Result Classes have been built using dbicdump , however I wish to overload the default accessor for a date field. Works, but a bodge To hackytest my idea, I simply added an accessor attribute to the created date key of the add_columns call: __PACKAGE__->add_columns( "stamp_id", { data_type => "integer", is_auto_increment => 1, is_nullable => 0, sequence => "timestamp_stamp_id_seq", }, "date", { data_type => "date", is_nullable =>

How do you create foreign keys in attached sqlite databases?

我的梦境 提交于 2020-01-16 00:55:21
问题 I am trying to create a sqlite3 database as a test environment that mimics the production environment. Due to the way production is setup the tables are in multiple schemas. I have setup the classes in DBIx::Class, using $schema->storage->dbh_do to attach the database with the schema, and using $schema-deploy() to create the database. However when it comes to creating the foreign key on the second table I get the following error: DBIx::Class::Schema::deploy(): DBIx::Class::Schema::deploy():

How do I handle errors in methods chains in Perl?

空扰寡人 提交于 2019-12-20 10:41:40
问题 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

DBIX::Class subclassing result class

谁说胖子不能爱 提交于 2019-12-13 03:59:15
问题 I am trying to use a common base class for multiple result classes in DBIX::Class. Reason is - I have few tables with same structure but different names. Here is my base class use utf8; package myapp::Schema::tablebase; use strict; use warnings; use base 'DBIx::Class::Core'; __PACKAGE__->table("unknown"); __PACKAGE__->add_columns( "id", { data_type => "smallint", is_nullable => 0 } #, ... and lot more ); Here is actual result class package myapp::Schema::Result::ActualTable; use base 'myapp:

DBIx::Class resultset creating related data without the select

南笙酒味 提交于 2019-12-13 00:41:16
问题 I'm trying to do something akin to this: $schema->resultset('Foo')->create({ Property => 1, Bar => { Property => 'non-unique', }, }); Where Bar is a belongs_to relation to another table, Bar, with an auto-incrementing primary key. Problem is that behind the scenes, dbix is always doing a select and finding an existing row in Bar with Property = 'non-unique', and inserting that row's PK into Foo. What I'd like it to do instead is create a new row in Bar each time with a new auto-generated

DBIx::Class Wrapping/overloading a column accessor

邮差的信 提交于 2019-12-12 14:42:02
问题 Using DBIx::Class I am trying to manipulate the data of a column whenever it is being updated or retrieved. For instance, before it goes into the database I would like to encrypt it, and whenever it is being accessed I would like to decrypt it. I am following this example in the DBIx::Class::Manual::Cookbook, however I can't seem to get it to work. I have placed the following in my User schema. For testing I am just using the name column, I know it doesn't make sense: __PACKAGE__->add_columns

Mojolicious Deploying database schema

余生长醉 提交于 2019-12-11 12:22:46
问题 I am currently working through this tutorial on building a Mojolicious web app for a project. In the tutorial he talks about using this in a script to create a database schema. my $schema = Moblo::Schema->connect('dbi:SQLite:moblo.db'); $schema->deploy(); and I have tried running perl -e '...' , putting it in different files and everything else I can think of, but with no success. Here is my code on GitHub. I am pretty lost on how to get this thing to create the schema so any help would be

How can I have DBIC persistent database connection in mod_perl?

假装没事ソ 提交于 2019-12-11 01:27:51
问题 I am using mod_perl for my web application. Currently, I plan to use a mysql database across the network. In every CGI request to display_customer_transaction.cgi, my script will Open up database connection across network Perform query on the database using SQL statement Analysis the data retrieved from database Print out the data in HTML format Close the database connection After some profiling, I realize step (1) is the bottleneck. Hence, I wish to avoid opening and closing a database

How do you specify index length when using DBIx::Class?

旧时模样 提交于 2019-12-10 12:18:24
问题 I'm using DBIx::Class and am using the sqlt_deploy_hook to: sub { my ($self, $sqlt_table) = @_; $sqlt_table->add_index(name => 'indexes', fields => [keys %for_indexing]); } Some of the columns I want to index are of type text, or are varchars > 255 length. MySQL doesn't like text indexes unless you specify them with a length, like this: index (long_field(996)) But looking at SQL::Translator::Schema::Table (which has the add_index method) and Index, I see no way to specify the length. add

How to properly use UTF-8-encoded data from Schema inside Catalyst app?

寵の児 提交于 2019-12-10 04:28:59
问题 Data defined inside Catalyst app or in templates has correct encoding and is diplayed well, but from database everything non- Latin1 is converted to ? . I suppose problem should be in model class, which is such: use strict; use base 'Catalyst::Model::DBIC::Schema'; __PACKAGE__->config( schema_class => 'vhinnad::Schema::DB', connect_info => { dsn => 'dbi:mysql:test', user => 'user', password => 'password', { AutoCommit => 1, RaiseError => 1, mysql_enable_utf8 => 1, }, 'on_connect_do' => [ 'SET