improve README
This commit is contained in:
parent
4dbd95fd4b
commit
10c061d75f
35
README.md
35
README.md
@ -44,6 +44,12 @@ The template provides a simple [Dockerfile](build/Dockerfile) and [script](scrip
|
||||
|
||||
## Development
|
||||
|
||||
### FORMAT ON EVERY COMMIT
|
||||
|
||||
```
|
||||
cargo fmt
|
||||
```
|
||||
|
||||
### Define a new model
|
||||
|
||||
1. Install sea-orm-cli first
|
||||
@ -54,12 +60,16 @@ cargo install sea-orm-cli
|
||||
|
||||
2. Define migration in [migrations](src/migrations)
|
||||
|
||||
For example, we want a user table storing username and password. An Identity, a migration and the migration trait need to be defined:
|
||||
|
||||
```rust
|
||||
// m20220804_000001_create_user_table.rs
|
||||
|
||||
#[derive(Iden)]
|
||||
pub enum User { // Identifiers for User table
|
||||
Table, // Table Identifier
|
||||
Id, // Id Column Identifier
|
||||
Name, // Name Column Identifier
|
||||
Username, // Name Column Identifier
|
||||
Password, // Password Column Identifier
|
||||
}
|
||||
|
||||
@ -76,7 +86,7 @@ impl MigrationTrait for Migration {
|
||||
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::Username).string().unique_key().not_null())
|
||||
.col(ColumnDef::new(User::Password).string().not_null())
|
||||
.to_owned()
|
||||
).await
|
||||
@ -90,15 +100,28 @@ impl MigrationTrait for Migration {
|
||||
|
||||
3. Add migration into migrator
|
||||
|
||||
> TODO
|
||||
```rust
|
||||
#[async_trait::async_trait]
|
||||
impl MigratorTrait for Migrator {
|
||||
fn migrations() -> Vec<Box<dyn MigrationTrait>> {
|
||||
vec![
|
||||
Box::new(m20220804_000001_create_user_table::Migration),
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
4. Run migrator
|
||||
|
||||
> TODO
|
||||
```
|
||||
DATABASE_URL=sqlite://data.db cargo run -- migrate refresh
|
||||
```
|
||||
|
||||
5. Generate models
|
||||
5. Generate entities
|
||||
|
||||
> TODO
|
||||
```
|
||||
DATABASE_URL=sqlite://data.db sea-orm-cli generate entity --with-serde both -o ./src/web/model/
|
||||
```
|
||||
|
||||
## Roadmap
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user