Skip to main content

saya_types/
query.rs

1use serde::{Deserialize, Serialize};
2use serde_json::Value;
3
4/// A bounded query passed to a database connector.
5#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
6pub struct QueryRequest {
7    pub sql: String,
8    pub max_rows: usize,
9}
10
11impl QueryRequest {
12    pub fn new(sql: impl Into<String>, max_rows: usize) -> Self {
13        Self {
14            sql: sql.into(),
15            max_rows,
16        }
17    }
18}
19
20/// Connector-neutral tabular result. Values are JSON-compatible for CLI output.
21#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
22pub struct QueryResult {
23    pub columns: Vec<String>,
24    pub rows: Vec<Value>,
25    pub row_count: usize,
26    pub truncated: bool,
27    pub executed_sql: String,
28}
29
30impl QueryResult {
31    pub fn empty(sql: impl Into<String>) -> Self {
32        Self {
33            columns: Vec::new(),
34            rows: Vec::new(),
35            row_count: 0,
36            truncated: false,
37            executed_sql: sql.into(),
38        }
39    }
40}