Skip to main content

reifydb_engine/bulk_insert/primitive/
table.rs

1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2025 ReifyDB
3
4use reifydb_type::params::Params;
5
6use crate::bulk_insert::builder::{BulkInsertBuilder, ValidationMode};
7
8#[derive(Debug, Clone)]
9pub struct PendingTableInsert {
10	pub namespace: String,
11	pub table: String,
12	pub rows: Vec<Params>,
13}
14
15impl PendingTableInsert {
16	pub fn new(namespace: String, table: String) -> Self {
17		Self {
18			namespace,
19			table,
20			rows: Vec::new(),
21		}
22	}
23
24	pub fn add_row(&mut self, params: Params) {
25		self.rows.push(params);
26	}
27
28	pub fn add_rows<I: IntoIterator<Item = Params>>(&mut self, iter: I) {
29		self.rows.extend(iter);
30	}
31}
32
33pub struct TableInsertBuilder<'a, 'e, V: ValidationMode> {
34	parent: &'a mut BulkInsertBuilder<'e, V>,
35	pending: PendingTableInsert,
36}
37
38impl<'a, 'e, V: ValidationMode> TableInsertBuilder<'a, 'e, V> {
39	pub(crate) fn new(parent: &'a mut BulkInsertBuilder<'e, V>, namespace: String, table: String) -> Self {
40		Self {
41			parent,
42			pending: PendingTableInsert::new(namespace, table),
43		}
44	}
45
46	pub fn row(mut self, params: Params) -> Self {
47		self.pending.add_row(params);
48		self
49	}
50
51	pub fn rows<I>(mut self, iter: I) -> Self
52	where
53		I: IntoIterator<Item = Params>,
54	{
55		self.pending.add_rows(iter);
56		self
57	}
58
59	pub fn done(self) -> &'a mut BulkInsertBuilder<'e, V> {
60		self.parent.add_table_insert(self.pending);
61		self.parent
62	}
63}