xref: /netbsd-src/external/bsd/kyua-cli/dist/store/backend.hpp (revision f39f9c9b2b3d39fa4e71f38ebea4c5d12192a641)
1 // Copyright 2011 Google Inc.
2 // All rights reserved.
3 //
4 // Redistribution and use in source and binary forms, with or without
5 // modification, are permitted provided that the following conditions are
6 // met:
7 //
8 // * Redistributions of source code must retain the above copyright
9 //   notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 //   notice, this list of conditions and the following disclaimer in the
12 //   documentation and/or other materials provided with the distribution.
13 // * Neither the name of Google Inc. nor the names of its contributors
14 //   may be used to endorse or promote products derived from this software
15 //   without specific prior written permission.
16 //
17 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
18 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
19 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
20 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
21 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
22 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
23 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
27 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 
29 /// \file store/backend.hpp
30 /// Interface to the backend database.
31 
32 #if !defined(STORE_BACKEND_HPP)
33 #define STORE_BACKEND_HPP
34 
35 #include "utils/shared_ptr.hpp"
36 
37 namespace utils {
38 namespace fs {
39 class path;
40 }  // namespace fs
41 namespace sqlite {
42 class database;
43 }  // namespace sqlite
44 }  // namespace utils
45 
46 namespace store {
47 
48 
49 class metadata;
50 
51 
52 namespace detail {
53 
54 
55 extern int current_schema_version;
56 
57 
58 utils::fs::path migration_file(const int, const int);
59 utils::fs::path schema_file(void);
60 metadata initialize(utils::sqlite::database&);
61 void backup_database(const utils::fs::path&, const int);
62 
63 
64 }  // anonymous namespace
65 
66 
67 class transaction;
68 
69 
70 /// Public interface to the database store.
71 class backend {
72     struct impl;
73 
74     /// Pointer to the shared internal implementation.
75     std::shared_ptr< impl > _pimpl;
76 
77     friend class metadata;
78 
79     backend(impl*);
80 
81 public:
82     ~backend(void);
83 
84     static backend open_ro(const utils::fs::path&);
85     static backend open_rw(const utils::fs::path&);
86 
87     utils::sqlite::database& database(void);
88     transaction start(void);
89 };
90 
91 
92 void migrate_schema(const utils::fs::path&);
93 
94 
95 }  // namespace store
96 
97 #endif  // !defined(STORE_BACKEND_HPP)
98