Leosac  0.7.0
OpenSourceAccessControl
LogEntry.hpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014-2016 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/db/database.hpp"
23 #include <boost/date_time/posix_time/posix_time.hpp>
24 #include <odb/core.hxx>
25 
26 namespace Leosac
27 {
28 namespace Tools
29 {
39 #pragma db object optimistic
40 class LogEntry
41 {
42  public:
43  LogEntry();
44 
45 #pragma db id auto
46  unsigned long id_;
47 
48 #pragma db not_null
49  boost::posix_time::ptime timestamp_;
50 
51 #pragma db not_null
52  std::string msg_;
53 
59 #pragma db not_null
60  std::string run_id_;
61 
62 #pragma db not_null
63  uint8_t level_;
64 
65 #pragma db not_null
66  size_t thread_id_;
67 
71  struct QueryResult
72  {
73  QueryResult() = default;
74  std::vector<LogEntry> entries;
75 
76  // metadata
77  size_t total;
78  size_t last;
79  size_t first;
80  };
81  static QueryResult retrieve(DBPtr database, int page_number, int page_size,
82  bool order_asc);
83 
84  private:
85  friend class odb::access;
86 
87 #pragma db version
88  const size_t version_;
89 };
90 
94 #pragma db view object(LogEntry)
95 struct LogView
96 {
97 #pragma db column("count(" + LogEntry::id_ + ")")
98  size_t count;
99 };
100 }
101 }
This is the header file for a generated source file, GitSHA1.cpp.
static QueryResult retrieve(DBPtr database, int page_number, int page_size, bool order_asc)
Definition: LogEntry.cpp:61
boost::posix_time::ptime timestamp_
Definition: LogEntry.hpp:49
SQL view over the LogEntry table.
Definition: LogEntry.hpp:95
std::string run_id_
The run_id is generated when Leosac starts, and it is used to identify "runs" (ie if Leosac restarts)...
Definition: LogEntry.hpp:60
const size_t version_
Definition: LogEntry.hpp:88
Structure holding the result for a retrieve() call.
Definition: LogEntry.hpp:71
unsigned long id_
Definition: LogEntry.hpp:46
std::vector< LogEntry > entries
Definition: LogEntry.hpp:74
std::shared_ptr< odb::database > DBPtr
Definition: db_fwd.hpp:31