aboutsummaryrefslogtreecommitdiff
path: root/libbrep/common-traits.hxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2018-05-24 00:25:45 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2018-05-24 17:11:47 +0300
commit6ce19c537bd9de8d3c9821841bc5ed680b762742 (patch)
tree2a487b1d5ec75b05e3001a461f149e14e5a859a8 /libbrep/common-traits.hxx
parent3363e1239973a66722f681999771964e39a98332 (diff)
Adapt to inventing package_name type
Diffstat (limited to 'libbrep/common-traits.hxx')
-rw-r--r--libbrep/common-traits.hxx65
1 files changed, 65 insertions, 0 deletions
diff --git a/libbrep/common-traits.hxx b/libbrep/common-traits.hxx
new file mode 100644
index 0000000..b3c562e
--- /dev/null
+++ b/libbrep/common-traits.hxx
@@ -0,0 +1,65 @@
+// file : libbrep/common-traits.hxx -*- C++ -*-
+// copyright : Copyright (c) 2014-2018 Code Synthesis Ltd
+// 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 <libbpkg/package-name.hxx>
+
+namespace odb
+{
+ namespace pgsql
+ {
+ 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