You've already forked AstralRinth
forked from didirus/AstralRinth
Migrate to MongoDB
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
use diesel::pg::PgConnection;
|
||||
use diesel::prelude::*;
|
||||
use dotenv::dotenv;
|
||||
use std::env;
|
||||
use mongodb::options::ClientOptions;
|
||||
use mongodb::Client;
|
||||
use mongodb::error::Error;
|
||||
|
||||
pub fn connect() -> PgConnection {
|
||||
dotenv().ok();
|
||||
pub async fn connect() -> Result<Client, Error> {
|
||||
info!("Initializing database connection");
|
||||
|
||||
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set!");
|
||||
PgConnection::establish(&database_url)
|
||||
.unwrap_or_else(|_| panic!("Error connecting to {}", database_url))
|
||||
let mut client_options = ClientOptions::parse("mongodb://localhost:27017").await?;
|
||||
client_options.app_name = Some("Actix Web Server".to_string());
|
||||
|
||||
Client::with_options(client_options)
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
use chrono::NaiveDate;
|
||||
use serde::{Serialize, Deserialize};
|
||||
|
||||
#[derive(Queryable)]
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Mod {
|
||||
pub id: i32,
|
||||
pub title: String,
|
||||
pub description: String,
|
||||
pub published: NaiveDate,
|
||||
pub published: String,
|
||||
pub author: String,
|
||||
pub downloads: i32,
|
||||
pub categories: Vec<String>,
|
||||
@@ -13,14 +13,14 @@ pub struct Mod {
|
||||
pub icon_path: String,
|
||||
}
|
||||
|
||||
#[derive(Queryable)]
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct Version {
|
||||
pub version_id: i32,
|
||||
pub mod_id: i32,
|
||||
pub title: String,
|
||||
pub changelog_path: String,
|
||||
pub files_path: Vec<String>,
|
||||
pub date_published: NaiveDate,
|
||||
pub date_published: String,
|
||||
pub author: String,
|
||||
pub downloads: i32,
|
||||
pub dependencies: Vec<String>,
|
||||
|
||||
Reference in New Issue
Block a user