Skip to content

Commit

Permalink
doc
Browse files Browse the repository at this point in the history
  • Loading branch information
cn-kali-team committed Aug 20, 2023
1 parent 17116b5 commit e75ca23
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 16 deletions.
5 changes: 3 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ nvd-db = { path = "nvd-db", optional = true }
serde = { version = "1", features = ["derive"] }
quick-xml = { version = "0.29.0", features = ["serde", "encoding_rs", "serialize"] }
serde_yaml = "0.9"

serde_json = "1.0"
flate2 = "1.0"
zip = "0.6"
zip = "0.6"
cve = { path = "cve"}
Binary file modified nvd-db/nvd-er.mwb
Binary file not shown.
2 changes: 1 addition & 1 deletion nvd-db/src/cpe.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use crate::schema::{products, vendors};
use diesel::prelude::*;
use serde::{Deserialize, Serialize};


#[derive(Insertable)]
#[table_name = "vendors"]
Expand Down
2 changes: 1 addition & 1 deletion nvd-db/src/models.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::schema::vendors;

use chrono::NaiveDateTime;
use diesel::prelude::*;
#[derive(Queryable, Debug, Clone)]
Expand Down
18 changes: 9 additions & 9 deletions tools/src/bin/cpe_to_db.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use cached::proc_macro::cached;
use cached::SizedCache;
use cpe::dictionary::{CPEItem, CPEList};
use cpe::dictionary::{CPEList};
use diesel::mysql::MysqlConnection;
use diesel::prelude::*;
use diesel::result::Error;

use nvd_db::cpe::{NewProducts, NewVendors};
use nvd_db::models::{Product, Vendor};
use nvd_db::schema::{products, vendors};
Expand All @@ -28,13 +28,13 @@ pub fn create_vendor(
description,
};
// 插入到数据库
let v = diesel::insert_into(vendors::table)
let _v = diesel::insert_into(vendors::table)
.values(&new_post)
// MySQL does not support RETURNING clauses
.execute(conn);
println!("{}", name);
println!("{name}");
vendors::dsl::vendors
.filter(vendors::name.eq(name.clone()))
.filter(vendors::name.eq(name))
.first(conn)
.unwrap()
}
Expand All @@ -52,13 +52,13 @@ pub fn create_product(conn: &mut MysqlConnection, vendor: Vec<u8>, name: String)
description: None,
};
// 插入到数据库
let p = diesel::insert_into(products::table)
let _p = diesel::insert_into(products::table)
.values(&new_post)
// MySQL does not support RETURNING clauses
.execute(conn);
println!("{}", name);
println!("{name}");
products::dsl::products
.filter(products::name.eq(name.clone()))
.filter(products::name.eq(name))
.first(conn)
.unwrap()
}
Expand All @@ -70,7 +70,7 @@ pub fn create_product(conn: &mut MysqlConnection, vendor: Vec<u8>, name: String)
convert = r#"{ format!("{}:{}", vendor.to_owned(),product.to_owned()) }"#
)]
fn import_to_db(vendor: String, product: String) -> Product {
println!("import_to_db: {}:{}", vendor, product);
println!("import_to_db: {vendor}:{product}");
let mut connection = init_db_pool().get().unwrap();
let vendor = create_vendor(&mut connection, vendor, None);
create_product(&mut connection, vendor.id, product)
Expand Down
6 changes: 3 additions & 3 deletions tools/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ pub type Pool = r2d2::Pool<ConnectionManager<Connection>>;
pub fn init_db_pool() -> Pool {
let database_url = dotenvy::var("DATABASE_URL").expect("DATABASE_URL must be set");
let manager = ConnectionManager::<Connection>::new(database_url);
let pool = r2d2::Pool::builder()

r2d2::Pool::builder()
.build(manager)
.expect("Failed to create pool.");
pool
.expect("Failed to create pool.")
}

0 comments on commit e75ca23

Please sign in to comment.