-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
1,677 additions
and
933 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,14 +4,18 @@ version = "0.1.0" | |
authors = ["ndelvalle <[email protected]>"] | ||
edition = "2021" | ||
|
||
[workspace] | ||
members = [".", "entity", "migration"] | ||
|
||
|
||
[dependencies] | ||
entity = { path = "entity" } | ||
migration = { path = "migration" } # depends on your needs | ||
|
||
config = "0.14.0" | ||
serde = { version = "1.0.202", features = ["derive"] } | ||
serde_json = "1.0.116" | ||
serde_derive = "1.0.152" | ||
# Wait for wither to relase a new version. | ||
# https://github.com/thedodd/wither/pull/89#issuecomment-1023644443 | ||
wither = { git = "https://github.com/thedodd/wither", rev = "52fd503" } | ||
futures = "0.3.30" | ||
thiserror = "1.0.61" | ||
axum = { version = "0.6.20", features = ["headers"] } | ||
|
@@ -35,6 +39,7 @@ bcrypt = "0.15.1" | |
validator = { version = "0.18.1", features = ["derive"] } | ||
mime = "0.3.17" | ||
bytes = "1.6.0" | ||
sea-orm = "0.12.15" | ||
|
||
[dev-dependencies] | ||
assert-json-diff = "2.0.2" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
{ | ||
"environment": "production", | ||
|
||
"logger": { | ||
"level": "info" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
mod entities; | ||
pub use entities::*; | ||
|
||
pub use entities::cat; | ||
pub use entities::user; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,25 @@ | ||
use mongodb::Database; | ||
use sea_orm::{ConnectOptions, Database, DatabaseConnection}; | ||
use tokio::sync::OnceCell; | ||
use wither::mongodb; | ||
|
||
use std::time::Duration; | ||
|
||
use crate::settings::SETTINGS; | ||
|
||
static CONNECTION: OnceCell<Database> = OnceCell::const_new(); | ||
static CONNECTION: OnceCell<DatabaseConnection> = OnceCell::const_new(); | ||
|
||
pub async fn connection() -> &'static DatabaseConnection { | ||
CONNECTION | ||
.get_or_init(|| async { | ||
let uri = SETTINGS.database.uri.as_str(); | ||
let mut opt = ConnectOptions::new(uri); | ||
|
||
pub async fn connection() -> &'static Database { | ||
CONNECTION | ||
.get_or_init(|| async { | ||
let db_uri = SETTINGS.database.uri.as_str(); | ||
let db_name = SETTINGS.database.name.as_str(); | ||
opt.min_connections(100) | ||
.max_connections(1) | ||
.connect_timeout(Duration::from_secs(10)); | ||
|
||
mongodb::Client::with_uri_str(db_uri) | ||
Database::connect(opt) | ||
.await | ||
.expect("Failed to connect to PostgreSQL") | ||
}) | ||
.await | ||
.expect("Failed to initialize MongoDB connection") | ||
.database(db_name) | ||
}) | ||
.await | ||
} |
Oops, something went wrong.