Skip to content
Merged
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
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "cornucopia"
version = "0.9.0"
edition = "2021"
edition = "2024"
rust-version = "1.88.0"
license = "MIT/Apache-2.0"
description = "Generate type-checked Rust from your PostgreSQL queries."
Expand Down Expand Up @@ -75,7 +75,7 @@ harness = false
path = "benches/codegen.rs"

[workspace]
resolver = "2"
resolver = "3"
members = ["examples/*", "tests/*"]
exclude = ["examples/basic_async_wasm"]

Expand Down
2 changes: 1 addition & 1 deletion examples/auto_build/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "auto-build"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_async/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
edition = "2021"
edition = "2024"
name = "basic-async"
version = "0.1.0"
publish = false
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_async_wasm/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
edition = "2021"
edition = "2024"
name = "basic-async-wasm"
version = "0.1.0"
publish = false
Expand Down
2 changes: 1 addition & 1 deletion examples/basic_sync/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "basic_sync"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
edition = "2021"
edition = "2024"
name = "custom-types"
version = "0.1.0"
publish = false
Expand Down
2 changes: 1 addition & 1 deletion examples/custom_types/db/db_types/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "db_types"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ pub fn idx_char(idx: usize) -> String {
format!("T{idx}")
}

pub(crate) fn gen(preparation: Preparation, config: &Config) -> Vfs {
pub(crate) fn generate(preparation: Preparation, config: &Config) -> Vfs {
let mut vfs = Vfs::empty();
let cargo = cargo::gen_cargo_file(&preparation.dependency_analysis, config);
vfs.add_string("Cargo.toml", cargo);
Expand Down
28 changes: 13 additions & 15 deletions src/codegen/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,21 +149,19 @@ impl DependencyContext<'_> {

fn get_workspace_deps(manifest_path: &Path) -> HashSet<String> {
let mut deps = HashSet::new();
if let Ok(contents) = fs::read_to_string(manifest_path) {
if let Ok(manifest) = toml::from_str::<cargo_toml::Value>(&contents) {
if let Some(workspace) = manifest
.get("workspace")
.and_then(|w| w.get("dependencies"))
{
deps.extend(
workspace
.as_table()
.into_iter()
.flat_map(|t| t.keys())
.map(|s| s.to_string()),
);
}
}
if let Ok(contents) = fs::read_to_string(manifest_path)
&& let Ok(manifest) = toml::from_str::<cargo_toml::Value>(&contents)
&& let Some(workspace) = manifest
.get("workspace")
.and_then(|w| w.get("dependencies"))
{
deps.extend(
workspace
.as_table()
.into_iter()
.flat_map(|t| t.keys())
.map(|s| s.to_string()),
);
}
deps
}
Expand Down
4 changes: 2 additions & 2 deletions src/codegen/queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,7 +703,7 @@ fn gen_specific(

pub(crate) fn gen_queries(vfs: &mut Vfs, preparation: &Preparation, config: &Config) {
for module in &preparation.modules {
let gen = gen_query_module(module, config);
let module_tokens = gen_query_module(module, config);

let path_components: Vec<&str> = module.info.full_module_path.split("::").collect();
let file_name = &module.info.name;
Expand All @@ -717,7 +717,7 @@ pub(crate) fn gen_queries(vfs: &mut Vfs, preparation: &Preparation, config: &Con

let file_path = format!("{dir_path}/{file_name}.rs");

vfs.add(file_path, gen);
vfs.add(file_path, module_tokens);
}

let module_tree = crate::read_queries::build_module_hierarchy(
Expand Down
30 changes: 15 additions & 15 deletions src/codegen/vfs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,23 +192,23 @@ impl Vfs {
};

// If something went wrong and we have a backup, restore it
if result.is_err() {
if let Some(backup_dir) = backup_dir {
// Clean the destination directory if it exists after a failed operation
if destination.exists() {
let _ = std::fs::remove_dir_all(destination);
}
if result.is_err()
&& let Some(backup_dir) = backup_dir
{
// Clean the destination directory if it exists after a failed operation
if destination.exists() {
let _ = std::fs::remove_dir_all(destination);
}

// Ensure the destination directory exists for restoration
let _ = std::fs::create_dir_all(destination);
// Ensure the destination directory exists for restoration
let _ = std::fs::create_dir_all(destination);

// Restore from backup
if let Err(restore_err) = copy_dir_recursive(backup_dir.path(), destination) {
// If restoration also fails, return a compound error
return Err(PersistError::wrap(
"failed to restore backup after generation error",
)(restore_err));
}
// Restore from backup
if let Err(restore_err) = copy_dir_recursive(backup_dir.path(), destination) {
// If restoration also fails, return a compound error
return Err(PersistError::wrap(
"failed to restore backup after generation error",
)(restore_err));
}
}

Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ impl Config {
config.manifest.package = default_manifest().package;
}

if let Some(manifest) = &mut config.manifest.package {
if manifest.edition == cargo_toml::Inheritable::Set(cargo_toml::Edition::E2015) {
manifest.edition = cargo_toml::Inheritable::Set(cargo_toml::Edition::E2021);
}
if let Some(manifest) = &mut config.manifest.package
&& manifest.edition == cargo_toml::Inheritable::Set(cargo_toml::Edition::E2015)
{
manifest.edition = cargo_toml::Inheritable::Set(cargo_toml::Edition::E2021);
}

config.check_deprecated_fields();
Expand Down
6 changes: 3 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ pub fn gen_live(client: &Client, config: Config) -> Result<(), Error> {

// Generate
let prepared_modules = prepare(client, modules, &config).map_err(Box::new)?;
let generated = codegen::gen(prepared_modules, &config);
let generated = codegen::generate(prepared_modules, &config);

// Write
generated.persist(config.destination, config.static_files)?;
Expand Down Expand Up @@ -88,7 +88,7 @@ pub fn gen_managed<P: AsRef<Path>>(schema_files: &[P], config: Config) -> Result
let client = conn::cornucopia_conn()?;
load_schema(&client, schema_files).map_err(Box::new)?;
let prepared_modules = prepare(&client, modules, &config).map_err(Box::new)?;
let generated = codegen::gen(prepared_modules, &config);
let generated = codegen::generate(prepared_modules, &config);
container::cleanup(config.podman)?;

// Write
Expand Down Expand Up @@ -143,7 +143,7 @@ pub fn gen_fresh<P: AsRef<Path>>(
load_schema(&db_client, schema_files).map_err(Box::new)?;

let prepared_modules = prepare(&db_client, modules, &config).map_err(Box::new)?;
let generated = codegen::gen(prepared_modules, &config);
let generated = codegen::generate(prepared_modules, &config);

generated.persist(config.destination, config.static_files)?;

Expand Down
12 changes: 6 additions & 6 deletions src/read_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ fn read_query_modules_recursive(

if path_buf.is_dir() {
// Skip directories starting with underscore if configured to do so
if let Some(dir_name) = path_buf.file_name() {
if let Some(dir_name_str) = dir_name.to_str() {
if config.ignore_underscore_files && dir_name_str.starts_with('_') {
continue;
}
}
if let Some(dir_name) = path_buf.file_name()
&& let Some(dir_name_str) = dir_name.to_str()
&& config.ignore_underscore_files
&& dir_name_str.starts_with('_')
{
continue;
}

// Recursively process subdirectory
Expand Down
2 changes: 1 addition & 1 deletion tests/codegen/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "test_codegen"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false

[dependencies]
Expand Down
2 changes: 1 addition & 1 deletion tests/integration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "test_integration"
version = "0.1.0"
edition = "2021"
edition = "2024"
publish = false

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down