]> git.donarmstrong.com Git - debbugs.git/blob - Debbugs/DB/ResultSet/Message.pm
switch to compatibility level 12
[debbugs.git] / Debbugs / DB / ResultSet / Message.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::Message;
7
8 =head1 NAME
9
10 Debbugs::DB::ResultSet::Message - Message table actions
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 get_message_id {
30     my ($self,$msg_id,$from,$to,$subject) = @_;
31     return $self->result_source->schema->storage->
32         dbh_do(sub {
33                    my ($dbh,$msg_id,$from,$to,$subject) = @_;
34                    my $mi = select_one($dbh,<<'SQL',@_[1..$#_],@_[1..$#_]);
35 WITH ins AS (
36 INSERT INTO message (msgid,from_complete,to_complete,subject) VALUES (?,?,?,?)
37  ON CONFLICT (msgid,from_complete,to_complete,subject) DO NOTHING RETURNING id
38 )
39 SELECT id FROM ins
40 UNION ALL
41 SELECT id FROM correspondent WHERE msgid=? AND from_complete = ?
42 AND to_complete = ? AND subject = ?
43 LIMIT 1;
44 SQL
45                    return $mi;
46 },
47                @_[1..$#_]
48               );
49
50 }
51
52
53
54 1;
55
56 __END__