|
|
@ -60,6 +60,29 @@ async fn connect() -> Result<Pool<Sqlite>, sqlx::Error> { |
|
|
|
Ok(pool) |
|
|
|
Ok(pool) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, sqlx::Type)] |
|
|
|
|
|
|
|
pub enum BazTypes { |
|
|
|
|
|
|
|
#[sqlx(rename = "foo")] |
|
|
|
|
|
|
|
One, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[sqlx(rename = "bar")] |
|
|
|
|
|
|
|
Two, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[sqlx(rename = "baz")] |
|
|
|
|
|
|
|
Three, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[derive(Debug, sqlx::FromRow)] |
|
|
|
|
|
|
|
struct Foo { |
|
|
|
|
|
|
|
id: i32, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[sqlx(rename = "bar")] |
|
|
|
|
|
|
|
indicator: String, |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#[sqlx(rename = "baz")] |
|
|
|
|
|
|
|
foo_type: BazTypes, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
#[tokio::main] |
|
|
|
#[tokio::main] |
|
|
|
async fn main() -> Result<(), sqlx::Error> { |
|
|
|
async fn main() -> Result<(), sqlx::Error> { |
|
|
|
let pool = connect().await?; |
|
|
|
let pool = connect().await?; |
|
|
@ -74,14 +97,16 @@ async fn main() -> Result<(), sqlx::Error> { |
|
|
|
|
|
|
|
|
|
|
|
println!("Command: \"{}\"", command); |
|
|
|
println!("Command: \"{}\"", command); |
|
|
|
|
|
|
|
|
|
|
|
if command == "add" { |
|
|
|
match command.as_str() { |
|
|
|
|
|
|
|
"add" => { |
|
|
|
println!("Should add \"{}\"", value); |
|
|
|
println!("Should add \"{}\"", value); |
|
|
|
let record = Label { |
|
|
|
let record = Label { |
|
|
|
id: None, |
|
|
|
id: None, |
|
|
|
description: value.into(), |
|
|
|
description: value.into(), |
|
|
|
}; |
|
|
|
}; |
|
|
|
repo.save(&record).await?; |
|
|
|
repo.save(&record).await?; |
|
|
|
} else if command == "remove" { |
|
|
|
} |
|
|
|
|
|
|
|
"remove" => { |
|
|
|
println!("Should remove \"{}\"", value); |
|
|
|
println!("Should remove \"{}\"", value); |
|
|
|
match repo.find_by_description(&value).await { |
|
|
|
match repo.find_by_description(&value).await { |
|
|
|
Ok(record) => { |
|
|
|
Ok(record) => { |
|
|
@ -93,5 +118,37 @@ async fn main() -> Result<(), sqlx::Error> { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
"one" => { |
|
|
|
|
|
|
|
let pool = connect().await.unwrap(); |
|
|
|
|
|
|
|
let record = Foo { |
|
|
|
|
|
|
|
id: 1, |
|
|
|
|
|
|
|
indicator: value.into(), |
|
|
|
|
|
|
|
foo_type: BazTypes::One, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
println!("Adding Foo({:?})", record); |
|
|
|
|
|
|
|
sqlx::query("INSERT INTO foo (bar, baz) values ($1, $2);") |
|
|
|
|
|
|
|
.bind(&record.indicator) |
|
|
|
|
|
|
|
.bind(&record.foo_type) |
|
|
|
|
|
|
|
.execute(&pool) |
|
|
|
|
|
|
|
.await |
|
|
|
|
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
"two" => { |
|
|
|
|
|
|
|
let pool = connect().await.unwrap(); |
|
|
|
|
|
|
|
let record = Foo { |
|
|
|
|
|
|
|
id: 1, |
|
|
|
|
|
|
|
indicator: value.into(), |
|
|
|
|
|
|
|
foo_type: BazTypes::Two, |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
println!("Adding Foo({:?})", record); |
|
|
|
|
|
|
|
sqlx::query("INSERT INTO foo (bar, baz) values ($1, $2);") |
|
|
|
|
|
|
|
.bind(&record.indicator) |
|
|
|
|
|
|
|
.bind(&record.foo_type) |
|
|
|
|
|
|
|
.execute(&pool) |
|
|
|
|
|
|
|
.await |
|
|
|
|
|
|
|
.unwrap(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
_ => println!("Unknonw command"), |
|
|
|
|
|
|
|
} |
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|