sea-orm
sea-orm copied to clipboard
Why does sea-orm-cli generate entity not include Cargo.toml file
Description
Steps to Reproduce
- When I use sea-orm-cli generate entity: not auto generate Cargo.toml file.
- exec cmd
~ sea-orm-cli generate entity \
-o entity/src \
--with-serde both
➜ tree
entity
└── src
├── device_config.rs
├── biz_info.rs
├── biz_task.rs
├── mod.rs
├── node.rs
├── prelude.rs
├── pack.rs
Versions
Additional Information
➜ sea-orm-cli -Vv
sea-orm-cli 0.8.1
➜
I expect whole cargo library. But now ,lost Cargo.toml not running. Need I add manully
- My guess is to consider that
entitycan also be used as amoduleinstead of astandalone package. - Below is my go-task script, you can use it. It fixes this automatically.
- This is not a big problem. Officials can add a support in the generation options.
tasks:
migrate:orm:model:
cmds:
- sea-orm-cli generate entity -u ${DATABASE_URL} -o {{.APP_NAME}}/src
- cd {{.APP_NAME}}; cargo init --lib;
- cd {{.APP_NAME}}; mv src/mod.rs src/lib.rs;
- cd {{.APP_NAME}}; cargo add serde@1 --features derive
- cd {{.APP_NAME}}; cargo add [email protected]
vars:
APP_NAME: "entity"
ignore_error: true
Maybe we can add a flag? Generate mod or new crate?
Maybe we can add a flag? Generate mod or new crate?
Yeah, related discussion
- https://github.com/SeaQL/sea-orm/discussions/604
May be sea-orm support config this all option into file. and then exec :sea-orm-cli, that all people can read file config known how to do it.
May be sea-orm support config this all option into file. and then exec :sea-orm-cli, that all people can read file config known how to do it.
Do you mean sea-orm-cli can load configuration (e.g. -u ${DATABASE_URL} -o {{.APP_NAME}}/src) from a environment file (.env file)? Then, user can simply execute the command sea-orm-cli generate entity.
Maybe we can add a flag? Generate mod or new crate?
Yeah, that's what I'm thinking. By default, it generate a module which is the current behaviour. We can introduce a new flag --lib which will generate a crate with a src folder that contains all of the generated entity files and mod.rs will be lib.rs, and of cause a Cargo.toml file with sea-orm dependency.
I'll open this issue for anyone interested to contribute :) We'd provide the necessary guidance
Yeah, that's what I'm thinking. By default, it generate a module which is the current behaviour. We can introduce a new flag
--libwhich will generate a crate with asrcfolder that contains all of the generated entity files andmod.rswill belib.rs, and of cause aCargo.tomlfile withsea-ormdependency.
If there are too many configurations of sea ORM cli, consider the configuration method:
e.g:
➜ ls
├── Cargo.toml
├── README.md
├── sea-orm.toml
├── migration
├── src
All configuration write in sea-orm.toml.
The more options sea ORM cli has, the more complex it is to use,not friendly.
Maybe we can solve this by introducing sea-orm-cli entity init analogous to sea-orm-cli migrate init?
This would reduce the number of manual steps required of setting up a project, thus improving developer experience. We also could introduce a flag which controls whether to create a module or a lib.rs.
I'll open this issue for anyone interested to contribute :) We'd provide the necessary guidance
@billy1624 If you are planning to add those features I would like to contribute.
The required features are still not decided but I can say we are looking for 2 things
- option to export as module or library
- read parameters from the config file or environment variables.