feat(server): start api using CRUD operations

This commit is contained in:
Jef Roosens 2023-07-30 16:55:44 +02:00
parent e08048d0f0
commit 37218536c5
Signed by: Jef Roosens
GPG key ID: B75D4F293C7052DB
11 changed files with 69 additions and 6 deletions

View file

@ -0,0 +1,5 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
pub mod prelude;
pub mod repo;

View file

@ -0,0 +1,3 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
pub use super::repo::Entity as Repo;

View file

@ -0,0 +1,18 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
use sea_orm::entity::prelude::*;
use serde::Serialize;
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq, Serialize)]
#[sea_orm(table_name = "repo")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub name: String,
pub description: Option<String>,
}
#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}
impl ActiveModelBehavior for ActiveModel {}

View file

@ -23,7 +23,7 @@ impl MigrationTrait for Migration {
.auto_increment()
.primary_key(),
)
.col(ColumnDef::new(Repo::Name).string().not_null())
.col(ColumnDef::new(Repo::Name).string().not_null().unique_key())
.col(ColumnDef::new(Repo::Description).string())
.to_owned(),
)

View file

@ -1,4 +1,5 @@
mod migrator;
pub mod entities;
use migrator::Migrator;
use sea_orm::ConnectOptions;
@ -8,7 +9,7 @@ use sea_orm_migration::MigratorTrait;
pub async fn init<C: Into<ConnectOptions>>(
opt: C,
) -> Result<sea_orm::DatabaseConnection, sea_orm::DbErr> {
let mut db = Database::connect(opt).await?;
let db = Database::connect(opt).await?;
Migrator::refresh(&db).await?;