pub async fn namechange(
        conn: &mut SqliteConnection,
        old: &Path,
        new: &Path,
    ) -> Result<(), anyhow::Error> {
        let id = query::get_by_path(conn, old.to_str().unwrap())
            .await?
            .zettel_id;
        let new_timestamp = {
            let meta = fs::metadata(new)?;
            let ts: chrono::DateTime<Utc> = meta.created()?.into();
            ts.timestamp()
        };
        conn.execute(
            sqlx::query_as::<_, Zettel>(
                "UPDATE zettels SET timestamp = ?, title = ? WHERE zettel_id = ?",
            )
            .bind(&new_timestamp)
            .bind(new.file_name().unwrap().to_str())
            .bind(old.file_name().unwrap().to_str())
            .bind(&id),
        )
        .await?;
        conn.execute(
            sqlx::query_as::<_, Zettel>("UPDATE full_text SET timestamp = ? WHERE zettel_id = ?")
                .bind(&new_timestamp)
                .bind(old.file_name().unwrap().to_str())
                .bind(&id),
        )
        .await?;
        conn.execute(
            sqlx::query_as::<_, Zettel>(
                "UPDATE headers SET timestamp = ?, title = ? zettel_id = ?",
            )
            .bind(&new_timestamp)
            .bind(new.file_name().unwrap().to_str())
            .bind(&id),
        )
        .await?;
        conn.execute(
            sqlx::query_as::<_, Zettel>(
                "UPDATE links SET timestamp = ?, title = ? WHERE zettel_id = ?",
            )
            .bind(&new_timestamp)
            .bind(new.file_name().unwrap().to_str())
            .bind(old.file_name().unwrap().to_str())
            .bind(&id),
        )
        .await?;
        conn.execute(
            sqlx::query_as::<_, Zettel>(
                "UPDATE tags SET timestamp = ?, title = ? WHERE zettel_id = ?",
            )
            .bind(&new_timestamp)
            .bind(new.file_name().unwrap().to_str())
            .bind(&id),
        )
        .await?;
        Ok(())
    }
/// Update a zettel when notified of a file name change
Update a zettel when notified of a file name change
Update a zettel when notified of a file name change
pub async fn namechange(
        conn: &mut SqliteConnection,
        old: &Path,
        new: &Path,
    ) -> Result<(), anyhow::Error> {
        let id = query::get_by_path(conn, old.to_str().unwrap())
            .await?
            .zettel_id;
        let new_timestamp = {
            let meta = fs::metadata(new)?;
            let ts: chrono::DateTime<Utc> = meta.created()?.into();
            ts.timestamp()
        };
        conn.execute(
            sqlx::query_as::<_, Zettel>(
                "UPDATE zettels SET timestamp = ?, title = ? WHERE zettel_id = ?",
            )
            .bind(&new_timestamp)
            .bind(new.file_name().unwrap().to_str())
            .bind(old.file_name().unwrap().to_str())
            .bind(&id),
        )
        .await?;
        conn.execute(
            sqlx::query_as::<_, Zettel>("UPDATE full_text SET timestamp = ? WHERE zettel_id = ?")
                .bind(&new_timestamp)
                .bind(old.file_name().unwrap().to_str())
                .bind(&id),
        )
        .await?;
        conn.execute(
            sqlx::query_as::<_, Zettel>(
                "UPDATE headers SET timestamp = ?, title = ? zettel_id = ?",
            )
            .bind(&new_timestamp)
            .bind(new.file_name().unwrap().to_str())
            .bind(&id),
        )
        .await?;
        conn.execute(
            sqlx::query_as::<_, Zettel>(
                "UPDATE links SET timestamp = ?, title = ? WHERE zettel_id = ?",
            )
            .bind(&new_timestamp)
            .bind(new.file_name().unwrap().to_str())
            .bind(old.file_name().unwrap().to_str())
            .bind(&id),
        )
        .await?;
        conn.execute(
            sqlx::query_as::<_, Zettel>(
                "UPDATE tags SET timestamp = ?, title = ? WHERE zettel_id = ?",
            )
            .bind(&new_timestamp)
            .bind(new.file_name().unwrap().to_str())
            .bind(&id),
        )
        .await?;
        Ok(())
    }
pub async fn namechange ( conn : & mut SqliteConnection , old : & Path , new : & Path , ) -> Result < ( ) , anyhow :: Error > { let id = query :: get_by_path ( conn , old . to_str ( ) . unwrap ( ) ) . await ? . zettel_id ; let new_timestamp = { let meta = fs :: metadata ( new ) ? ; let ts : chrono :: DateTime < Utc > = meta . created ( ) ? . into ( ) ; ts . timestamp ( ) } ; conn . execute ( sqlx :: query_as :: < _ , Zettel > ( " " , ) . bind ( & new_timestamp ) . bind ( new . file_name ( ) . unwrap ( ) . to_str ( ) ) . bind ( old . file_name ( ) . unwrap ( ) . to_str ( ) ) . bind ( & id ) , ) . await ? ; conn . execute ( sqlx :: query_as :: < _ , Zettel > ( " " ) . bind ( & new_timestamp ) . bind ( old . file_name ( ) . unwrap ( ) . to_str ( ) ) . bind ( & id ) , ) . await ? ; conn . execute ( sqlx :: query_as :: < _ , Zettel > ( " " , ) . bind ( & new_timestamp ) . bind ( new . file_name ( ) . unwrap ( ) . to_str ( ) ) . bind ( & id ) , ) . await ? ; conn . execute ( sqlx :: query_as :: < _ , Zettel > ( " " , ) . bind ( & new_timestamp ) . bind ( new . file_name ( ) . unwrap ( ) . to_str ( ) ) . bind ( old . file_name ( ) . unwrap ( ) . to_str ( ) ) . bind ( & id ) , ) . await ? ; conn . execute ( sqlx :: query_as :: < _ , Zettel > ( " " , ) . bind ( & new_timestamp ) . bind ( new . file_name ( ) . unwrap ( ) . to_str ( ) ) . bind ( & id ) , ) . await ? ; Ok ( ( ) ) }
Update a zettel when notified of a file name change
Update a zettel when notified of a file name change
conn
&mut SqliteConnection
old
&Path
new
&Path
conn
&mut SqliteConnection
old
&Path
new
&Path