feat(server): start api using CRUD operations
This commit is contained in:
parent
e08048d0f0
commit
37218536c5
11 changed files with 69 additions and 6 deletions
5
server/src/db/entities/mod.rs
Normal file
5
server/src/db/entities/mod.rs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
||||
|
||||
pub mod prelude;
|
||||
|
||||
pub mod repo;
|
||||
3
server/src/db/entities/prelude.rs
Normal file
3
server/src/db/entities/prelude.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.1
|
||||
|
||||
pub use super::repo::Entity as Repo;
|
||||
18
server/src/db/entities/repo.rs
Normal file
18
server/src/db/entities/repo.rs
Normal 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 {}
|
||||
|
|
@ -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(),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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?;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue