How to add_column for table with composite type via DBIx::Class?

71 views Asked by At

https://www.postgresql.org/docs/current/rowtypes.html#ROWTYPES-DECLARING

Whenever you create a table, a composite type is also automatically created, with the same name as the table

So if such composite type is returned by database server (I am using PostgreSQL). How should I declare my column?

package App::Schema::Result::Example;

use utf8;
use Modern::Perl;
use parent 'App::Schema::Result';



my $X =  __PACKAGE__;
$X->table_class('DBIx::Class::ResultSource::View');

$X->table('example');
$X->result_source_instance->is_virtual(1);
$X->result_source_instance->view_definition( <<'SQL' );
  select t from my_table t; -- NOTICE: I return row as composite type
SQL

$X->add_columns(
    t => {
        data_type => '????',
    },
);

If I for my_table already have App::Schema::Result::Table, can I just write: data_type => my_table or data_type => App::Schema::Result::Table?

In case if I can not. How to explain DBIx::Class how to extract data from t column?

1

There are 1 answers

0
Eugen Konkov On

I found a thread how to accomplish this: https://groups.google.com/g/perl.dbd.pg/c/roY9y-Tq198?pli=1

So we have tow ways:

  1. Use PGObject perl module
  2. Use InflateColumn functionality