reifydb_export/
options.rs1#[derive(Debug, Clone, PartialEq)]
5pub struct ExportOptions {
6 pub selection: ExportSelection,
7 pub contents: ExportContents,
8 pub insert_batch_size: usize,
9 pub if_not_exists: bool,
10}
11
12#[derive(Debug, Clone, PartialEq)]
13pub enum ExportSelection {
14 All,
15 Namespaces(Vec<String>),
16 Shapes(Vec<QualifiedShape>),
17 Kinds(Vec<ShapeKind>),
18}
19
20#[derive(Debug, Clone, PartialEq)]
21pub struct QualifiedShape {
22 pub namespace: String,
23 pub name: String,
24}
25
26#[derive(Debug, Clone, Copy, PartialEq)]
27pub enum ExportContents {
28 SchemaAndData,
29 SchemaOnly,
30 DataOnly,
31}
32
33#[derive(Debug, Clone, Copy, PartialEq, Eq)]
34pub enum ShapeKind {
35 Table,
36 RingBuffer,
37 Series,
38 Dictionary,
39 Enum,
40}
41
42pub const DEFAULT_INSERT_BATCH_SIZE: usize = 500;
43
44impl ExportOptions {
45 pub fn all() -> Self {
46 Self {
47 selection: ExportSelection::All,
48 contents: ExportContents::SchemaAndData,
49 insert_batch_size: DEFAULT_INSERT_BATCH_SIZE,
50 if_not_exists: false,
51 }
52 }
53
54 pub fn namespace(mut self, name: impl Into<String>) -> Self {
55 let name = name.into();
56 match &mut self.selection {
57 ExportSelection::Namespaces(names) => names.push(name),
58 _ => self.selection = ExportSelection::Namespaces(vec![name]),
59 }
60 self
61 }
62
63 pub fn shape(mut self, namespace: impl Into<String>, name: impl Into<String>) -> Self {
64 let shape = QualifiedShape {
65 namespace: namespace.into(),
66 name: name.into(),
67 };
68 match &mut self.selection {
69 ExportSelection::Shapes(shapes) => shapes.push(shape),
70 _ => self.selection = ExportSelection::Shapes(vec![shape]),
71 }
72 self
73 }
74
75 pub fn kind(mut self, kind: ShapeKind) -> Self {
76 match &mut self.selection {
77 ExportSelection::Kinds(kinds) => {
78 if !kinds.contains(&kind) {
79 kinds.push(kind);
80 }
81 }
82 _ => self.selection = ExportSelection::Kinds(vec![kind]),
83 }
84 self
85 }
86
87 pub fn schema_only(mut self) -> Self {
88 self.contents = ExportContents::SchemaOnly;
89 self
90 }
91
92 pub fn data_only(mut self) -> Self {
93 self.contents = ExportContents::DataOnly;
94 self
95 }
96
97 pub fn batch_size(mut self, size: usize) -> Self {
98 self.insert_batch_size = size.max(1);
99 self
100 }
101
102 pub fn if_not_exists(mut self, enabled: bool) -> Self {
103 self.if_not_exists = enabled;
104 self
105 }
106
107 pub fn includes_schema(&self) -> bool {
108 !matches!(self.contents, ExportContents::DataOnly)
109 }
110
111 pub fn includes_data(&self) -> bool {
112 !matches!(self.contents, ExportContents::SchemaOnly)
113 }
114}
115
116impl Default for ExportOptions {
117 fn default() -> Self {
118 Self::all()
119 }
120}