/// Save a new edit into the db
Save a new edit into the db
Save a new edit into the db
pub async fn insert_edit(form: EditForm, conn: &ToolsDb) -> Result<Edit> {
    conn.run(move |c| {
        let new_edit = NewEdit {
            wiki: &form.wiki,
            text: form.text.as_bytes(),
            summary: &form.summary,
            baserevid: &form.baserevid,
            pageid: &form.pageid,
            pagename: &form.pagename,
            state: "pending",
        };
        // FIXME: validate data input is sane
        match diesel::insert_into(schema::edits::table)
            .values(&new_edit)
            .execute(c)
        {
            Ok(_) => {
                use schema::edits::dsl::*;
                Ok(edits.order(id.desc()).first(c).unwrap())
            }
            Err(e) => Err(e.into()),
        }
    })
    .await
}
pub async fn insert_edit ( form : EditForm , conn : & ToolsDb ) -> Result < Edit > { conn . run ( move | c | { let new_edit = NewEdit { wiki : & form . wiki , text : form . text . as_bytes ( ) , summary : & form . summary , baserevid : & form . baserevid , pageid : & form . pageid , pagename : & form . pagename , state : " " , } ; // FIXME: validate data input is sane match diesel :: insert_into ( schema :: edits :: table ) . values ( & new_edit ) . execute ( c ) { Ok ( _ ) => { use schema :: edits :: dsl :: * ; Ok ( edits . order ( id . desc ( ) ) . first ( c ) . unwrap ( ) ) } Err ( e ) => Err ( e . into ( ) ) , } } ) . await }
Save a new edit into the db
Save a new edit into the db
form
EditForm
conn
&ToolsDb