reifydb_engine/table_virtual/
factory.rs

1// Copyright (c) reifydb.com 2025
2// This file is licensed under the AGPL-3.0-or-later, see license.md file
3
4use std::sync::Arc;
5
6use reifydb_core::interface::TableVirtualDef;
7
8use super::TableVirtual;
9
10/// Factory for creating virtual table instances.
11///
12/// Implementations must be thread-safe and create fresh instances on each call.
13/// The factory pattern allows virtual tables to be registered once and instantiated
14/// on-demand for each query execution.
15///
16/// # Example
17///
18/// ```ignore
19/// struct MyTableFactory {
20///     definition: Arc<TableVirtualDef>,
21/// }
22///
23/// impl VirtualTableFactory for MyTableFactory {
24///     fn create_boxed(&self) -> Box<dyn TableVirtual + Send + Sync> {
25///         Box::new(MyVirtualTable::new(self.definition.clone()))
26///     }
27///
28///     fn definition(&self) -> Arc<TableVirtualDef> {
29///         self.definition.clone()
30///     }
31/// }
32/// ```
33pub trait VirtualTableFactory: Send + Sync + 'static {
34	/// Create a new virtual table instance.
35	///
36	/// Each call should return a fresh instance ready to process a new query.
37	fn create_boxed(&self) -> Box<dyn TableVirtual + Send + Sync>;
38
39	/// Get the table definition (schema).
40	///
41	/// Returns the metadata including column names, types, and constraints.
42	fn definition(&self) -> Arc<TableVirtualDef>;
43}