reifydb_core/interface/
engine.rs

1use async_trait::async_trait;
2
3use crate::{
4	interface::{CommandTransaction, Identity, Params, QueryTransaction, WithEventBus},
5	stream::SendableFrameStream,
6};
7
8/// Async database engine trait.
9///
10/// This trait defines the core interface for database engines. The `command_as`
11/// and `query_as` methods return async streams for non-blocking execution.
12///
13/// All methods create `Send` futures to work with tokio's multi-threaded runtime.
14#[async_trait]
15pub trait Engine: WithEventBus + Send + Sync + Clone + 'static {
16	type Command: CommandTransaction;
17	type Query: QueryTransaction;
18
19	/// Begin a new command (write) transaction.
20	async fn begin_command(&self) -> crate::Result<Self::Command>;
21
22	/// Begin a new query (read) transaction.
23	async fn begin_query(&self) -> crate::Result<Self::Query>;
24
25	/// Execute a command and return a stream of result frames.
26	///
27	/// Commands are write operations (INSERT, UPDATE, DELETE, DDL) that modify
28	/// the database state. The command runs in a transaction that is automatically
29	/// committed on success or rolled back on error.
30	fn command_as(&self, identity: &Identity, rql: &str, params: Params) -> SendableFrameStream;
31
32	/// Execute a query and return a stream of result frames.
33	///
34	/// Queries are read operations (SELECT) that do not modify the database.
35	/// Results are streamed as they become available, providing backpressure
36	/// if the consumer is slow.
37	fn query_as(&self, identity: &Identity, rql: &str, params: Params) -> SendableFrameStream;
38}