]> git.donarmstrong.com Git - debbugs.git/blob - lib/Debbugs/DB/ResultSet/Message.pm
Debbugs::DB::Util is now a component of Debbugs::DB
[debbugs.git] / lib / 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 sub get_message_id {
28     my ($self,$msg_id,$from,$to,$subject) = @_;
29     return $self->result_source->schema->
30         select_one(<<'SQL',@_,@_);
31 WITH ins AS (
32 INSERT INTO message (msgid,from_complete,to_complete,subject) VALUES (?,?,?,?)
33  ON CONFLICT (msgid,from_complete,to_complete,subject) DO NOTHING RETURNING id
34 )
35 SELECT id FROM ins
36 UNION ALL
37 SELECT id FROM correspondent WHERE msgid=? AND from_complete = ?
38 AND to_complete = ? AND subject = ?
39 LIMIT 1;
40 SQL
41 }
42
43
44
45 1;
46
47 __END__