X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=blobdiff_plain;f=lib%2FDBIx%2FClass%2FResultSource.pm;h=e7ab22d80cf2d6de18987fe5627ab50c7c122f93;hb=8f4b5c084378a4c457c8893404aded4398c1d811;hp=075c331ae045ed7389fd958aa5fccd9bbd8806e5;hpb=d2fcb9b3612958ecc794acae77520f3da06d3c5b;p=dbsrgits%2FDBIx-Class-Historic.git diff --git a/lib/DBIx/Class/ResultSource.pm b/lib/DBIx/Class/ResultSource.pm index 075c331..e7ab22d 100644 --- a/lib/DBIx/Class/ResultSource.pm +++ b/lib/DBIx/Class/ResultSource.pm @@ -361,22 +361,22 @@ sub column_info { my ($self, $column) = @_; $self->throw_exception("No such column $column") unless exists $self->_columns->{$column}; - #warn $self->{_columns_info_loaded}, "\n"; + if ( ! $self->_columns->{$column}{data_type} - and $self->column_info_from_storage and ! $self->{_columns_info_loaded} - and $self->schema and $self->storage ) + and $self->column_info_from_storage + and $self->schema and my $stor = $self->storage ) { $self->{_columns_info_loaded}++; - my $info = {}; - my $lc_info = {}; # try for the case of storage without table try { - $info = $self->storage->columns_info_for( $self->from ); - for my $realcol ( keys %{$info} ) { - $lc_info->{lc $realcol} = $info->{$realcol}; - } + my $info = $stor->columns_info_for( $self->from ); + my $lc_info = { map + { (lc $_) => $info->{$_} } + ( keys %$info ) + }; + foreach my $col ( keys %{$self->_columns} ) { $self->_columns->{$col} = { %{ $self->_columns->{$col} }, @@ -385,6 +385,7 @@ sub column_info { } }; } + return $self->_columns->{$column}; } @@ -412,6 +413,82 @@ sub columns { return @{$self->{_ordered_columns}||[]}; } +=head2 columns_info + +=over + +=item Arguments: \@colnames ? + +=item Return value: Hashref of column name/info pairs + +=back + + my $columns_info = $source->columns_info; + +Like L but returns information for the requested columns. If +the optional column-list arrayref is ommitted it returns info on all columns +currently defined on the ResultSource via L. + +=cut + +sub columns_info { + my ($self, $columns) = @_; + + my $colinfo = $self->_columns; + + if ( + first { ! $_->{data_type} } values %$colinfo + and + ! $self->{_columns_info_loaded} + and + $self->column_info_from_storage + and + $self->schema + and + my $stor = $self->storage + ) { + $self->{_columns_info_loaded}++; + + # try for the case of storage without table + try { + my $info = $stor->columns_info_for( $self->from ); + my $lc_info = { map + { (lc $_) => $info->{$_} } + ( keys %$info ) + }; + + foreach my $col ( keys %$colinfo ) { + $colinfo->{$col} = { + %{ $colinfo->{$col} }, + %{ $info->{$col} || $lc_info->{lc $col} || {} } + }; + } + }; + } + + my %ret; + + if ($columns) { + for (@$columns) { + if (my $inf = $colinfo->{$_}) { + $ret{$_} = $inf; + } + else { + $self->throw_exception( sprintf ( + "No such column '%s' on source %s", + $_, + $self->source_name, + )); + } + } + } + else { + %ret = %$colinfo; + } + + return \%ret; +} + =head2 remove_columns =over @@ -537,6 +614,34 @@ sub _pri_cols { return @pcols; } +=head2 sequence + +Manually define the correct sequence for your table, to avoid the overhead +associated with looking up the sequence automatically. The supplied sequence +will be applied to the L of each L + +=over 4 + +=item Arguments: $sequence_name + +=item Return value: undefined + +=back + +=cut + +sub sequence { + my ($self,$seq) = @_; + + my $rsrc = $self->result_source; + my @pks = $rsrc->primary_columns + or next; + + $_->{sequence} = $seq + for values %{ $rsrc->columns_info (\@pks) }; +} + + =head2 add_unique_constraint =over 4