use clap::{Args, Subcommand};
#[derive(Debug, Clone, Subcommand)]
pub enum QueryCommand {
Run(RunArgs),
Sample(SampleArgs),
Explain(ExplainArgs),
Analyze(StatementArgs),
Plan(PlanArgs),
Lineage(StatementArgs),
File(FileArgs),
Tx(TxArgs),
Call(CallArgs),
Named(NamedArgs),
}
#[derive(Debug, Clone, Args)]
pub struct StatementArgs {
pub statement: Option<String>,
#[arg(long, conflicts_with = "statement")]
pub stdin: bool,
#[arg(long = "param", value_name = "VALUE")]
pub params: Vec<String>,
}
#[derive(Debug, Clone, Args)]
pub struct RunArgs {
#[command(flatten)]
pub statement: StatementArgs,
}
#[derive(Debug, Clone, Args)]
pub struct SampleArgs {
#[arg(long)]
pub table: Option<String>,
#[arg(long)]
pub rows: Option<usize>,
}
#[derive(Debug, Clone, Args)]
pub struct ExplainArgs {
#[command(flatten)]
pub statement: StatementArgs,
#[arg(long)]
pub trace: bool,
}
#[derive(Debug, Clone, Args)]
pub struct PlanArgs {
#[arg(long = "connection", alias = "id")]
pub id: Option<u64>,
}
#[derive(Debug, Clone, Args)]
pub struct FileArgs {
pub path: Option<std::path::PathBuf>,
#[arg(long)]
pub delimiter: Option<String>,
#[arg(long = "on-error", value_name = "POLICY")]
pub on_error: Option<crate::cli::data::OnError>,
}
#[derive(Debug, Clone, Args)]
pub struct TxArgs {
#[arg(long = "statement", value_name = "SQL")]
pub statements: Vec<String>,
#[arg(long, conflicts_with = "statements")]
pub stdin: bool,
#[arg(long, value_name = "PATH", conflicts_with_all = ["statements", "stdin"])]
pub file: Option<std::path::PathBuf>,
}
#[derive(Debug, Clone, Args)]
pub struct CallArgs {
pub routine: Option<String>,
#[arg(long = "param", value_name = "VALUE")]
pub params: Vec<String>,
#[arg(long = "out", value_name = "NAME")]
pub outputs: Vec<String>,
}
#[derive(Debug, Clone, Args)]
pub struct NamedArgs {
#[command(subcommand)]
pub action: NamedAction,
}
#[derive(Debug, Clone, Subcommand)]
pub enum NamedAction {
Save {
#[arg(default_value = "")]
name: String,
#[arg(default_value = "")]
statement: String,
#[arg(long = "param", value_name = "NAME:TYPE")]
params: Vec<String>,
#[arg(long)]
max_rows: Option<usize>,
},
List,
Remove {
#[arg(default_value = "")]
name: String,
},
Run {
#[arg(default_value = "")]
name: String,
#[arg(long = "param", alias = "arg", value_name = "NAME=VALUE")]
args: Vec<String>,
},
}
impl NamedAction {
#[must_use]
pub const fn published_name(&self) -> &'static str {
match self {
Self::Save { .. } => "query named save",
Self::List => "query named list",
Self::Remove { .. } => "query named remove",
Self::Run { .. } => "query named run",
}
}
}