1#include "duckdb/parser/constraint.hpp"
2
3#include "duckdb/common/printer.hpp"
4#include "duckdb/common/serializer.hpp"
5#include "duckdb/parser/constraints/list.hpp"
6#include "duckdb/common/field_writer.hpp"
7
8namespace duckdb {
9
10Constraint::Constraint(ConstraintType type) : type(type) {
11}
12
13Constraint::~Constraint() {
14}
15
16void Constraint::Serialize(Serializer &serializer) const {
17 FieldWriter writer(serializer);
18 writer.WriteField<ConstraintType>(element: type);
19 Serialize(writer);
20 writer.Finalize();
21}
22
23unique_ptr<Constraint> Constraint::Deserialize(Deserializer &source) {
24 FieldReader reader(source);
25 auto type = reader.ReadRequired<ConstraintType>();
26 unique_ptr<Constraint> result;
27 switch (type) {
28 case ConstraintType::NOT_NULL:
29 result = NotNullConstraint::Deserialize(source&: reader);
30 break;
31 case ConstraintType::CHECK:
32 result = CheckConstraint::Deserialize(source&: reader);
33 break;
34 case ConstraintType::UNIQUE:
35 result = UniqueConstraint::Deserialize(source&: reader);
36 break;
37 case ConstraintType::FOREIGN_KEY:
38 result = ForeignKeyConstraint::Deserialize(source&: reader);
39 break;
40 default:
41 throw InternalException("Unrecognized constraint type for serialization");
42 }
43 reader.Finalize();
44 return result;
45}
46
47void Constraint::Print() const {
48 Printer::Print(str: ToString());
49}
50
51} // namespace duckdb
52