-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dumped diesel ORM for the mysql driver in rust
- Loading branch information
1 parent
13526ba
commit 10d5d2c
Showing
10 changed files
with
612 additions
and
728 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
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,25 +1,13 @@ | ||
#[macro_use] | ||
extern crate rocket; | ||
|
||
use dotenvy::dotenv; | ||
use sea_orm::ConnectOptions; | ||
|
||
#[rocket::main] | ||
async fn main() -> Result<(), rocket::Error> { | ||
#[launch] | ||
fn rocket() -> _ { | ||
dotenv().ok(); | ||
|
||
let opt = database_options(); | ||
|
||
rocket::build() | ||
.mount("/api", api_lib::handlers::handlers()) | ||
.manage(sea_orm::Database::connect(opt).await.unwrap()) | ||
.launch() | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
fn database_options() -> ConnectOptions { | ||
let database_url = std::env::var("DATABASE_URL").unwrap(); | ||
|
||
let mut opt = ConnectOptions::new(database_url); | ||
opt.max_connections(100).min_connections(10); | ||
opt | ||
.manage(mysql::Pool::new("mysql://user:password@localhost:3306/f1db").unwrap()) | ||
} |
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
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,27 +1,16 @@ | ||
diesel::table! { | ||
circuits (circuit_id) { | ||
#[sql_name = "circuitId"] | ||
circuit_id -> Integer, | ||
#[sql_name = "circuitRef"] | ||
#[max_length = 255] | ||
circuit_ref -> Varchar, | ||
#[sql_name = "circuitName"] | ||
#[max_length = 255] | ||
circuit_name -> Varchar, | ||
#[sql_name = "circuitLocation"] | ||
#[max_length = 255] | ||
circuit_location -> Nullable<Varchar>, | ||
#[sql_name = "circuitCountry"] | ||
#[max_length = 255] | ||
country -> Nullable<Varchar>, | ||
#[sql_name = "circuitLat"] | ||
lat -> Nullable<Float>, | ||
#[sql_name = "circuitLng"] | ||
lng -> Nullable<Float>, | ||
#[sql_name = "circuitAlt"] | ||
alt -> Nullable<Integer>, | ||
#[sql_name = "circuitUrl"] | ||
#[max_length = 255] | ||
url -> Varchar, | ||
} | ||
use mysql::prelude::*; | ||
|
||
#[derive(FromRow, Debug)] | ||
pub struct Circuits { | ||
#[mysql(rename = "circuitId")] | ||
circuit_id: i32, | ||
#[mysql(rename = "circuitRef")] | ||
circuit_ref: String, | ||
name: String, | ||
location: Option<String>, | ||
country: Option<String>, | ||
lat: Option<f32>, | ||
lng: Option<f32>, | ||
alt: Option<i32>, | ||
url: String, | ||
} |