Skip to main content

bunnydb_rs/
types.rs

1use crate::Value;
2
3/// Column metadata returned by query responses.
4#[derive(Clone, Debug, PartialEq, Eq)]
5pub struct Col {
6    /// Column name.
7    pub name: String,
8    /// Declared SQL type, if present.
9    pub decltype: Option<String>,
10}
11
12/// Query response shape.
13#[derive(Clone, Debug, PartialEq)]
14pub struct QueryResult {
15    /// Column metadata.
16    pub cols: Vec<Col>,
17    /// Decoded row values.
18    pub rows: Vec<Vec<Value>>,
19    /// Optional replication index returned by API.
20    pub replication_index: Option<String>,
21    /// Optional number of rows read by query.
22    pub rows_read: Option<u64>,
23    /// Optional number of rows written by query.
24    pub rows_written: Option<u64>,
25    /// Optional execution duration in milliseconds.
26    pub query_duration_ms: Option<f64>,
27}
28
29/// Execute response shape.
30#[derive(Clone, Debug, PartialEq, Eq)]
31pub struct ExecResult {
32    /// Number of affected rows.
33    pub affected_row_count: u64,
34    /// Last inserted row id if returned by engine.
35    pub last_insert_rowid: Option<i64>,
36    /// Optional replication index returned by API.
37    pub replication_index: Option<String>,
38    /// Optional number of rows read during execution.
39    pub rows_read: Option<u64>,
40    /// Optional number of rows written during execution.
41    pub rows_written: Option<u64>,
42}
43
44/// Batch outcome per statement.
45#[derive(Clone, Debug, PartialEq)]
46pub enum StatementOutcome {
47    /// Successful query statement.
48    Query(QueryResult),
49    /// Successful execute statement.
50    Exec(ExecResult),
51    /// Statement-level SQL error from pipeline response.
52    SqlError {
53        /// Index of statement in request batch.
54        request_index: usize,
55        /// SQL error message.
56        message: String,
57        /// Optional SQL error code.
58        code: Option<String>,
59    },
60}