forked from
rocksky.app/rocksky
A decentralized music tracking and discovery platform built on AT Protocol 馃幍
1use core::create_tables;
2use std::{
3 env,
4 sync::{Arc, Mutex},
5};
6
7use clap::Command;
8use cmd::{serve::serve, sync::sync};
9use dotenv::dotenv;
10use duckdb::Connection;
11use sqlx::postgres::PgPoolOptions;
12
13pub mod cmd;
14pub mod core;
15pub mod handlers;
16pub mod subscriber;
17pub mod types;
18pub mod xata;
19
20fn cli() -> Command {
21 Command::new("analytics")
22 .version(env!("CARGO_PKG_VERSION"))
23 .about("Rocksky Analytics CLI built with Rust and DuckDB")
24 .subcommand(Command::new("sync").about("Sync data from Xata to DuckDB"))
25 .subcommand(Command::new("serve").about("Serve the Rocksky Analytics API"))
26}
27
28#[tokio::main]
29async fn main() -> Result<(), Box<dyn std::error::Error>> {
30 dotenv().ok();
31
32 let pool = PgPoolOptions::new()
33 .max_connections(5)
34 .connect(&env::var("XATA_POSTGRES_URL")?)
35 .await?;
36 let conn = Connection::open("./rocksky-analytics.ddb")?;
37
38 create_tables(&conn).await?;
39
40 let args = cli().get_matches();
41 let conn = Arc::new(Mutex::new(conn));
42
43 match args.subcommand() {
44 Some(("sync", _)) => sync(conn, &pool).await?,
45 Some(("serve", _)) => serve(conn).await?,
46 _ => serve(conn).await?,
47 }
48
49 Ok(())
50}