MCPcopy Create free account
hub / github.com/SeaQL/sea-orm / init

Method init

examples/rocket_example/api/src/pool.rs:24–38  ·  view source on GitHub ↗
(figment: &Figment)

Source from the content-addressed store, hash-verified

22 type Connection = sea_orm::DatabaseConnection;
23
24 async fn init(figment: &Figment) -> Result<Self, Self::Error> {
25 let config = figment.extract::<Config>().unwrap();
26 let mut options: ConnectOptions = config.url.into();
27 options
28 .max_connections(config.max_connections as u32)
29 .min_connections(config.min_connections.unwrap_or_default())
30 .connect_timeout(Duration::from_secs(config.connect_timeout))
31 .sqlx_logging(config.sqlx_logging);
32 if let Some(idle_timeout) = config.idle_timeout {
33 options.idle_timeout(Duration::from_secs(idle_timeout));
34 }
35 let conn = sea_orm::Database::connect(options).await?;
36
37 Ok(SeaOrmPool { conn })
38 }
39
40 async fn get(&self) -> Result<Self::Connection, Self::Error> {
41 Ok(self.conn.clone())

Callers 1

mainFunction · 0.45

Calls 6

unwrapMethod · 0.80
sqlx_loggingMethod · 0.80
connect_timeoutMethod · 0.80
min_connectionsMethod · 0.80
max_connectionsMethod · 0.80
idle_timeoutMethod · 0.80

Tested by

no test coverage detected