aboutsummaryrefslogtreecommitdiff
path: root/libbrep/common-traits.hxx
blob: 141a738a00ba5f5de8a91e8cbe9ff423d79ff455 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// file      : libbrep/common-traits.hxx -*- C++ -*-
// license   : MIT; see accompanying LICENSE file

#ifndef LIBBREP_COMMON_TRAITS_HXX
#define LIBBREP_COMMON_TRAITS_HXX

#include <string>
#include <cstddef> // size_t
#include <utility> // move()

#include <odb/pgsql/traits.hxx>

#include <libbutl/target-triplet.hxx>

#include <libbpkg/package-name.hxx>

namespace odb
{
  namespace pgsql
  {
    // target_triplet
    //
    template <>
    class value_traits<butl::target_triplet, id_string>:
      value_traits<std::string, id_string>
    {
    public:
      using value_type = butl::target_triplet;
      using query_type = butl::target_triplet;
      using image_type = details::buffer;

      using base_type = value_traits<std::string, id_string>;

      static void
      set_value (value_type& v,
                 const details::buffer& b,
                 std::size_t n,
                 bool is_null)
      {
        std::string s;
        base_type::set_value (s, b, n, is_null);
        v = !s.empty () ? value_type (s) : value_type ();
      }

      static void
      set_image (details::buffer& b,
                 std::size_t& n,
                 bool& is_null,
                 const value_type& v)
      {
        base_type::set_image (b, n, is_null, v.string ());
      }
    };

    // package_name
    //
    template <>
    class value_traits<bpkg::package_name, id_string>:
      value_traits<std::string, id_string>
    {
    public:
      using value_type = bpkg::package_name;
      using query_type = bpkg::package_name;
      using image_type = details::buffer;

      using base_type = value_traits<std::string, id_string>;

      static void
      set_value (value_type& v,
                 const details::buffer& b,
                 std::size_t n,
                 bool is_null)
      {
        std::string s;
        base_type::set_value (s, b, n, is_null);
        v = !s.empty () ? value_type (std::move (s)) : value_type ();
      }

      static void
      set_image (details::buffer& b,
                 std::size_t& n,
                 bool& is_null,
                 const value_type& v)
      {
        base_type::set_image (b, n, is_null, v.string ());
      }
    };

    template <>
    struct type_traits<bpkg::package_name>
    {
      static const database_type_id db_type_id = id_string;

      struct conversion
      {
        static const char* to () {return "(?)::CITEXT";}
      };
    };
  }
}

#endif // LIBBREP_COMMON_TRAITS_HXX