MCPcopy Create free account
hub / github.com/chirpstack/chirpstack / sqlite_establish_connection

Function sqlite_establish_connection

chirpstack/src/storage/sqlite.rs:49–73  ·  view source on GitHub ↗
(
    url: &str,
)

Source from the content-addressed store, hash-verified

47}
48
49fn sqlite_establish_connection(
50 url: &str,
51) -> BoxFuture<'_, ConnectionResult<SyncConnectionWrapper<SqliteConnection>>> {
52 let url = url.to_string();
53 tokio::task::spawn_blocking(
54 move || -> ConnectionResult<SyncConnectionWrapper<SqliteConnection>> {
55 let mut conn = SqliteConnection::establish(&url)?;
56
57 use diesel::connection::SimpleConnection;
58 let conf = config::get();
59 let pragmas = &conf
60 .sqlite
61 .pragmas
62 .iter()
63 .map(|p| format!("PRAGMA {};", p))
64 .collect::<Vec<String>>()
65 .join("");
66 conn.batch_execute(pragmas)
67 .map_err(|err| ConnectionError::BadConnection(err.to_string()))?;
68 Ok(SyncConnectionWrapper::new(conn))
69 },
70 )
71 .unwrap_or_else(|err| Err(ConnectionError::BadConnection(err.to_string())))
72 .boxed()
73}
74
75fn get_async_db_pool() -> Result<AsyncSqlitePool> {
76 let pool_r = ASYNC_SQLITE_POOL.read().unwrap();

Callers

nothing calls this directly

Calls 3

to_stringMethod · 0.80
iterMethod · 0.80
getFunction · 0.70

Tested by

no test coverage detected