]> git.donarmstrong.com Git - debbugs.git/blob - lib/Debbugs/DB/ResultSet/BinPkg.pm
Debbugs::DB::Util is now a component of Debbugs::DB
[debbugs.git] / lib / 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 sub bin_pkg_and_ver_in_suite {
28     my ($self,$suite) = @_;
29     $suite = $self->result_source->schema->
30         resultset('Suite')->get_suite_id($suite);
31     return
32         $self->search_rs({'bin_associations.suite' => $suite,
33                          },
34                         {join => {bin_vers => ['bin_associations','arch']},
35                          result_class => 'DBIx::Class::ResultClass::HashRefInflator',
36                          columns => [qw(me.pkg  bin_vers.ver arch.arch bin_associations.id)]
37                         },
38                         )->all;
39 }
40
41
42 sub get_bin_pkg_id {
43     my ($self,$pkg) = @_;
44     return $self->result_source->schema->
45         select_one(<<'SQL',$pkg);
46 SELECT id FROM bin_pkg where pkg = ?;
47 SQL
48 }
49
50 sub get_or_create_bin_pkg_id {
51     my ($self,$pkg) = @_;
52     return $self->result_source->schema->
53         select_one(<<'SQL',$pkg,$pkg);
54 WITH ins AS (
55 INSERT INTO bin_pkg (pkg)
56 VALUES (?) ON CONFLICT (pkg) DO NOTHING RETURNING id
57 )
58 SELECT id FROM ins
59 UNION ALL
60 SELECT id FROM bin_pkg where pkg = ?
61 LIMIT 1;
62 SQL
63 }
64
65 1;
66
67 __END__