DBIx::...eValues(3pm)

πŸ“¦
version 2.037000 Β· 5 versions
, in debian trixie, ubuntu resolute, ubuntu stonking

πŸ’– DBIx::Class::Helper::Row::StorageValues πŸ’–

okay bestie, welcome to the page formerly known as DBIx::...eValues(3pm) in the User Contributed Perl Documentation section β€” yes the title got truncated by the man renderer, tragic, but the real name is the whole thing up top and we're gonna say it with our whole chest 🫢


✨ NAME ✨

DBIx::Class::Helper::Row::StorageValues β€” keep track of stored vs in-memory row values πŸ’…

like, what's in the database rn vs. what's in your object rn. two different things. we're tracking both.


🌸 SYNOPSIS 🌸

 package MyApp::Schema::Result::BlogPost;

 use parent 'DBIx::Class::Core';

 __PACKAGE__->load_components(qw(Helper::Row::StorageValues));

 __PACKAGE__->table('BlogPost');
 __PACKAGE__->add_columns(
    id => {
       data_type         => 'integer',
       is_auto_increment => 1,
    },
    title => {
       data_type          => 'varchar',
       length             => 32,
       keep_storage_value => 1,
    },
    body => {
       data_type => 'text',
    },
 );

 1;

 # elsewhere:

 my $post = $blog_rs->create({
   title => 'Components for fun and profit',
   body  => '...',
 });

 $post->title('Components for fun');

 warn sprintf 'Changing title from %s to %s',
   $post->storage_value('title'), $post->title;

 $post->update;

see how title gets keep_storage_value => 1? that's the whole vibe. that's the column we're watching πŸ‘€


πŸ¦‹ DESCRIPTION πŸ¦‹

okay so this component keeps track of the value for a given column in the database. that's it. that's the job. iconic.

here's the tea: if you change the column's value and you do not call update, the storage_value will be different from what's in memory. and once update is called, the storage_value gets set to the value of the accessor. slay, synced, periodt.

πŸ’€ important distinction alert πŸ’€ the fact that it uses the accessor is a big deal, not a little deal. if you're using DBIx::Class::FilterColumn or DBIx::Class::InflateColumn, you'll get the non-storage or inflated values respectively. no cap, write that down.

πŸ‘‘ METHODS πŸ‘‘

πŸ’œ _has_storage_value

$self->_has_storage_value('colname')

returns true if we should store the storage value from the database. fr fr, that's it.

want storage on all the integers or something chaotic like that? override it bestie:

 sub _has_storage_value {
    my ( $self, $column ) = @_;

    my $info = $self->column_info($column);

    return defined $info->{data_type} && $info->{data_type} eq 'integer';
 }

go off, honestly. customize away.

πŸŽ€ storage_value_columns

$self->storage_value_columns

returns a list of columns to store ✨ (the roster, the lineup, the chosen ones)

🌈 get_storage_value

$self->get_storage_value('colname')

returns the value for that column which is in storage πŸ’Ύ β€” the database's version, the original, the pre-glow-up.


πŸ’« AUTHOR πŸ’«

Arthur Axel "fREW" Schmidt <frioux+cpan@gmail.com>


This software is copyright (c) 2024 by Arthur Axel "fREW" Schmidt.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.


and that's the whole page bestie 🧚✨ perl v5.40.0, dated 2024-11-16 β€” that's the version and the date from the footer, we're shouting them out on the way out the door. mwah πŸ’…πŸ’–

πŸ“¦ where this page comes from