Skip to main content

shape_ast/ast/
data_sources.rs

1//! Data source and query declaration types for Shape AST
2
3use serde::{Deserialize, Serialize};
4
5use super::expressions::Expr;
6use super::span::Span;
7use super::types::TypeAnnotation;
8
9/// Data source declaration: `datasource MarketData: DataSource<CandleRow> = provider("market_data")`
10#[derive(Debug, Clone, Serialize, Deserialize)]
11pub struct DataSourceDecl {
12    pub name: String,
13    pub name_span: Span,
14    /// Output schema type (e.g., CandleRow)
15    pub schema: TypeAnnotation,
16    /// Provider expression (e.g., provider("postgres"))
17    pub provider_expr: Expr,
18}
19
20/// Query declaration: `query UserById: Query<UserRow, { id: i64 }> = sql(DB, "SELECT ...")`
21#[derive(Debug, Clone, Serialize, Deserialize)]
22pub struct QueryDecl {
23    pub name: String,
24    pub name_span: Span,
25    /// Output schema type (e.g., UserRow)
26    pub output_schema: TypeAnnotation,
27    /// Runtime parameter schema (object type)
28    pub params_schema: TypeAnnotation,
29    /// Data source reference (identifier)
30    pub source_name: String,
31    /// SQL string literal
32    pub sql: String,
33    pub sql_span: Span,
34}