]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/DB/ResultSet/BinPkg.pm
b89cb40fdcd4ee3490a9dead5b5a926bd62c0a4a
[debbugs.git] / Debbugs / DB / ResultSet / BinPkg.pm
1 # This module is part of debbugs, and is released
2 # under the terms of the GPL version 2, or any later version. See the
3 # file README and COPYING for more information.
4 # Copyright 2017 by Don Armstrong <don@donarmstrong.com>.
5 use utf8;
6 package Debbugs::DB::ResultSet::BinPkg;
7
8 =head1 NAME
9
10 Debbugs::DB::ResultSet::BinPkg - Source Package
11
12 =head1 SYNOPSIS
13
14
15
16 =head1 DESCRIPTION
17
18
19
20 =cut
21
22 use strict;
23 use warnings;
24
25 use base 'DBIx::Class::ResultSet';
26
27 use Debbugs::DB::Util qw(select_one);
28
29 sub bin_pkg_and_ver_in_suite {
30     my ($self,$suite) = @_;
31     $suite = $self->result_source->schema->
32         resultset('Suite')->get_suite_id($suite);
33     return
34         $self->search_rs({'bin_associations.suite' => $suite,
35                          },
36                         {join => {bin_vers => ['bin_associations','arch']},
37                          result_class => 'DBIx::Class::ResultClass::HashRefInflator',
38                          columns => [qw(me.pkg  bin_vers.ver arch.arch bin_associations.id)]
39                         },
40                         )->all;
41 }
42
43
44 sub get_bin_pkg_id {
45     my ($self,$pkg) = @_;
46     return $self->result_source->schema->storage->
47         dbh_do(sub {
48                    my ($s,$dbh,$bin_pkg) = @_;
49                    return select_one($dbh,<<'SQL',$bin_pkg,$bin_pkg);
50 WITH ins AS (
51 INSERT INTO bin_pkg (pkg)
52 VALUES (?) ON CONFLICT (pkg) DO NOTHING RETURNING id
53 )
54 SELECT id FROM ins
55 UNION ALL
56 SELECT id FROM bin_pkg where pkg = ?
57 LIMIT 1;
58 SQL
59                },
60                $pkg
61               );
62 }
63
64 1;
65
66 __END__