forked from launchbadge/sqlx
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdatabase.rs
More file actions
32 lines (27 loc) · 717 Bytes
/
database.rs
File metadata and controls
32 lines (27 loc) · 717 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
use console::style;
use dialoguer::Confirm;
use sqlx::any::Any;
use sqlx::migrate::MigrateDatabase;
pub async fn create(uri: &str) -> anyhow::Result<()> {
if !Any::database_exists(uri).await? {
Any::create_database(uri).await?;
}
Ok(())
}
pub async fn drop(uri: &str, confirm: bool) -> anyhow::Result<()> {
if confirm
&& !Confirm::new()
.with_prompt(format!(
"\nAre you sure you want to drop the database at {}?",
style(uri).cyan()
))
.default(false)
.interact()?
{
return Ok(());
}
if Any::database_exists(uri).await? {
Any::drop_database(uri).await?;
}
Ok(())
}