sea-orm icon indicating copy to clipboard operation
sea-orm copied to clipboard

Why does sea-orm-cli generate entity not include Cargo.toml file

Open baoyachi opened this issue 3 years ago • 8 comments
trafficstars

Description

Steps to Reproduce

  1. 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

baoyachi avatar Jun 21 '22 03:06 baoyachi

  • My guess is to consider that entity can also be used as a module instead of a standalone 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

hhstore avatar Jun 30 '22 04:06 hhstore

Maybe we can add a flag? Generate mod or new crate?

ikrivosheev avatar Jul 04 '22 07:07 ikrivosheev

Maybe we can add a flag? Generate mod or new crate?

Yeah, related discussion

  • https://github.com/SeaQL/sea-orm/discussions/604

billy1624 avatar Jul 04 '22 07:07 billy1624

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.

baoyachi avatar Jul 04 '22 08:07 baoyachi

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.

billy1624 avatar Jul 06 '22 08:07 billy1624

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.

billy1624 avatar Jul 06 '22 08:07 billy1624

I'll open this issue for anyone interested to contribute :) We'd provide the necessary guidance

billy1624 avatar Jul 06 '22 08:07 billy1624

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.

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.

baoyachi avatar Jul 06 '22 16:07 baoyachi

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.

JonasCir avatar Oct 10 '22 13:10 JonasCir

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

  1. option to export as module or library
  2. read parameters from the config file or environment variables.

Diwakar-Gupta avatar Jan 17 '23 06:01 Diwakar-Gupta