Skip to main content

reifydb_export/
options.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 ReifyDB
3
4#[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	Objects(Vec<QualifiedObject>),
17	Kinds(Vec<ObjectKind>),
18}
19
20#[derive(Debug, Clone, PartialEq)]
21pub struct QualifiedObject {
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 ObjectKind {
35	Table,
36	Queue,
37	RingBuffer,
38	Series,
39	Dictionary,
40	Enum,
41}
42
43pub const DEFAULT_INSERT_BATCH_SIZE: usize = 500;
44
45impl ExportOptions {
46	pub fn all() -> Self {
47		Self {
48			selection: ExportSelection::All,
49			contents: ExportContents::SchemaAndData,
50			insert_batch_size: DEFAULT_INSERT_BATCH_SIZE,
51			if_not_exists: false,
52		}
53	}
54
55	pub fn namespace(mut self, name: impl Into<String>) -> Self {
56		let name = name.into();
57		match &mut self.selection {
58			ExportSelection::Namespaces(names) => names.push(name),
59			_ => self.selection = ExportSelection::Namespaces(vec![name]),
60		}
61		self
62	}
63
64	pub fn object(mut self, namespace: impl Into<String>, name: impl Into<String>) -> Self {
65		let object = QualifiedObject {
66			namespace: namespace.into(),
67			name: name.into(),
68		};
69		match &mut self.selection {
70			ExportSelection::Objects(objects) => objects.push(object),
71			_ => self.selection = ExportSelection::Objects(vec![object]),
72		}
73		self
74	}
75
76	pub fn kind(mut self, kind: ObjectKind) -> Self {
77		match &mut self.selection {
78			ExportSelection::Kinds(kinds) => {
79				if !kinds.contains(&kind) {
80					kinds.push(kind);
81				}
82			}
83			_ => self.selection = ExportSelection::Kinds(vec![kind]),
84		}
85		self
86	}
87
88	pub fn schema_only(mut self) -> Self {
89		self.contents = ExportContents::SchemaOnly;
90		self
91	}
92
93	pub fn data_only(mut self) -> Self {
94		self.contents = ExportContents::DataOnly;
95		self
96	}
97
98	pub fn batch_size(mut self, size: usize) -> Self {
99		self.insert_batch_size = size.max(1);
100		self
101	}
102
103	pub fn if_not_exists(mut self, enabled: bool) -> Self {
104		self.if_not_exists = enabled;
105		self
106	}
107
108	pub fn includes_schema(&self) -> bool {
109		!matches!(self.contents, ExportContents::DataOnly)
110	}
111
112	pub fn includes_data(&self) -> bool {
113		!matches!(self.contents, ExportContents::SchemaOnly)
114	}
115}
116
117impl Default for ExportOptions {
118	fn default() -> Self {
119		Self::all()
120	}
121}