refactor: 🔨 workspace organization: workspace deps

This commit is contained in:
Lucas Colombo 2024-03-28 15:58:00 -03:00
parent 5d80f46e6e
commit 38442e5146
Signed by: lucas
GPG Key ID: EF34786CFEFFAE35
9 changed files with 60 additions and 27 deletions

View File

@ -19,8 +19,7 @@
"target": true, "target": true,
// 📝 readmes // 📝 readmes
"**/**/README.md": true, // "**/**/README.md": true,
"LICENSE": true,
// 🗑 // 🗑
"check_size.py": true, "check_size.py": true,

2
Cargo.lock generated
View File

@ -1095,6 +1095,7 @@ version = "0.1.0"
dependencies = [ dependencies = [
"entities", "entities",
"eyre", "eyre",
"log",
"prost", "prost",
"tonic", "tonic",
"tonic-build", "tonic-build",
@ -2249,6 +2250,7 @@ dependencies = [
"entities", "entities",
"eyre", "eyre",
"grpc", "grpc",
"log",
"tokio", "tokio",
] ]

View File

@ -24,12 +24,19 @@ path = "app/main.rs"
[workspace] [workspace]
members = [".", "migration", "entities", "grpc"] members = [".", "migration", "entities", "grpc"]
[workspace.dependencies]
log = { version = "0.4.21" }
eyre = { version = "0.6.12" }
[dependencies] [dependencies]
# internal # internal
entities = { path = "entities" } entities = { path = "entities" }
grpc = { path = "grpc" } grpc = { path = "grpc" }
# workspace
log = { workspace = true }
eyre = { workspace = true, default-features = false, features = ["auto-install"] }
# external # external
eyre = { version = "0.6.12", default-features = false, features = ["auto-install"] }
tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] } tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
dotenvy = "0.15.7" dotenvy = "0.15.7"

View File

@ -27,6 +27,9 @@
## Commands ## Commands
```bash ```bash
# run migrations # add a dependency to a project
task db:migrate cargo add {dependency} -p {project}
# example
cargo add tokio-tungstenite -p gateway
``` ```

View File

@ -1,9 +1,4 @@
use { use {dotenvy::dotenv, eyre::Result, log::info};
dotenvy::dotenv,
entities::sea_orm::{ConnectionTrait, Database, DbBackend, Statement},
eyre::Result,
std::sync::Arc,
};
// TODO: here we will trigger the start of both the grpc server and the websocket gateway // TODO: here we will trigger the start of both the grpc server and the websocket gateway
// look at: https://github.com/hyperium/tonic/discussions/740 // look at: https://github.com/hyperium/tonic/discussions/740
@ -11,19 +6,9 @@ use {
#[tokio::main] #[tokio::main]
async fn main() -> Result<()> { async fn main() -> Result<()> {
dotenv()?; dotenv()?;
let conn = entities::db::get_connection().await?;
let db_conn_str = std::env::var("DATABASE_URL")?; info!("Starting gRPC server...");
// let conn = Arc::new();
let conn = Arc::new(Database::connect(&db_conn_str).await?);
conn.query_one(Statement::from_string(
DbBackend::Sqlite,
r#"
PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
"#,
))
.await?;
grpc::server::start(conn.clone()).await?; grpc::server::start(conn.clone()).await?;

View File

@ -9,5 +9,12 @@ name = "entities"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
sea-orm = { version = "0.12.15", features = ["runtime-tokio-native-tls", "sqlx-sqlite", "macros"] } # common
eyre = { version = "0.6.12", default-features = false } eyre = { workspace = true, default-features = false }
# external
sea-orm = { version = "0.12.15", features = [
"runtime-tokio-native-tls",
"sqlx-sqlite",
"macros",
] }

View File

@ -2,3 +2,27 @@ pub mod market;
pub mod ticker; pub mod ticker;
pub use sea_orm; pub use sea_orm;
pub mod db {
use {
eyre::Result,
sea_orm::{ConnectionTrait, Database, DatabaseConnection, DbBackend, Statement},
std::sync::Arc,
};
pub async fn get_connection() -> Result<Arc<DatabaseConnection>> {
let db_conn_str = std::env::var("DATABASE_URL")?;
let conn = Arc::new(Database::connect(&db_conn_str).await?);
conn.query_one(Statement::from_string(
DbBackend::Sqlite,
r#"
PRAGMA journal_mode = WAL;
PRAGMA synchronous = NORMAL;
"#,
))
.await?;
Ok(conn)
}
}

View File

@ -10,5 +10,5 @@ path = "src/lib.rs"
[dependencies] [dependencies]
entities = { path = "../entities" } entities = { path = "../entities" }
eyre = { version = "0.6.12", default-features = false } eyre = { workspace = true, default-features = false }

View File

@ -9,8 +9,14 @@ name = "grpc"
path = "src/lib.rs" path = "src/lib.rs"
[dependencies] [dependencies]
# common
log = { workspace = true }
eyre = { workspace = true, default-features = false }
# internal
entities = { path = "../entities" } entities = { path = "../entities" }
eyre = { version = "0.6.12", default-features = false }
# external
prost = "0.12.3" prost = "0.12.3"
tonic = "0.11.0" tonic = "0.11.0"