1use crate::database::{MEMORY_DB, SQLiteDatabase};
2use nu_engine::command_prelude::*;
3use nu_protocol::Signals;
4
5#[derive(Clone)]
6pub struct StorOpen;
7
8impl Command for StorOpen {
9 fn name(&self) -> &str {
10 "stor open"
11 }
12
13 fn signature(&self) -> Signature {
14 Signature::build("stor open")
15 .input_output_types(vec![(Type::Nothing, Type::Custom("SQLiteDatabase".into()))])
16 .allow_variants_without_examples(true)
17 .category(Category::Database)
18 }
19
20 fn description(&self) -> &str {
21 "Opens the in-memory sqlite database."
22 }
23
24 fn search_terms(&self) -> Vec<&str> {
25 vec!["sqlite", "storing", "access"]
26 }
27
28 fn examples(&self) -> Vec<Example<'_>> {
29 vec![Example {
30 description: "Open the in-memory sqlite database",
31 example: "stor open",
32 result: None,
33 }]
34 }
35
36 fn run(
37 &self,
38 _engine_state: &EngineState,
39 _stack: &mut Stack,
40 call: &Call,
41 _input: PipelineData,
42 ) -> Result<PipelineData, ShellError> {
43 let db = Box::new(SQLiteDatabase::new(
56 std::path::Path::new(MEMORY_DB),
57 Signals::empty(),
58 ));
59
60 Ok(db.into_value(call.head).into_pipeline_data())
62 }
63}
64
65#[cfg(test)]
66mod test {
67 use super::*;
68 use nu_test_support::Result;
69 use nu_test_support::prelude::*;
70
71 #[test]
72 fn test_examples() -> Result {
73 test().examples(StorOpen)
74 }
75
76 #[test]
77 #[exp(nu_experimental::ENFORCE_RUNTIME_ANNOTATIONS)]
78 fn correct_return_ty() -> Result {
79 let () = test().run("let db = stor open")?;
80 Ok(())
81 }
82}