MCPcopy Index your code
hub / github.com/Rust-Web-Development/code / setup_store

Function setup_store

ch_11/src/lib.rs:93–120  ·  view source on GitHub ↗
(config: &config::Config)

Source from the content-addressed store, hash-verified

91}
92
93pub async fn setup_store(config: &config::Config) -> Result<store::Store, handle_errors::Error> {
94 let store = store::Store::new(&format!(
95 "postgres://{}:{}@{}:{}/{}",
96 config.db_user, config.db_password, config.db_host, config.db_port, config.db_name
97 ))
98 .await
99 .map_err(handle_errors::Error::DatabaseQueryError)?;
100
101 sqlx::migrate!()
102 .run(&store.clone().connection)
103 .await
104 .map_err(handle_errors::Error::MigrationError)?;
105
106 let log_filter = format!(
107 "handle_errors={},rust_web_dev={},warp={}",
108 config.log_level, config.log_level, config.log_level
109 );
110
111 tracing_subscriber::fmt()
112 // Use the filter we built above to determine which traces to record.
113 .with_env_filter(log_filter)
114 // Record an event when each span closes. This can be used to time our
115 // routes' durations!
116 .with_span_events(FmtSpan::CLOSE)
117 .init();
118
119 Ok(store)
120}
121
122pub async fn run(config: config::Config, store: store::Store) {
123 let routes = build_routes(store).await;

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls 1

initMethod · 0.45

Tested by

no test coverage detected