DBIx::...ontents(3pm)

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

πŸ’– DBIx::Class::Helper::Schema::LintContents πŸ’–

okay bestie, welcome to the page for DBIx::Class::Helper::Schema::LintContents β€” a whole lil suite of methods that go find violated "constraints" for you. This is part of the User Contributed Perl Documentation, and yeah the title gets squished to DBIx::...ontents(3pm) in the header but you and me both know what it really is 🫢


✨ NAME ✨

DBIx::Class::Helper::Schema::LintContents β€” a whole suite of methods whose entire job is to find violated "constraints" πŸ”


🌸 SYNOPSIS 🌸

package MyApp::Schema;

use parent 'DBIx::Class::Schema';

__PACKAGE__->load_components('Helper::Schema::LintContents');

1;

And then later, somewhere else entirely (like, the part where you actually go looking for crimes):

say "Incorrectly Null Users:";
for ($schema->null_check_source_auto('User')->all) {
   say '* ' . $_->id
}

say "Duplicate Users:";
my $duplicates = $schema->dup_check_source_auto('User');
for (keys %$duplicates) {
   say "Constraint: $_";
   for ($duplicates->{$_}->all) {
      say '* ' . $_->id
   }
}

say "Users with invalid FK's:";
my $invalid_fks = $schema->fk_check_source_auto('User');
for (keys %$invalid_fks) {
   say "Rel: $_";
   for ($invalid_fks->{$_}->all) {
      say '* ' . $_->id
   }
}

πŸ’… DESCRIPTION πŸ’…

So some people out here think constraints make their databases slower. Which is silly, yes, but bestie β€” I have literally been in a similar situation! So I'm here to help you, dear developers 🫢

Basically: this is a suite of methods that let you go find violated "constraints." And to be super clear about what I mean β€” the constraints I'm talking about are the ones you tell DBIx::Class about. Real, actual database-level constraints are, like, pretty much sure to be followed. No cap. ✨


πŸ‘‘ METHODS πŸ‘‘

πŸ¦‹ fk_check_source πŸ¦‹

my $busted = $schema->fk_check_source(
  'User',
  'Group',
  { group_id => 'id' },
);

fk_check_source takes three arguments, bestie:

  1. the from source moniker of a relationship
  2. the to source or source moniker of a relationship
  3. a hash reference representing the columns of the relationship

The return value? A resultset of the from source that do not have a corresponding to row. To be clear (and I love being clear), the example above would hand you back a resultset of User rows that have a group_id pointing at a Group that straight up does not exist 😭 it's giving ghost town.


πŸŽ€ fk_check_source_auto πŸŽ€

my $broken = $schema->fk_check_source_auto('User');

fk_check_source_auto takes a single argument: the source to check. It will check all the foreign key (that is, belongs_to) relationships for missing... "foreign" rows πŸ‘€

The return value is a hashref where the keys are the relationship name and the values are resultsets of the respective violated relationship. Chef's kiss, very organized of it πŸ’…


πŸ“ dup_check_source πŸ“

my $smashed = $schema->fk_check_source( 'Group', ['id'] );

dup_check_source takes two arguments:

  1. the source moniker to be checked
  2. an arrayref of columns that "should be" unique

The return value is a resultset of the source that duplicate the passed columns. So with the example above, the resultset would return all groups that are "duplicates" of other groups based on id. twin behavior, but make it a bug πŸ™ˆ


🧚 dup_check_source_auto 🧚

my $ruined = $schema->dup_check_source_auto('Group');

dup_check_source_auto takes a single argument, which is the name of the resultsource in which to check for duplicates.

It will return a hashref where they keys are the names of the unique constraints to be checked. The values will be resultsets of the respective duplicate rows. Slay, it went and found them all by itself ⭐


πŸ’œ null_check_source πŸ’œ

my $blarg = $schema->null_check_source('Group', ['id']);

null_check_source takes two arguments:

  1. the name of the source to check
  2. an arrayref of columns that should contain no nulls

The return value is simply a resultset of rows that contain nulls where they shouldn't be. nothing but vibes, and the vibes are null 😭


🌈 null_check_source_auto 🌈

my $wrecked = $schema->null_check_source_auto('Group');

null_check_source_auto takes a single argument, which is the name of the resultsource in which to check for nulls.

The return value is simply a resultset of rows that contain nulls where they shouldn't be.

And here's the cute part: this method automatically uses the configured columns that have is_nullable set to false. no manual list needed, she reads the schema herself πŸ’–βœ¨


🫢 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.


okay that's the whole page, bestie, go forth and lint those contents πŸ’…βœ¨

this has been DBIx::...ontents(3pm), generated by perl v5.40.0 on 2024-11-16 β€” mwah, tysm for reading, periodt πŸŽ€πŸ’–

πŸ“¦ where this page comes from