Leosac  0.8.0
Open Source Access Control
STDDurationODB.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2017 Leosac
3 
4  This file is part of Leosac.
5 
6  Leosac is free software: you can redistribute it and/or modify
7  it under the terms of the GNU Affero General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  Leosac is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  GNU Affero General Public License for more details.
15 
16  You should have received a copy of the GNU Affero General Public License
17  along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19 
20 #pragma once
21 
22 #include "tools/MyTime.hpp"
23 #include <cassert>
24 #include <chrono>
25 #include <iomanip>
26 #include <odb/pgsql/traits.hxx>
27 #include <odb/sqlite/traits.hxx>
28 
29 namespace odb
30 {
35 // For PGSql
36 
37 namespace pgsql
38 {
39 template <>
40 class value_traits<std::chrono::milliseconds, id_bigint>
41 {
42  public:
43  typedef std::chrono::milliseconds value_type;
45  typedef long long image_type;
46 
47  static void set_value(std::chrono::milliseconds &v, image_type i, bool is_null)
48  {
49  if (is_null)
50  v = std::chrono::milliseconds(0);
51  else
52  {
53  v = std::chrono::milliseconds(i);
54  }
55  }
56 
57  static void set_image(image_type &i, bool &is_null,
58  const std::chrono::milliseconds &v)
59  {
60  is_null = false;
61  i = v.count();
62  }
63 };
64 }
65 
66 
67 // For SQLite
68 
69 namespace sqlite
70 {
71 template <>
72 class value_traits<std::chrono::milliseconds, id_integer>
73 {
74  public:
75  typedef std::chrono::milliseconds value_type;
77  typedef long long image_type;
78 
79  static void set_value(std::chrono::milliseconds &v, image_type i, bool is_null)
80  {
81  if (is_null)
82  v = std::chrono::milliseconds(0);
83  else
84  {
85  v = std::chrono::milliseconds(i);
86  }
87  }
88 
89  static void set_image(image_type &i, bool &is_null,
90  const std::chrono::milliseconds &v)
91  {
92  is_null = false;
93  i = v.count();
94  }
95 };
96 }
97 }
odb
Provide ODB magic to be able to store an Leosac::Audit::EventType (FlagSet) object.
Definition: AuditEventMaskODB.hpp:31
odb::pgsql::value_traits< std::chrono::milliseconds, id_bigint >::image_type
long long image_type
Definition: STDDurationODB.hpp:45
odb::sqlite::value_traits< std::chrono::milliseconds, id_integer >::query_type
value_type query_type
Definition: STDDurationODB.hpp:76
odb::sqlite::value_traits< std::chrono::milliseconds, id_integer >::set_value
static void set_value(std::chrono::milliseconds &v, image_type i, bool is_null)
Definition: STDDurationODB.hpp:79
odb::sqlite::value_traits< std::chrono::milliseconds, id_integer >::set_image
static void set_image(image_type &i, bool &is_null, const std::chrono::milliseconds &v)
Definition: STDDurationODB.hpp:89
odb::sqlite::value_traits< std::chrono::milliseconds, id_integer >::image_type
long long image_type
Definition: STDDurationODB.hpp:77
odb::pgsql::value_traits< std::chrono::milliseconds, id_bigint >::query_type
value_type query_type
Definition: STDDurationODB.hpp:44
odb::pgsql::value_traits< std::chrono::milliseconds, id_bigint >::value_type
std::chrono::milliseconds value_type
Definition: STDDurationODB.hpp:43
odb::sqlite::value_traits< std::chrono::milliseconds, id_integer >::value_type
std::chrono::milliseconds value_type
Definition: STDDurationODB.hpp:75
odb::pgsql::value_traits< std::chrono::milliseconds, id_bigint >::set_value
static void set_value(std::chrono::milliseconds &v, image_type i, bool is_null)
Definition: STDDurationODB.hpp:47
odb::pgsql::value_traits< std::chrono::milliseconds, id_bigint >::set_image
static void set_image(image_type &i, bool &is_null, const std::chrono::milliseconds &v)
Definition: STDDurationODB.hpp:57
MyTime.hpp