Help with error in connection #726
Answered
by
tyt2y3
fabioluciano
asked this question in
Q&A
-
Can anybody help me figure out what i'm doing wrong? I'm following the documentation and set two files: main.rs mod database;
use entity::url::Entity as Url;
use sea_orm::EntityTrait;
fn main() {
get_urls();
}
pub async fn get_urls() {
let connection = database::get_connection();
let urls = Url::find().all(&connection);
} database.rs use sea_orm::{ConnectOptions, Database, DatabaseConnection};
use std::time::Duration;
pub async fn get_connection() -> Result<DatabaseConnection, sea_orm::DbErr> {
let mut opt = ConnectOptions::new(std::env::var("DATABASE_URL").unwrap());
opt.max_connections(100)
.min_connections(5)
.connect_timeout(Duration::from_secs(8))
.idle_timeout(Duration::from_secs(8))
.max_lifetime(Duration::from_secs(8))
.sqlx_logging(true);
Ok(Database::connect(opt).await.unwrap())
} i`'m getting:
What i'm doing wrong? I just follow the documentation. |
Beta Was this translation helpful? Give feedback.
Answered by
tyt2y3
May 14, 2022
Replies: 1 comment
-
You did not unwrap the Result. |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
fabioluciano
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You did not unwrap the Result.
Try
let connection = database::get_connection()?;
but then yourget_urls
needs to return a result as well.I suggest you take a second look at the
examples/basic
project.