MCPcopy Create free account
hub / github.com/erans/pgsqlite / main

Function main

src/main.rs:29–232  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

27
28#[tokio::main]
29async fn main() -> Result<()> {
30 let config = Config::load();
31
32 // Initialize logging
33 tracing_subscriber::fmt()
34 .with_env_filter(config.log_level.clone())
35 .init();
36
37 // Display version
38 info!("pgsqlite v{}", env!("CARGO_PKG_VERSION"));
39
40 // Determine database path based on --in-memory flag
41 let db_path = if config.in_memory {
42 info!("Using in-memory SQLite database (testing mode)");
43 ":memory:".to_string()
44 } else {
45 config.database.clone()
46 };
47
48 // Handle migration command
49 if config.migrate {
50 info!("Running database migrations...");
51
52 // Open connection directly for migration
53 let conn = rusqlite::Connection::open(&db_path)
54 .map_err(|e| anyhow::anyhow!("Failed to open database: {}", e))?;
55
56 // Register functions needed for migrations
57 pgsqlite::functions::register_all_functions(&conn)
58 .map_err(|e| anyhow::anyhow!("Failed to register functions: {}", e))?;
59
60 let mut runner = MigrationRunner::new(conn);
61 match runner.run_pending_migrations() {
62 Ok(applied) => {
63 if applied.is_empty() {
64 info!("No pending migrations. Database is up to date.");
65 } else {
66 info!("Successfully applied {} migrations: {:?}", applied.len(), applied);
67 }
68 std::process::exit(0);
69 }
70 Err(e) => {
71 error!("Migration failed: {}", e);
72 std::process::exit(1);
73 }
74 }
75 }
76
77 // Initialize database handler with direct executor
78 let db_handler = Arc::new(
79 DbHandler::new_with_config(&db_path, &config)
80 .map_err(|e| anyhow::anyhow!("Failed to create database handler: {}", e))?,
81 );
82
83 // Unix socket setup (only on Unix platforms)
84 #[cfg(unix)]
85 let (socket_path, unix_listener) = {
86 let socket_path = PathBuf::from(&config.socket_dir).join(format!(".s.PGSQL.{}", config.port));

Callers

nothing calls this directly

Calls 9

register_all_functionsFunction · 0.85
log_cache_statusFunction · 0.85
handle_tcp_connectionFunction · 0.85
initializeMethod · 0.80
initMethod · 0.45
cloneMethod · 0.45
is_emptyMethod · 0.45

Tested by

no test coverage detected