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![(
16 Type::Nothing,
17 Type::Custom("sqlite-in-memory".into()),
18 )])
19 .allow_variants_without_examples(true)
20 .category(Category::Database)
21 }
22
23 fn description(&self) -> &str {
24 "Opens the in-memory sqlite database."
25 }
26
27 fn search_terms(&self) -> Vec<&str> {
28 vec!["sqlite", "storing", "access"]
29 }
30
31 fn examples(&self) -> Vec<Example<'_>> {
32 vec![Example {
33 description: "Open the in-memory sqlite database",
34 example: "stor open",
35 result: None,
36 }]
37 }
38
39 fn run(
40 &self,
41 _engine_state: &EngineState,
42 _stack: &mut Stack,
43 call: &Call,
44 _input: PipelineData,
45 ) -> Result<PipelineData, ShellError> {
46 let db = Box::new(SQLiteDatabase::new(
59 std::path::Path::new(MEMORY_DB),
60 Signals::empty(),
61 ));
62
63 Ok(db.into_value(call.head).into_pipeline_data())
65 }
66}
67
68#[cfg(test)]
69mod test {
70 use super::*;
71
72 #[test]
73 fn test_examples() -> nu_test_support::Result {
74 nu_test_support::test().examples(StorOpen)
75 }
76}