routes: pastes: Finish impl of paste creation
Signed-off-by: ATechnoHazard <amolele@gmail.com>
This commit is contained in:
15 files changed
+141
-22
No files matched your search
@@ -1,10 +1,10 @@
|
||||
use crate::schema::pastes;
|
||||
|
||||
#[table_name="pastes"]
|
||||
#[table_name = "pastes"]
|
||||
#[derive(AsChangeset, Serialize, Deserialize, Queryable, Insertable)]
|
||||
pub struct Paste {
|
||||
pub id: Option<String>,
|
||||
pub belongs_to: String,
|
||||
pub belongs_to: Option<String>,
|
||||
pub is_url: bool,
|
||||
pub content: String
|
||||
pub content: String,
|
||||
}
|
||||
@@ -1,4 +1,3 @@
|
||||
pub mod entity;
|
||||
pub mod repository;
|
||||
pub mod diesel;
|
||||
pub mod postgres;
|
||||
pub mod service;
|
||||
@@ -1,13 +1,14 @@
|
||||
use diesel::{RunQueryDsl};
|
||||
use anyhow::Result;
|
||||
use diesel::pg::PgConnection;
|
||||
use diesel::result::Error;
|
||||
use diesel::RunQueryDsl;
|
||||
|
||||
use crate::schema::pastes;
|
||||
|
||||
use super::entity::Paste;
|
||||
|
||||
pub fn create_paste(paste: &Paste, conn: &PgConnection) -> Result<usize, Error> {
|
||||
diesel::insert_into(pastes::table)
|
||||
pub fn create_paste(paste: &Paste, conn: &PgConnection) -> Result<usize> {
|
||||
let rows = diesel::insert_into(pastes::table)
|
||||
.values(paste)
|
||||
.execute(conn)
|
||||
.execute(conn)?;
|
||||
Ok(rows)
|
||||
}
|
||||
Whitespace-only changes.
@@ -0,0 +1,9 @@
|
||||
use anyhow::Result;
|
||||
use diesel::pg::PgConnection;
|
||||
|
||||
use super::entity::Paste;
|
||||
use super::postgres;
|
||||
|
||||
pub fn create_paste(paste: &Paste, conn: &PgConnection) -> Result<usize> {
|
||||
postgres::create_paste(paste, conn)
|
||||
}
|
||||
Reference in new issue
Block a user