]> git.donarmstrong.com Git - debbugs.git/blob - lib/Debbugs/DB/ResultSet/BinVer.pm
move Debbugs to lib
[debbugs.git] / lib / Debbugs / DB / ResultSet / BinVer.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::BinVer;
7
8 =head1 NAME
9
10 Debbugs::DB::ResultSet::BinVer - Source Version association
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
30 sub get_bin_ver_id {
31     my ($self,$bin_pkg_id,$bin_ver,$arch_id,$src_ver_id) = @_;
32     return $self->result_source->schema->storage->
33         dbh_do(sub {
34                    my ($s,$dbh,$bp_id,$bv,$a_id,$sv_id) = @_;
35                    return select_one($dbh,<<'SQL',
36 WITH ins AS (
37 INSERT INTO bin_ver (bin_pkg,src_ver,arch,ver)
38 VALUES (?,?,?,?) ON CONFLICT (bin_pkg,arch,ver) DO NOTHING RETURNING id
39 )
40 SELECT id FROM ins
41 UNION ALL
42 SELECT id FROM bin_ver WHERE bin_pkg = ? AND arch = ? AND ver = ?
43 LIMIT 1;
44 SQL
45                                      $bp_id,$sv_id,
46                                      $a_id,$bv,
47                                      $bp_id,$a_id,
48                                      $bv);
49                },
50                $bin_pkg_id,$bin_ver,$arch_id,$src_ver_id
51               );
52 }
53
54 1;
55
56 __END__