-
-
Notifications
You must be signed in to change notification settings - Fork 477
Expand file tree
/
Copy pathflex-index.hpp
More file actions
106 lines (82 loc) · 2.62 KB
/
flex-index.hpp
File metadata and controls
106 lines (82 loc) · 2.62 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef OSM2PGSQL_FLEX_INDEX_HPP
#define OSM2PGSQL_FLEX_INDEX_HPP
/**
* SPDX-License-Identifier: GPL-2.0-or-later
*
* This file is part of osm2pgsql (https://osm2pgsql.org/).
*
* Copyright (C) 2006-2026 by the osm2pgsql developer community.
* For a full list of authors see the git log.
*/
#include <cassert>
#include <cstdint>
#include <stdexcept>
#include <string>
#include <vector>
/**
* This class represents a database index.
*/
class flex_index_t
{
public:
explicit flex_index_t(std::string method) : m_method(std::move(method)) {}
std::string const &method() const noexcept { return m_method; }
std::string columns() const;
/// Set columns (single-column version)
void set_columns(std::string const &columns)
{
assert(m_columns.empty());
m_columns.push_back(columns);
}
/// Set columns (multi-column version)
void set_columns(std::vector<std::string> const &columns)
{
m_columns = columns;
}
std::string include_columns() const;
void set_include_columns(std::vector<std::string> const &columns)
{
m_include_columns = columns;
}
std::string const &name() const noexcept { return m_name; }
void set_name(std::string name) { m_name = std::move(name); }
std::string const &expression() const noexcept { return m_expression; }
void set_expression(std::string expression)
{
m_expression = std::move(expression);
}
std::string const &tablespace() const noexcept { return m_tablespace; }
void set_tablespace(std::string tablespace)
{
m_tablespace = std::move(tablespace);
}
std::string const &where_condition() const noexcept
{
return m_where_condition;
}
void set_where_condition(std::string where_condition)
{
m_where_condition = std::move(where_condition);
}
void set_fillfactor(uint8_t fillfactor)
{
if (fillfactor < 10 || fillfactor > 100) {
throw std::runtime_error{"Fillfactor must be between 10 and 100."};
}
m_fillfactor = fillfactor;
}
bool is_unique() const noexcept { return m_is_unique; }
void set_is_unique(bool unique) noexcept { m_is_unique = unique; }
std::string create_index(std::string const &qualified_table_name) const;
private:
std::vector<std::string> m_columns;
std::vector<std::string> m_include_columns;
std::string m_name;
std::string m_method;
std::string m_expression;
std::string m_tablespace;
std::string m_where_condition;
uint8_t m_fillfactor = 0;
bool m_is_unique = false;
}; // class flex_index_t
#endif // OSM2PGSQL_FLEX_INDEX_HPP