MCPcopy Create free account
hub / github.com/clockworklabs/SpacetimeDB / exec

Function exec

crates/cli/src/subcommands/repl.rs:41–93  ·  view source on GitHub ↗
(con: Connection)

Source from the content-addressed store, hash-verified

39";
40
41pub async fn exec(con: Connection) -> Result<(), anyhow::Error> {
42 let database = con.database.clone();
43 let mut rl = Editor::<ReplHelper, DefaultHistory>::new().unwrap();
44 let history = home_dir().unwrap_or_else(temp_dir).join(".stdb.history.txt");
45 if rl.load_history(&history).is_err() {
46 eprintln!("No previous history.");
47 }
48 rl.set_helper(Some(ReplHelper::new().unwrap()));
49
50 println!(
51 "\
52┌──────────────────────────────────────────────────────────┐
53│ .exit: Exit the REPL │
54│ .clear: Clear the Screen │
55│ │
56│ Give us feedback in our Discord server: │
57│ https://discord.gg/w2DVqNZXdN │
58└──────────────────────────────────────────────────────────┘",
59 );
60
61 let api = ClientApi::new(con);
62
63 loop {
64 let readline = rl.readline(&format!("🪐{}>", &database).green());
65 match readline {
66 Ok(line) => match line.as_str() {
67 ".exit" => break,
68 ".clear" => {
69 rl.clear_screen().ok();
70 }
71 sql => {
72 rl.add_history_entry(sql).ok();
73
74 if let Err(err) = run_sql(api.sql(), sql, true).await {
75 eprintln!("{}", err.to_string().red())
76 }
77 }
78 },
79 Err(ReadlineError::Interrupted) | Err(ReadlineError::Eof) => {
80 println!("\n{}", "Aborted!".red());
81 break;
82 }
83 x => {
84 eprintln!("\nUnexpected: {x:?}");
85 break;
86 }
87 }
88 }
89
90 rl.save_history(&history).ok();
91
92 Ok(())
93}
94
95pub(crate) struct ReplHelper {
96 syntaxes: SyntaxSet,

Callers

nothing calls this directly

Calls 10

run_sqlFunction · 0.85
joinMethod · 0.80
newFunction · 0.50
OkFunction · 0.50
cloneMethod · 0.45
unwrapMethod · 0.45
is_errMethod · 0.45
as_strMethod · 0.45
okMethod · 0.45
sqlMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…