MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / new

Method new

crates/opencode-storage/src/database.rs:31–53  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

29
30impl Database {
31 pub async fn new() -> Result<Self, DatabaseError> {
32 let db_path = Self::get_database_path()?;
33
34 if let Some(parent) = db_path.parent() {
35 std::fs::create_dir_all(parent)
36 .map_err(|e| DatabaseError::ConnectionError(e.to_string()))?;
37 }
38
39 let db_url = format!("sqlite:{}?mode=rwc", db_path.display());
40
41 info!("Connecting to database at {}", db_path.display());
42
43 let pool = SqlitePoolOptions::new()
44 .max_connections(5)
45 .connect(&db_url)
46 .await
47 .map_err(|e| DatabaseError::ConnectionError(e.to_string()))?;
48
49 let db = Self { pool };
50 db.run_migrations().await?;
51
52 Ok(db)
53 }
54
55 pub async fn in_memory() -> Result<Self, DatabaseError> {
56 let pool = SqlitePoolOptions::new()

Callers

nothing calls this directly

Calls 3

newFunction · 0.85
run_migrationsMethod · 0.80
connectMethod · 0.45

Tested by

no test coverage detected