I'm not that good with Diesel yet am I
continuous-integration/drone the build failed
Details
continuous-integration/drone the build failed
Details
parent
4faf19aae5
commit
e1282dacb0
|
@ -187,6 +187,7 @@ dependencies = [
|
|||
"diesel_derives",
|
||||
"pq-sys",
|
||||
"r2d2",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -417,6 +418,7 @@ dependencies = [
|
|||
"diesel_migrations",
|
||||
"rocket",
|
||||
"rocket_sync_db_pools",
|
||||
"uuid",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1379,6 +1381,15 @@ version = "0.2.2"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "8ccb82d61f80a663efe1f787a51b16b5a51e3314d6ac365b08639f52387b33f3"
|
||||
|
||||
[[package]]
|
||||
name = "uuid"
|
||||
version = "0.8.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bc5cf98d8186244414c848017f0e2676b3fcb46807f6668a97dfe67359a3c4b7"
|
||||
dependencies = [
|
||||
"getrandom",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "vcpkg"
|
||||
version = "0.2.15"
|
||||
|
|
|
@ -22,10 +22,15 @@ doctest = true
|
|||
|
||||
[dependencies]
|
||||
rocket = "0.5.0-rc.1"
|
||||
diesel = { version = "1.4.7", features = ["postgres"] }
|
||||
diesel = { version = "1.4.7", features = ["postgres", "uuidv07"] }
|
||||
diesel_migrations = "1.4.0"
|
||||
|
||||
[dependencies.rocket_sync_db_pools]
|
||||
version = "0.1.0-rc.1"
|
||||
default_features = false
|
||||
features = ["diesel_postgres_pool"]
|
||||
|
||||
[dependencies.uuid]
|
||||
version = "0.8.2"
|
||||
default_features = false
|
||||
features = [ "v4" ]
|
||||
|
|
|
@ -2,4 +2,4 @@
|
|||
# see diesel.rs/guides/configuring-diesel-cli
|
||||
|
||||
[print_schema]
|
||||
file = "src/schema.rs"
|
||||
file = "src/libhilde/schema.rs"
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
-- This file should undo anything in `up.sql`
|
||||
DROP TABLE distributions;
|
|
@ -0,0 +1,12 @@
|
|||
-- Your SQL goes here
|
||||
CREATE TABLE distributions (
|
||||
id uuid DEFAULT gen_random_uuid() PRIMARY KEY,
|
||||
|
||||
name text UNIQUE NOT NULL,
|
||||
description text,
|
||||
origin text,
|
||||
label text,
|
||||
version text,
|
||||
suite text,
|
||||
codename text
|
||||
);
|
|
@ -4,13 +4,15 @@ extern crate rocket;
|
|||
#[macro_use]
|
||||
extern crate diesel_migrations;
|
||||
|
||||
mod routes;
|
||||
|
||||
use rocket::{fairing::AdHoc, Build, Rocket};
|
||||
use rocket_sync_db_pools::{database, diesel};
|
||||
|
||||
embed_migrations!();
|
||||
|
||||
#[database("postgres_hilde")]
|
||||
struct HildeDbConn(diesel::PgConnection);
|
||||
pub struct HildeDbConn(diesel::PgConnection);
|
||||
|
||||
async fn run_db_migrations(rocket: Rocket<Build>) -> Result<Rocket<Build>, Rocket<Build>> {
|
||||
let conn = HildeDbConn::get_one(&rocket)
|
||||
|
@ -31,4 +33,5 @@ fn rocket() -> _ {
|
|||
"Run database migrations",
|
||||
run_db_migrations,
|
||||
))
|
||||
.mount("/", routes::routes())
|
||||
}
|
||||
|
|
|
@ -0,0 +1,13 @@
|
|||
use rocket::Route;
|
||||
use libhilde::packages::generate_release_file;
|
||||
use crate::HildeDbConn;
|
||||
|
||||
pub fn routes() -> Vec<Route> {
|
||||
routes![get_dist_release]
|
||||
}
|
||||
|
||||
// NOTE: for now, only dists without slashes are supported
|
||||
#[get("/dists/<dist>/Release")]
|
||||
async fn get_dist_release(conn: HildeDbConn, dist: String) -> String {
|
||||
conn.run(|c| generate_release_file(dist, c)).await
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
#[macro_use]
|
||||
extern crate diesel;
|
||||
|
||||
pub mod packages;
|
||||
pub mod schema;
|
|
@ -0,0 +1,21 @@
|
|||
use diesel::{PgConnection, Queryable, QueryDsl, ExpressionMethods, RunQueryDsl};
|
||||
use crate::schema::distributions::dsl::*;
|
||||
|
||||
#[derive(Queryable)]
|
||||
struct Distribution {
|
||||
id: uuid::Uuid,
|
||||
name: String,
|
||||
description: Option<String>,
|
||||
origin: Option<String>,
|
||||
label: Option<String>,
|
||||
version: Option<String>,
|
||||
suite: Option<String>,
|
||||
codename: Option<String>
|
||||
}
|
||||
|
||||
/// Generate a Release file for a given distribution
|
||||
pub fn generate_release_file(dist: String, conn: &PgConnection) -> String {
|
||||
let results = distributions.filter(name.eq(dist)).load::<Distribution>(conn).unwrap();
|
||||
|
||||
format!("{}", results.len())
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
table! {
|
||||
distributions (id) {
|
||||
id -> Uuid,
|
||||
name -> Text,
|
||||
description -> Nullable<Text>,
|
||||
origin -> Nullable<Text>,
|
||||
label -> Nullable<Text>,
|
||||
version -> Nullable<Text>,
|
||||
suite -> Nullable<Text>,
|
||||
codename -> Nullable<Text>,
|
||||
}
|
||||
}
|
Reference in New Issue