Butane database adapter for Rocket framework
Configure your database in Rocket.toml
. Parameters url
and backend_name
are required.
toml
[default.databases.test]
backend_name = "sqlite" #Butane's backend name
url = "test.db"
Add and init database in your application's code ```rust
struct DbConn(butanerocketpool::Connection);
fn rocket() -> _ { rocket::build().mount("/", routes![create]) .attach(DbConn::fairing()) } ``` 3. To use the connection with Butane functions apply two dereference operators.
```rust
async fn create(db: DbConn, post: Json
match result {
Ok(res) => (Status::Created, json!({
"message" : "Post is created!",
"data" : res
})),
Err(err) => (Status::InternalServerError, json!({
"message" : "Can't create post!",
"error" : format!("{}", err)
}))
}
} ```