The backend of a gist server written in Rust
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

12345678910111213141516171819
  1. use diesel::pg::PgConnection as PGC;
  2. use diesel::prelude::*;
  3. use crate::schema::gists;
  4. #[derive(Queryable, AsChangeset, Serialize, Deserialize)]
  5. pub struct Gist {
  6. pub id: i32,
  7. pub title: String,
  8. pub body: String,
  9. }
  10. pub fn all(connection: &PGC) -> QueryResult<Vec<Gist>> {
  11. gists::table.load::<Gist>(&*connection)
  12. }
  13. pub fn get(connection: &PGC, id: i32) -> QueryResult<Gist> {
  14. gists::table.find(id).get_result::<Gist>(connection)
  15. }