Support for UUID column type?

39 views
Skip to first unread message

Randall Sindlinger

unread,
Jan 27, 2016, 12:34:22 PM1/27/16
to Rose::DB::Object
Hello,

I wanted to confirm that there is no support in Rose::DB::Object for a UUID column type (eg, from PostgreSQL).

I found an rather old perlmonks post indicating that there is no support, but I'm wondering if that has changed at all in the last several years?

If not, the error I'm getting is
Value for id() is too long.  Maximum length is 16 characters.  Value is 36 characters: 1181c9fa-a427-11e5-8c84-02da833577b1 at /home/ubuntu/perl5/perlbrew/perls/perl-5.20.0/lib/site_perl/5.20.0/Rose/Object.pm line 25.
From this old sourceforge post, it sounds like it might be possible to strong-arm a workaround for it, but I'm not entirely clear on how. 
This project is using the Rose::DB::Object::Loader for all of the classes and DB initialization, so perhaps it's something that would need to be added to the ConventionManager?

Alternatively, I might need to just store the UUIDs in a generic Character Varying datatype, which appears to be how it's been handled in other tables previously.

I'm new to working with Rose::DB, as I've just become involved with a project using it on GitHub (GCIS, for those interested)

Thanks in advance for any insights,
-Randall

Konstantin Tokar

unread,
Jan 29, 2016, 6:49:49 PM1/29/16
to Rose::DB::Object
Try 'overflow'->'warn'.

http://search.cpan.org/~jsiracusa/Rose-DB-Object/lib/Rose/DB/Object/Metadata/Column/Scalar.pm

overflow [BEHAVIOR]

Get or set the setting that determines the behavior when the column value is greater than length characters. Valid values for BEHAVIOR are:

fatal

Throw an exception.

truncate

Truncate the column value to the correct length.

warn

Print a warning message.

The default value is "fatal".


Example:

  my @classes = $loader->make_modules(
    db            
=> $db,
    post_init_hook
=> sub {
     
my $meta = shift;
      $meta
->{allow_inline_column_values} = 1;
     
foreach my $column (keys %{$meta->{columns}}) {
       
my $c = $meta->{columns}->{$column};
       
$c->{overflow} = 'warn';
       
next unless defined $c->{default};
       
if ($c->{default} =~ /\S\s/o) {
          $c
->{default} =~ s{\s+$}{}o;
       
}
       
if ($c->{default} eq 'NULL') {
         
delete $c->{default};
       
}
     
}
   
},
 
);


Peter Karman

unread,
Feb 1, 2016, 10:55:32 PM2/1/16
to rose-db...@googlegroups.com
Randall Sindlinger wrote on 1/27/16, 11:34 AM:
> Hello,
>
> I wanted to confirm that there is no support in Rose::DB::Object for a UUID
> column type (eg, from PostgreSQL).
>

Correct. There is no built-in class for a UUID column.


> This project is using the Rose::DB::Object::Loader for all of the classes and DB
> initialization, so perhaps it's something that would need to be added to the
> ConventionManager?
>
> Alternatively, I might need to just store the UUIDs in a generic Character
> Varying datatype, which appears to be how it's been handled in other tables
> previously.
>


I believe the "correct" way to do this, if you want to auto-generate your
classes, is to define a new Column type and tell the Metadata class about it:


package My::Column::UUID;
use strict;
use Rose::DB::Object::Metadata::Column::Scalar;
our @ISA = qw(Rose::DB::Object::Metadata::Column::Scalar);
sub type {'uuid'}
1;


and then in the init code, before you invoke the Loader:

Rose::DB::Object::Metadata->column_type_class( 'uuid' => 'My::Column::UUID' );

my $loader = Rose::DB::Object::Loader->new( ..... );

HTH,
pek

--
Peter Karman . http://peknet.com/ . pe...@peknet.com
Reply all
Reply to author
Forward
0 new messages