names-changer

Crates.ionames-changer
lib.rsnames-changer
version0.2.1
sourcesrc
created_at2021-01-28 18:38:12.06833
updated_at2021-02-02 19:50:40.914764
descriptionConvert a names of sql schemes from camelcase to snake case.
homepage
repositoryhttps://github.com/mnnxp/names-changer
max_upload_size
id347724
size19,166
(mnnxp)

documentation

https://docs.rs/names-changer

README

names-changer

Convert a names of sql schemes from camelcase to snake case.

Taking data as str. This crate #[names_changer] provides trait method .camel_to_snake() that convert a names from camel case to snake case. The trait searches for words matching the pattern and converts them to snake case.

Getting Started

First of all you have to add this dependency to your Cargo.toml:

[dev-dependencies]
names-changer = "0.2.1"

Additionally, you have to import the procedural macro with use statement:

use names_changer::NamesChanger;

Example usage:

#[cfg(test)]
mod tests {
   use names_changer::NamesChanger;

   // Not needed for this example, but useful in general
   use super::*;

   #[test]
   fn test_name_change() {
       let content = "TABLE ClientTokensRef IS 'text';";
       let change_content = content.camel_to_snake();

       assert_eq!("TABLE client_tokens_ref IS 'text';", change_content)
   }
}

Why is it?

This for update old sql schemes with names include of upper case e.g.

#[cfg(test)]
mod tests {
   use names_changer::NamesChanger;
   use heck::SnakeCase;

   #[test]
   fn test_names_changer_to_snake_case() {
       let content = "TABLE ClientTokensRef IS 'text';";
       
       assert_eq!("TABLE client_tokens_ref IS 'text';", content.camel_to_snake())
   }

   #[test]
   fn test_classic_to_snake_case() {
       let content = "TABLE ClientTokensRef IS 'text';";

       assert_eq!("table_client_tokens_ref_is_text", content.to_snake_case()())
   }
}

What's new

0.2.1

  • fixed bug with skipping small words, i.e. "idExt", "idEx", "dE".

0.2.0

  • fixed bug with method name
  • added recursive processing of segments without spaces: from "(ClientRefA (ClientRefB (ClientRefC ((ClientRefE (id)))))" we get "(client_ref_a (client_ref_b (client_ref_c ((client_ref_e (id)))))"
  • added tests
  • case crate (the have problems with abbreviations) replaced with heck

Cons: requires a lot of resources, not optimized.

Todos

  • fix warning

  • optimize code

  • add asynchronous processing?

License

This project is licensed under either of

Commit count: 28

cargo fmt