Upgrade skyrim-cell-dump and handle Cow<str>s

This commit is contained in:
2021-07-23 23:40:05 -04:00
parent 19126f4981
commit 39ae7703b0
4 changed files with 36 additions and 45 deletions

View File

@@ -1,9 +1,10 @@
use anyhow::{Context, Result};
use chrono::NaiveDateTime;
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use tracing::instrument;
#[derive(Debug, Serialize, Deserialize)]
#[derive(Debug, Serialize, Deserialize, FromRow)]
pub struct Plugin {
pub id: i32,
pub name: String,
@@ -30,30 +31,29 @@ pub async fn insert(
size: i64,
author: Option<&str>,
description: Option<&str>,
masters: &[String],
masters: &[&str],
file_name: &str,
file_path: &str,
) -> Result<Plugin> {
sqlx::query_as!(
Plugin,
"INSERT INTO plugins
// sqlx doesn't understand slices of &str with the query_as! macro: https://github.com/launchbadge/sqlx/issues/280
sqlx::query_as(
r#"INSERT INTO plugins
(name, hash, file_id, version, size, author, description, masters, file_name, file_path, created_at, updated_at)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, now(), now())
ON CONFLICT (file_id, file_path) DO UPDATE
SET (name, hash, version, author, description, masters, file_name, updated_at) =
(EXCLUDED.name, EXCLUDED.hash, EXCLUDED.version, EXCLUDED.author, EXCLUDED.description, EXCLUDED.masters, EXCLUDED.file_name, now())
RETURNING *",
name,
hash,
file_id,
version,
size,
author,
description,
masters,
file_name,
file_path
RETURNING *"#,
)
.bind(name)
.bind(hash)
.bind(file_id)
.bind(version)
.bind(size)
.bind(author)
.bind(description)
.bind(masters)
.bind(file_name)
.fetch_one(pool)
.await
.context("Failed to insert plugin")