Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[codegen] create the root folder if not exists #46

Closed
billy1624 opened this issue Sep 6, 2022 · 0 comments · Fixed by #40
Closed

[codegen] create the root folder if not exists #46

billy1624 opened this issue Sep 6, 2022 · 0 comments · Fixed by #40

Comments

@billy1624
Copy link
Member

Following command should output the source code to mysql folder in the current directory. However, if the directory doesn't exist, it will result in an error.

➜ cargo r mysql://root:root@localhost/sakila mysql mysql
    Finished dev [unoptimized + debuginfo] target(s) in 0.80s
     Running `target/debug/seaography 'mysql://root:root@localhost/sakila' mysql mysql`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: IoError(Os { code: 2, kind: NotFound, message: "No such file or directory" })', src/main.rs:19:10
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

I think we should always check the existence of the target directory before writing Cargo.toml file to it. Perhaps adding std::fs::create_dir_all(path.as_ref())?; before writer::write_cargo_toml(path, crate_name, &sql_version)?; at:

  • let (tables, sql_version) =
    seaography_discoverer::extract_database_metadata(&database_url).await?;
    writer::write_cargo_toml(path, crate_name, &sql_version)?;
    std::fs::create_dir_all(&path.as_ref().join("src/entities"))?;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant