forked from extern/nushell
# Description This updates all the positional arguments (except with `--features=dataframe` or `--features=extra`) to start with an uppercase letter and end with a period. Part of #5066, specifically [this comment](/nushell/nushell/issues/5066#issuecomment-1421528910) Some arguments had example data removed from them because it also appears in the examples. There are other inconsistencies in positional arguments I noticed while making the tests pass which I will bring up in #5066. # User-Facing Changes Positional arguments are now consistent # Tests + Formatting - 🟢 `toolkit fmt` - 🟢 `toolkit clippy` - 🟢 `toolkit test` - 🟢 `toolkit test stdlib` # After Submitting Automatic documentation updates
60 lines
1.5 KiB
Rust
60 lines
1.5 KiB
Rust
use nu_engine::CallExt;
|
|
use nu_protocol::{
|
|
ast::Call,
|
|
engine::{Command, EngineState, Stack},
|
|
Category, Example, IntoPipelineData, PipelineData, ShellError, Signature, Spanned, SyntaxShape,
|
|
Type,
|
|
};
|
|
|
|
use super::super::SQLiteDatabase;
|
|
|
|
#[derive(Clone)]
|
|
pub struct QueryDb;
|
|
|
|
impl Command for QueryDb {
|
|
fn name(&self) -> &str {
|
|
"query db"
|
|
}
|
|
|
|
fn signature(&self) -> Signature {
|
|
Signature::build(self.name())
|
|
.input_output_types(vec![(Type::Any, Type::Any)])
|
|
.required(
|
|
"SQL",
|
|
SyntaxShape::String,
|
|
"SQL to execute against the database.",
|
|
)
|
|
.category(Category::Database)
|
|
}
|
|
|
|
fn usage(&self) -> &str {
|
|
"Query a database using SQL."
|
|
}
|
|
|
|
fn examples(&self) -> Vec<Example> {
|
|
vec![Example {
|
|
description: "Execute SQL against a SQLite database",
|
|
example: r#"open foo.db | query db "SELECT * FROM Bar""#,
|
|
result: None,
|
|
}]
|
|
}
|
|
|
|
fn search_terms(&self) -> Vec<&str> {
|
|
vec!["database", "SQLite"]
|
|
}
|
|
|
|
fn run(
|
|
&self,
|
|
engine_state: &EngineState,
|
|
stack: &mut Stack,
|
|
call: &Call,
|
|
input: PipelineData,
|
|
) -> Result<PipelineData, ShellError> {
|
|
let sql: Spanned<String> = call.req(engine_state, stack, 0)?;
|
|
|
|
let db = SQLiteDatabase::try_from_pipeline(input, call.head)?;
|
|
db.query(&sql, call.head)
|
|
.map(IntoPipelineData::into_pipeline_data)
|
|
}
|
|
}
|