NAME
DBIx::Class::ResultSet::Void - improve DBIx::Class::ResultSet with void context
VERSION
version 0.07
SYNOPSIS
my $rs = $schema->resultset('CD');
$rs->find_or_create( {
artist => 'Massive Attack',
title => 'Mezzanine',
} );
As ResultSet subclass in Schema.pm:
__PACKAGE__->load_namespaces(
default_resultset_class => '+DBIx::Class::ResultSet::Void'
);
Or in Schema/CD.pm
__PACKAGE__->resultset_class('DBIx::Class::ResultSet::Void');
Or in ResultSet/CD.pm
use base 'DBIx::Class::ResultSet::Void';
DESCRIPTION
The API is the same as DBIx::Class::ResultSet.
use exists
instead of find
unless defined wantarray.
(Thank ribasushi to tell me count
is bad)
METHODS
exists
$rs->exists( { id => 1 } );
It works like:
$rs->search( { id => 1 }, { rows => 1, select => [1] } )->single;
It is a little faster than
count
if you don't care the real count.find_or_create
"find_or_create" in DBIx::Class::ResultSet:
$rs->find_or_create( { id => 1, name => 'A' } );
produces SQLs like:
# SELECT me.id, me.name FROM item me WHERE ( me.id = ? ): '1' # INSERT INTO item ( id, name) VALUES ( ?, ? ): '1', 'A'
but indeed
SELECT 1 ... LIMIT 1
is performing a little better than me.id, me.namethis module DBIx::Class::ResultSet::Void produces SQLs like:
# SELECT 1 FROM item me WHERE ( me.id = ? ) LIMIT 1: '1' # INSERT INTO item ( id, name) VALUES ( ?, ? ): '1', 'A'
we would delegate it DBIx::Class::ResultSet under context like:
my $row = $rs->find_or_create( { id => 1, name => 'A' } );
update_or_create
"update_or_create" in DBIx::Class::ResultSet:
$rs->update_or_create( { id => 1, name => 'B' } );
produces SQLs like:
# SELECT me.id, me.name FROM item me WHERE ( me.id = ? ): '1' # UPDATE item SET name = ? WHERE ( id = ? ): 'B', '1'
this module:
# SELECT 1 FROM item me WHERE ( me.id = ? ) LIMIT 1: '1' # UPDATE item SET name = ? WHERE ( id = ? ): 'B', '1'
AUTHOR
Fayland Lam <fayland@gmail.com>
COPYRIGHT AND LICENSE
This software is copyright (c) 2017 by Fayland Lam.
This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.