improve README

This commit is contained in:
guochao 2022-08-05 08:04:32 +08:00
parent 0fb0cdd2fd
commit 9b8999e0f3
Signed by: guochao
GPG Key ID: 79F7306D2AA32FC3

View File

@ -46,6 +46,58 @@ The template provides a simple [Dockerfile](build/Dockerfile) and [script](scrip
### Define a new model ### Define a new model
1. Install sea-orm-cli first
```
cargo install sea-orm-cli
```
2. Define migration in [migrations](src/migrations)
```rust
#[derive(Iden)]
pub enum User { // Identifiers for User table
Table, // Table Identifier
Id, // Id Column Identifier
Name, // Name Column Identifier
Password, // Password Column Identifier
}
impl MigrationName for Migration {
fn name(&self) -> &str {
"m20220804_000001_create_user_table" // A migration name `m$(date +%Y%m%d)_8digitno_desc`
}
}
#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: & sea_orm_migration::SchemaManager) -> Result<(),sea_orm::DbErr> {
manager.create_table(
Table::create()
.table(User::Table) // Table
.col(ColumnDef::new(User::Id).integer().primary_key().auto_increment().not_null()) // And each col
.col(ColumnDef::new(User::Name).string().unique_key().not_null())
.col(ColumnDef::new(User::Password).string().not_null())
.to_owned()
).await
}
async fn down(&self, manager: & sea_orm_migration::SchemaManager) -> Result<(),sea_orm::DbErr> {
manager.drop_table(Table::drop().table(User::Table).to_owned()).await
}
}
```
3. Add migration into migrator
> TODO
4. Run migrator
> TODO
5. Generate models
> TODO > TODO
## Roadmap ## Roadmap