feat: add a project model

This commit is contained in:
Matouš Volf 2024-08-17 00:23:05 +02:00
parent 2262111f97
commit 283b3965db
5 changed files with 34 additions and 0 deletions

View File

@ -0,0 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE IF EXISTS "projects";

View File

@ -0,0 +1,6 @@
-- Your SQL goes here
CREATE TABLE "projects"(
"id" SERIAL NOT NULL PRIMARY KEY,
"title" TEXT NOT NULL
);

1
src/models/mod.rs Normal file
View File

@ -0,0 +1 @@
pub(crate) mod project;

17
src/models/project.rs Normal file
View File

@ -0,0 +1,17 @@
use crate::schema::projects;
use diesel::prelude::*;
use serde::{Deserialize, Serialize};
#[derive(Queryable, Selectable, Serialize, Deserialize)]
#[diesel(table_name = crate::schema::projects)]
#[diesel(check_for_backend(diesel::pg::Pg))]
pub struct Project {
pub(crate) id: i32,
pub(crate) title: String,
}
#[derive(Insertable, Serialize, Deserialize)]
#[diesel(table_name = projects)]
pub struct NewProject<'a> {
pub title: &'a str,
}

8
src/schema/mod.rs Normal file
View File

@ -0,0 +1,8 @@
// @generated automatically by Diesel CLI.
diesel::table! {
projects (id) {
id -> Int4,
title -> Text,
}
}