123456789101112131415161718192021222324252627282930313233343536 |
- use chrono::NaiveDateTime;
- use diesel::pg::PgConnection as PGC;
- use diesel::prelude::*;
-
- use crate::schema::gists;
-
- #[derive(Queryable, Serialize, Deserialize)]
- pub struct Gist {
- pub id: i32,
- pub title: String,
- pub body: String,
- pub created_at: Option<NaiveDateTime>,
- pub filetype: Option<String>,
- }
-
- #[derive(Insertable, AsChangeset, Serialize, Deserialize)]
- #[table_name = "gists"]
- pub struct InsertableGist {
- pub title: String,
- pub body: String,
- pub filetype: Option<String>,
- }
-
- pub fn all(connection: &PGC) -> QueryResult<Vec<Gist>> {
- gists::table.load::<Gist>(&*connection)
- }
-
- pub fn get(connection: &PGC, id: i32) -> QueryResult<Gist> {
- gists::table.find(id).get_result::<Gist>(connection)
- }
-
- pub fn insert(gist: InsertableGist, connection: &PGC) -> QueryResult<Gist> {
- diesel::insert_into(gists::table)
- .values(gist)
- .get_result(connection)
- }
|