DBIx::...Columns(3pm)

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

✨ NAME ✨

okay so bestie, this is DBIx::Class::Helper::ResultSet::AutoRemoveColumns (it's a Perl module, from the User Contributed Perl Documentation crew πŸ’…) and it does exactly one iconic thing: it automatically removes columns from a ResultSet. no cap. that's the whole gig. πŸ’–


🌸 SYNOPSIS 🌸

like, here's the vibe. you set up your Result class:

package MySchema::Result::Bar;

use strict;
use warnings;

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

__PACKAGE__->table('KittenRobot');
__PACKAGE__->add_columns(
   id => {
      data_type         => 'integer',
      is_auto_increment => 1,
   },
   kitten => {
      data_type         => 'integer',
   },
   robot => {
      data_type         => 'text',
      is_nullable       => 1,
   },
   your_mom => {
      data_type         => 'blob',
      is_nullable       => 1,
      remove_column     => 0,
   },
);

1;

then your ResultSet class pulls in the component:

package MySchema::ResultSet::Bar;

use strict;
use warnings;

use parent 'DBIx::Class::ResultSet';

__PACKAGE__->load_components('Helper::ResultSet::AutoRemoveColumns');

and boom πŸŽ€ the heavy columns just… stop showing up. slay.


πŸ¦‹ DESCRIPTION πŸ¦‹

so this component automatically removes "heavy-weight" columns. and when we say heavy-weight, we mean it literally, specifically these data types:

  • text
  • ntext
  • blob
  • clob
  • bytea

those ones. all of them. gone. by default. πŸ™ˆ

but bestie, you're the main character β€” you get a say. you can use the remove_column key inside the column info to say directly whether or not a column should get auto-removed. it's giving control. it's giving agency. πŸ‘‘

and if you wanna apply this whole thing across your entire schema, go peek at "NOTE" in DBIx::Class::Helper::ResultSet β€” there's a nice way to do it. iykyk. ✨

πŸ’… METHODS πŸ’…

_should_column_fetch

here's how you call it:

$self->_should_column_fetch('kitten')

it returns true if a column should be fetched, and false if it shouldn't. simple as that fr fr.

the logic: it fetches a column if the column is not one of text, ntext, blob, clob, or bytea β€” or if remove_column is set to true. either one gets you in. 🫢

now. say you're the type of girl who wants to only explicitly state which columns to remove and nothing else? you'd override this method like this:

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

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

   return exists $info->{remove_column}
       ? $info->{remove_column}
       : 0;
}

look at that. chef's kiss. 😭✨

fetchable_columns

simply returns a list of columns that are fetchable. that's it. that's the whole method. iconic behaviour, honestly. πŸ‘‘


πŸŽ€ 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, no notes πŸ’œ this was served up on the 2024-11-16 by perl v5.40.0 β€” thanks for reading, mwah πŸ’‹πŸŒΈπŸ¦‹

πŸ“¦ where this page comes from