Skip to content

Commit

Permalink
refactor: use &str instead of String
Browse files Browse the repository at this point in the history
  • Loading branch information
mrjackwills committed May 6, 2024
1 parent 766220c commit f39364f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/database/postgres/models/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl<'r> FromRow<'r, PgRow> for ModelUser {
max_monthly_bandwidth_in_bytes: row.try_get("max_monthly_bandwidth_in_bytes")?,
timestamp: row.try_get("timestamp")?,
user_level_id: row.try_get("user_level_id")?,
user_level: UserLevel::from(row.try_get::<'r, String, &str>("user_level_name")?),
user_level: UserLevel::from(row.try_get::<'r, &str, &str>("user_level_name")?),
custom_device_name: row.try_get("custom_device_name")?,
device_password: row.try_get("device_password")?,
structured_data: row.try_get("structured_data")?,
Expand Down Expand Up @@ -284,6 +284,7 @@ WHERE
.execute(&mut *transaction)
.await?;

// These are wrong
ModelUserAgentIp::delete_ip(&mut transaction, redis).await?;
ModelUserAgentIp::delete_useragent(&mut transaction, redis).await?;

Expand Down
6 changes: 3 additions & 3 deletions src/database/postgres/models/user_level.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ impl sqlx::Type<sqlx::Postgres> for UserLevel {
}
}

impl From<String> for UserLevel {
fn from(user_level: String) -> Self {
match user_level.as_str() {
impl From<&str> for UserLevel {
fn from(user_level: &str) -> Self {
match user_level {
"admin" => Self::Admin,
"pro" => Self::Pro,
_ => Self::Free,
Expand Down

0 comments on commit f39364f

Please sign in to comment.