Generate Entity from Database

Now that we have a database with a defined schema, we can generate the entities with sea-orm-cli.

sea-orm-cli is able to discover the schema given the database URL and generated the appropriate entity files.

# In case you have not installed `sea-orm-cli`
$ cargo install sea-orm-cli
# Generate entity files of database `bakeries_db` to `src/entities`
$ sea-orm-cli generate entity \
    -u mysql://root:password@localhost:3306/bakeries_db \
    -o src/entities

The generated entity files:

├── Cargo.toml
├── migration
│   └── ...
└── src
    ├── entities
    │   ├──
    │   ├──
    │   ├──
    │   └──

Put the focus on and, they are the entities representing the tables Baker and Bakery, respectively.