X-Git-Url: https://git.donarmstrong.com/?a=blobdiff_plain;f=Debbugs%2FDB%2FResultSet%2FBinPkg.pm;fp=Debbugs%2FDB%2FResultSet%2FBinPkg.pm;h=b89cb40fdcd4ee3490a9dead5b5a926bd62c0a4a;hb=53c435119200ab9b1c2538a96b8374c51a078855;hp=0000000000000000000000000000000000000000;hpb=0e8f07fda6e40b5967d9c6b28b3200db22766343;p=debbugs.git diff --git a/Debbugs/DB/ResultSet/BinPkg.pm b/Debbugs/DB/ResultSet/BinPkg.pm new file mode 100644 index 0000000..b89cb40 --- /dev/null +++ b/Debbugs/DB/ResultSet/BinPkg.pm @@ -0,0 +1,66 @@ +# This module is part of debbugs, and is released +# under the terms of the GPL version 2, or any later version. See the +# file README and COPYING for more information. +# Copyright 2017 by Don Armstrong . +use utf8; +package Debbugs::DB::ResultSet::BinPkg; + +=head1 NAME + +Debbugs::DB::ResultSet::BinPkg - Source Package + +=head1 SYNOPSIS + + + +=head1 DESCRIPTION + + + +=cut + +use strict; +use warnings; + +use base 'DBIx::Class::ResultSet'; + +use Debbugs::DB::Util qw(select_one); + +sub bin_pkg_and_ver_in_suite { + my ($self,$suite) = @_; + $suite = $self->result_source->schema-> + resultset('Suite')->get_suite_id($suite); + return + $self->search_rs({'bin_associations.suite' => $suite, + }, + {join => {bin_vers => ['bin_associations','arch']}, + result_class => 'DBIx::Class::ResultClass::HashRefInflator', + columns => [qw(me.pkg bin_vers.ver arch.arch bin_associations.id)] + }, + )->all; +} + + +sub get_bin_pkg_id { + my ($self,$pkg) = @_; + return $self->result_source->schema->storage-> + dbh_do(sub { + my ($s,$dbh,$bin_pkg) = @_; + return select_one($dbh,<<'SQL',$bin_pkg,$bin_pkg); +WITH ins AS ( +INSERT INTO bin_pkg (pkg) +VALUES (?) ON CONFLICT (pkg) DO NOTHING RETURNING id +) +SELECT id FROM ins +UNION ALL +SELECT id FROM bin_pkg where pkg = ? +LIMIT 1; +SQL + }, + $pkg + ); +} + +1; + +__END__