aether_protocol/
response.rs

1// File: src/response.rs
2// =============================================================================
3// This file defines the top-level `Response` enum. This is the single, unified
4// type that represents every possible reply the server can send to a client.
5
6use crate::types::{BatchResponse, DbStats, Record, RecordSet};
7use serde::{Deserialize, Serialize};
8
9/// A struct to hold performance metrics for a query.
10#[derive(Serialize, Deserialize, Debug, PartialEq)]
11pub struct QueryMetrics {
12    pub execution_time_micros: u64,
13    // We can add more later, like records_scanned, etc.
14}
15
16/// The primary enum representing all possible server responses.
17#[derive(Serialize, Deserialize, Debug, PartialEq)]
18pub enum Response {
19    // --- General Responses ---
20    Success,
21    Error(String),
22
23    // --- Database Management Responses ---
24    DatabaseList(Vec<String>),
25    DatabaseCreated(bool),
26    DatabaseDropped(bool),
27
28    // --- Collection Management Responses ---
29    CollectionList(Vec<String>),
30    Stats(DbStats),
31    IndexList(Vec<String>),
32
33    // --- Record & Query Responses ---
34    Record(Option<Record>),
35    RecordSet(RecordSet),
36    RecordCount(u64),
37    RecordDeleted(bool),
38    LastInsertId(u64),
39    RecordWithRelated(Option<(Record, Record)>),
40    BatchResponse(BatchResponse),
41    RecordIdSet(Vec<String>),
42
43    /// A special response that wraps another response and includes performance data.
44    ResultMetrics {
45        data: Box<Response>, // The original response (e.g., RecordSet)
46        metrics: QueryMetrics,
47    },
48}