-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathColumn.cpp
More file actions
54 lines (44 loc) · 1.25 KB
/
Column.cpp
File metadata and controls
54 lines (44 loc) · 1.25 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
//
// Created by Piotrek Rybiec on 05/05/2025.
//
#include <algorithm>
#include "Column.hpp"
#include "Constraint.hpp"
auto Column::addConstraint(const std::shared_ptr<Constraint>& constraint) -> void {
constraints.push_back(constraint);
}
auto Column::isPrimaryKey() const -> bool {
/*
for (const auto& c : constraints) {
if (c->getType() == ConstraintType::PRIMARY_KEY) {
return true;
}
}
return false;
*/
return std::ranges::any_of(constraints, [](const auto& c) {
return c->getType() == ConstraintType::UNIQUE;
});
}
auto Column::isUnique() const -> bool {
return std::ranges::any_of(constraints, [](const auto& c) {
return c->getType() == ConstraintType::UNIQUE;
});
}
auto Column::isNullable() const -> bool {
return std::ranges::any_of(constraints, [](const auto& c) {
return c->getType() == ConstraintType::NOT_NULL;
});
}
auto Column::getName() const -> const std::string& {
return name;
}
auto Column::getType() const -> DataType {
return type;
}
auto Column::getConstraints() const -> const std::vector<std::shared_ptr<Constraint>>& {
return constraints;
}
auto Column::setName(std::string new_name) -> void {
name = std::move(new_name);
}