Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions cornucopia/src/cli.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use clap::{Parser, Subcommand};

use crate::{conn, container, error::Error, generate_live, generate_managed, CodegenSettings};
use crate::{conn, error::Error, generate_live, generate_managed, CodegenSettings};

/// Command line interface to interact with Cornucopia SQL.
#[derive(Parser, Debug)]
Expand Down Expand Up @@ -65,7 +65,7 @@ pub fn run() -> Result<(), Error> {
}
Action::Schema { schema_files } => {
// Run the generate command. If the command is unsuccessful, cleanup Cornucopia's container
if let Err(e) = generate_managed(
generate_managed(
&queries_path,
schema_files,
Some(&destination),
Expand All @@ -74,10 +74,7 @@ pub fn run() -> Result<(), Error> {
is_async: !sync,
derive_ser: serialize,
},
) {
container::cleanup(podman).ok();
return Err(e);
}
)?;
}
};
Ok(())
Expand Down
13 changes: 12 additions & 1 deletion cornucopia/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,18 @@ pub fn generate_managed(
destination: Option<&str>,
podman: bool,
settings: CodegenSettings,
) -> Result<String, Error> {
let result = generate(queries_path, podman, schema_files, settings, destination);
container::cleanup(podman).ok();
result
}

fn generate(
queries_path: &str,
podman: bool,
schema_files: Vec<String>,
settings: CodegenSettings,
destination: Option<&str>,
) -> Result<String, Error> {
// Read
let modules = read_query_modules(queries_path)?
Expand All @@ -85,7 +97,6 @@ pub fn generate_managed(
load_schema(&mut client, schema_files)?;
let prepared_modules = prepare(&mut client, modules)?;
let generated_code = generate_internal(prepared_modules, settings);
container::cleanup(podman)?;

if let Some(destination) = destination {
write_generated_code(destination, &generated_code)?;
Expand Down