]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/DB/ResultSet/BinPkg.pm
e938cdaf294ce1bd0fb3d009f30ed10cffa79083
[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);
50 SELECT id FROM bin_pkg where pkg = ?;
51 SQL
52                },
53                $pkg
54               );
55 }
56 sub get_or_create_bin_pkg_id {
57     my ($self,$pkg) = @_;
58     return $self->result_source->schema->storage->
59         dbh_do(sub {
60                    my ($s,$dbh,$bin_pkg) = @_;
61                    return select_one($dbh,<<'SQL',$bin_pkg,$bin_pkg);
62 WITH ins AS (
63 INSERT INTO bin_pkg (pkg)
64 VALUES (?) ON CONFLICT (pkg) DO NOTHING RETURNING id
65 )
66 SELECT id FROM ins
67 UNION ALL
68 SELECT id FROM bin_pkg where pkg = ?
69 LIMIT 1;
70 SQL
71                },
72                $pkg
73               );
74 }
75
76 1;
77
78 __END__