remove sqlx from database-tree

pull/62/head
Takayuki Maeda 3 years ago
parent 5d0be971db
commit 465f719f3c

1
Cargo.lock generated

@ -288,7 +288,6 @@ version = "0.1.0-alpha.1"
dependencies = [
"anyhow",
"chrono",
"sqlx",
"thiserror",
]

@ -11,6 +11,5 @@ description = "Database tree structure"
[dependencies]
thiserror = "1.0"
sqlx = { version = "0.5.7", features = ["chrono", "runtime-tokio-rustls"], default-features = false }
chrono = "0.4"
anyhow = "1.0.38"

@ -50,16 +50,11 @@ pub struct Schema {
pub tables: Vec<Table>,
}
#[derive(sqlx::FromRow, Debug, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
pub struct Table {
#[sqlx(rename = "Name")]
pub name: String,
#[sqlx(rename = "Create_time")]
pub create_time: Option<chrono::DateTime<chrono::Utc>>,
#[sqlx(rename = "Update_time")]
pub update_time: Option<chrono::DateTime<chrono::Utc>>,
#[sqlx(rename = "Engine")]
pub engine: Option<String>,
#[sqlx(default)]
pub schema: Option<String>,
}

@ -158,10 +158,18 @@ impl Pool for MySqlPool {
}
async fn get_tables(&self, database: String) -> anyhow::Result<Vec<Child>> {
let tables =
sqlx::query_as::<_, Table>(format!("SHOW TABLE STATUS FROM `{}`", database).as_str())
.fetch_all(&self.pool)
.await?;
let query = format!("SHOW TABLE STATUS FROM `{}`", database);
let mut rows = sqlx::query(query.as_str()).fetch(&self.pool);
let mut tables = vec![];
while let Some(row) = rows.try_next().await? {
tables.push(Table {
name: row.try_get("Name")?,
create_time: row.try_get("Create_time")?,
update_time: row.try_get("Update_time")?,
engine: row.try_get("Engine")?,
schema: None,
})
}
Ok(tables.into_iter().map(|table| table.into()).collect())
}

Loading…
Cancel
Save