mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-23 00:45:37 +01:00
check if datbase is initialized before display schema, index and tables
This commit is contained in:
29
cli/app.rs
29
cli/app.rs
@@ -945,6 +945,15 @@ impl Limbo {
|
||||
}
|
||||
|
||||
fn display_schema(&mut self, table: Option<&str>) -> anyhow::Result<()> {
|
||||
if !self.conn.is_db_initialized() {
|
||||
if let Some(table_name) = table {
|
||||
self.write_fmt(format_args!("-- Error: Table '{table_name}' not found."))?;
|
||||
} else {
|
||||
self.writeln("-- No tables or indexes found in the database.")?;
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let sql = match table {
|
||||
Some(table_name) => format!(
|
||||
"SELECT sql FROM sqlite_schema WHERE type IN ('table', 'index') AND tbl_name = '{table_name}' AND name NOT LIKE 'sqlite_%'"
|
||||
@@ -1002,6 +1011,15 @@ impl Limbo {
|
||||
}
|
||||
|
||||
fn display_indexes(&mut self, maybe_table: Option<String>) -> anyhow::Result<()> {
|
||||
if !self.conn.is_db_initialized() {
|
||||
if let Some(tbl_name) = &maybe_table {
|
||||
self.write_fmt(format_args!("-- Error: Table '{tbl_name}' not found."))?;
|
||||
} else {
|
||||
self.writeln("-- No indexes found in the database.")?;
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let sql = match maybe_table {
|
||||
Some(ref tbl_name) => format!(
|
||||
"SELECT name FROM sqlite_schema WHERE type='index' AND tbl_name = '{tbl_name}' ORDER BY 1"
|
||||
@@ -1050,6 +1068,17 @@ impl Limbo {
|
||||
}
|
||||
|
||||
fn display_tables(&mut self, pattern: Option<&str>) -> anyhow::Result<()> {
|
||||
if !self.conn.is_db_initialized() {
|
||||
if let Some(pattern) = pattern {
|
||||
self.write_fmt(format_args!(
|
||||
"-- Error: Tables with pattern '{pattern}' not found."
|
||||
))?;
|
||||
} else {
|
||||
self.writeln("-- No tables found in the database.")?;
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let sql = match pattern {
|
||||
Some(pattern) => format!(
|
||||
"SELECT name FROM sqlite_schema WHERE type='table' AND name NOT LIKE 'sqlite_%' AND name LIKE '{pattern}' ORDER BY 1"
|
||||
|
||||
@@ -1167,6 +1167,10 @@ impl Connection {
|
||||
let schema = Arc::make_mut(&mut *schema_ref);
|
||||
f(schema)
|
||||
}
|
||||
|
||||
pub fn is_db_initialized(&self) -> bool {
|
||||
self._db.db_state.is_initialized()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Statement {
|
||||
|
||||
Reference in New Issue
Block a user