vibesql_ast/introspection.rs
1//! Database introspection statements (SHOW, DESCRIBE)
2//!
3//! This module defines MySQL-style introspection statements for querying metadata.
4
5use crate::Expression;
6
7// ============================================================================
8// SHOW Statements
9// ============================================================================
10
11/// SHOW TABLES statement
12#[derive(Debug, Clone, PartialEq)]
13pub struct ShowTablesStmt {
14 /// Optional database name (FROM database_name)
15 pub database: Option<String>,
16 /// Optional LIKE pattern
17 pub like_pattern: Option<String>,
18 /// Optional WHERE expression
19 pub where_clause: Option<Expression>,
20}
21
22/// SHOW DATABASES statement
23#[derive(Debug, Clone, PartialEq)]
24pub struct ShowDatabasesStmt {
25 /// Optional LIKE pattern
26 pub like_pattern: Option<String>,
27 /// Optional WHERE expression
28 pub where_clause: Option<Expression>,
29}
30
31/// SHOW COLUMNS statement
32#[derive(Debug, Clone, PartialEq)]
33pub struct ShowColumnsStmt {
34 /// Table name
35 pub table_name: String,
36 /// Optional database name (FROM database_name)
37 pub database: Option<String>,
38 /// Show full column information
39 pub full: bool,
40 /// Optional LIKE pattern
41 pub like_pattern: Option<String>,
42 /// Optional WHERE expression
43 pub where_clause: Option<Expression>,
44}
45
46/// SHOW INDEX statement
47#[derive(Debug, Clone, PartialEq)]
48pub struct ShowIndexStmt {
49 /// Table name
50 pub table_name: String,
51 /// Optional database name (FROM database_name)
52 pub database: Option<String>,
53}
54
55/// SHOW CREATE TABLE statement
56#[derive(Debug, Clone, PartialEq)]
57pub struct ShowCreateTableStmt {
58 /// Table name
59 pub table_name: String,
60}
61
62// ============================================================================
63// DESCRIBE Statement
64// ============================================================================
65
66/// DESCRIBE statement (synonym for SHOW COLUMNS)
67#[derive(Debug, Clone, PartialEq)]
68pub struct DescribeStmt {
69 /// Table name
70 pub table_name: String,
71 /// Optional column name or pattern
72 pub column_pattern: Option<String>,
73}
74
75// ============================================================================
76// EXPLAIN Statement
77// ============================================================================
78
79/// EXPLAIN statement output format
80#[derive(Debug, Clone, PartialEq, Default)]
81pub enum ExplainFormat {
82 /// Plain text output (default)
83 #[default]
84 Text,
85 /// JSON output
86 Json,
87}
88
89/// EXPLAIN statement
90///
91/// Shows the query execution plan for a SELECT, INSERT, UPDATE, or DELETE statement.
92#[derive(Debug, Clone, PartialEq)]
93pub struct ExplainStmt {
94 /// The statement to explain
95 pub statement: Box<crate::Statement>,
96 /// Output format
97 pub format: ExplainFormat,
98 /// Whether to analyze the query (run it and show actual timing)
99 pub analyze: bool,
100 /// Whether this is EXPLAIN QUERY PLAN (SQLite-style execution plan)
101 pub query_plan: bool,
102}