forked from scylladb/scylladb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathschema_builder.hh
52 lines (46 loc) · 1.55 KB
/
schema_builder.hh
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
/*
* Copyright 2015 Cloudius Systems
*/
#pragma once
#include "schema.hh"
enum class column_kind { partition_key, clustering_key, static_column, regular_column };
struct schema_builder {
sstring _ks_name;
sstring _cf_name;
std::vector<schema::column> _partition_key;
std::vector<schema::column> _clustering_key;
std::vector<schema::column> _static_columns;
std::vector<schema::column> _regular_columns;
public:
schema_builder(const sstring& ks_name, const sstring& cf_name)
: _ks_name(ks_name)
, _cf_name(cf_name)
{ }
schema_builder& with_column(bytes name, data_type type, column_kind kind = column_kind::regular_column) {
switch (kind) {
case column_kind::partition_key:
_partition_key.emplace_back(schema::column{name, type});
break;
case column_kind::clustering_key:
_clustering_key.emplace_back(schema::column{name, type});
break;
case column_kind::static_column:
_static_columns.emplace_back(schema::column{name, type});
break;
case column_kind::regular_column:
_regular_columns.emplace_back(schema::column{name, type});
break;
};
return *this;
}
schema_ptr build() {
return make_lw_shared<schema>(schema({},
_ks_name,
_cf_name,
_partition_key,
_clustering_key,
_regular_columns,
_static_columns,
utf8_type));
}
};