idk what to name this commit

This commit is contained in:
missing 2022-09-09 18:30:20 -05:00
parent 31066e6efa
commit 029cad16b4
3 changed files with 9 additions and 29 deletions

View file

@ -9,6 +9,8 @@ use sqlx::{
Decode, Encode, Executor, FromRow, Postgres, Type,
};
use crate::index::DependencyKind;
#[derive(Clone, Copy, Default, Debug)]
#[repr(transparent)]
pub struct PgU32(pub u32);
@ -107,7 +109,7 @@ pub struct DbDep {
pub optional: bool,
pub default_features: bool,
pub target: Option<String>,
pub kind: String,
pub kind: DependencyKind,
pub registry: Option<String>,
pub package: Option<String>,
pub features: Vec<String>,

View file

@ -1,9 +1,9 @@
use std::{collections::HashMap, process::Stdio, str::FromStr};
use std::{collections::HashMap, process::Stdio};
use futures_util::StreamExt;
use semver::{Version, VersionReq};
use serde::{Deserialize, Serialize};
use sqlx::query_as;
use sqlx::{query_as, Type};
use tokio::{
fs::{self, OpenOptions},
io::AsyncWriteExt,
@ -48,37 +48,15 @@ pub struct BaseDependency {
pub registry: Option<String>,
}
#[derive(Serialize, Deserialize, Clone, Copy)]
#[derive(Serialize, Deserialize, Clone, Copy, Type)]
#[serde(rename_all = "lowercase")]
#[sqlx(rename_all = "lowercase")]
pub enum DependencyKind {
Dev,
Build,
Normal,
}
impl DependencyKind {
pub fn to_db_repr(self) -> &'static str {
match self {
DependencyKind::Dev => "dev",
DependencyKind::Build => "build",
DependencyKind::Normal => "normal",
}
}
}
impl FromStr for DependencyKind {
type Err = ();
fn from_str(s: &str) -> Result<Self, Self::Err> {
match s {
"dev" => Ok(DependencyKind::Dev),
"build" => Ok(DependencyKind::Build),
"normal" => Ok(DependencyKind::Normal),
_ => Err(()),
}
}
}
pub async fn update_crate_from_db(
crate_id: PgU32,
state: &State,
@ -117,7 +95,7 @@ pub async fn update_crate_from_db(
optional: dep.optional,
default_features: dep.default_features,
target: dep.target,
kind: dep.kind.parse().unwrap(),
kind: dep.kind,
registry: dep.registry,
},
package: dep.package,

View file

@ -209,7 +209,7 @@ pub async fn new_crate(
.bind(&dep.base.optional)
.bind(&dep.base.default_features)
.bind(&dep.base.target)
.bind(&dep.base.kind.to_db_repr())
.bind(&dep.base.kind)
.bind(&dep.base.registry)
.bind(&dep.explicit_name_in_toml)
.bind(&dep.base.features)