refactor: 🔨 workspace organization: workspace deps
This commit is contained in:
parent
5d80f46e6e
commit
38442e5146
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
@ -19,8 +19,7 @@
|
||||
"target": true,
|
||||
|
||||
// 📝 readmes
|
||||
"**/**/README.md": true,
|
||||
"LICENSE": true,
|
||||
// "**/**/README.md": true,
|
||||
|
||||
// 🗑️
|
||||
"check_size.py": true,
|
||||
|
||||
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -1095,6 +1095,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"entities",
|
||||
"eyre",
|
||||
"log",
|
||||
"prost",
|
||||
"tonic",
|
||||
"tonic-build",
|
||||
@ -2249,6 +2250,7 @@ dependencies = [
|
||||
"entities",
|
||||
"eyre",
|
||||
"grpc",
|
||||
"log",
|
||||
"tokio",
|
||||
]
|
||||
|
||||
|
||||
@ -24,12 +24,19 @@ path = "app/main.rs"
|
||||
[workspace]
|
||||
members = [".", "migration", "entities", "grpc"]
|
||||
|
||||
[workspace.dependencies]
|
||||
log = { version = "0.4.21" }
|
||||
eyre = { version = "0.6.12" }
|
||||
|
||||
[dependencies]
|
||||
# internal
|
||||
entities = { path = "entities" }
|
||||
grpc = { path = "grpc" }
|
||||
|
||||
# workspace
|
||||
log = { workspace = true }
|
||||
eyre = { workspace = true, default-features = false, features = ["auto-install"] }
|
||||
|
||||
# external
|
||||
eyre = { version = "0.6.12", default-features = false, features = ["auto-install"] }
|
||||
tokio = { version = "1.36.0", features = ["macros", "rt-multi-thread"] }
|
||||
dotenvy = "0.15.7"
|
||||
|
||||
@ -27,6 +27,9 @@
|
||||
## Commands
|
||||
|
||||
```bash
|
||||
# run migrations
|
||||
task db:migrate
|
||||
# add a dependency to a project
|
||||
cargo add {dependency} -p {project}
|
||||
|
||||
# example
|
||||
cargo add tokio-tungstenite -p gateway
|
||||
```
|
||||
21
app/main.rs
21
app/main.rs
@ -1,9 +1,4 @@
|
||||
use {
|
||||
dotenvy::dotenv,
|
||||
entities::sea_orm::{ConnectionTrait, Database, DbBackend, Statement},
|
||||
eyre::Result,
|
||||
std::sync::Arc,
|
||||
};
|
||||
use {dotenvy::dotenv, eyre::Result, log::info};
|
||||
|
||||
// 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
|
||||
@ -11,19 +6,9 @@ use {
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
dotenv()?;
|
||||
let conn = entities::db::get_connection().await?;
|
||||
|
||||
let db_conn_str = std::env::var("DATABASE_URL")?;
|
||||
// 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?;
|
||||
info!("Starting gRPC server...");
|
||||
|
||||
grpc::server::start(conn.clone()).await?;
|
||||
|
||||
|
||||
@ -9,5 +9,12 @@ name = "entities"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
sea-orm = { version = "0.12.15", features = ["runtime-tokio-native-tls", "sqlx-sqlite", "macros"] }
|
||||
eyre = { version = "0.6.12", default-features = false }
|
||||
# common
|
||||
eyre = { workspace = true, default-features = false }
|
||||
|
||||
# external
|
||||
sea-orm = { version = "0.12.15", features = [
|
||||
"runtime-tokio-native-tls",
|
||||
"sqlx-sqlite",
|
||||
"macros",
|
||||
] }
|
||||
|
||||
@ -2,3 +2,27 @@ pub mod market;
|
||||
pub mod ticker;
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
@ -10,5 +10,5 @@ path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
entities = { path = "../entities" }
|
||||
eyre = { version = "0.6.12", default-features = false }
|
||||
eyre = { workspace = true, default-features = false }
|
||||
|
||||
|
||||
@ -9,8 +9,14 @@ name = "grpc"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
# common
|
||||
log = { workspace = true }
|
||||
eyre = { workspace = true, default-features = false }
|
||||
|
||||
# internal
|
||||
entities = { path = "../entities" }
|
||||
eyre = { version = "0.6.12", default-features = false }
|
||||
|
||||
# external
|
||||
prost = "0.12.3"
|
||||
tonic = "0.11.0"
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user