This repository has been archived by the owner on Jan 3, 2024. It is now read-only.
forked from fnc12/sqlite_orm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathview.h
66 lines (54 loc) · 2.17 KB
/
view.h
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
#pragma once
#include <sqlite3.h>
#include <string> // std::string
#include <utility> // std::forward, std::move
#include <tuple> // std::tuple, std::make_tuple
#include "row_extractor.h"
#include "error_code.h"
#include "iterator.h"
#include "ast_iterator.h"
#include "prepared_statement.h"
#include "connection_holder.h"
#include "util.h"
namespace sqlite_orm {
namespace internal {
/**
* This class does not related to SQL view. This is a container like class which is returned by
* by storage_t::iterate function. This class contains STL functions:
* - size_t size()
* - bool empty()
* - iterator end()
* - iterator begin()
* All these functions are not right const cause all of them may open SQLite connections.
*/
template<class T, class S, class... Args>
struct view_t {
using mapped_type = T;
using storage_type = S;
using self = view_t<T, S, Args...>;
storage_type& storage;
connection_ref connection;
get_all_t<T, std::vector<T>, Args...> args;
view_t(storage_type& stor, decltype(connection) conn, Args&&... args_) :
storage(stor), connection(std::move(conn)), args{std::make_tuple(std::forward<Args>(args_)...)} {}
size_t size() const {
return this->storage.template count<T>();
}
bool empty() const {
return !this->size();
}
iterator_t<self> begin() {
using context_t = serializer_context<typename storage_type::db_objects_type>;
context_t context{obtain_db_objects(this->storage)};
context.skip_table_name = false;
context.replace_bindable_with_question = true;
statement_finalizer stmt{prepare_stmt(this->connection.get(), serialize(this->args, context))};
iterate_ast(this->args.conditions, conditional_binder{stmt.get()});
return {std::move(stmt), *this};
}
iterator_t<self> end() {
return {};
}
};
}
}