chore: upgrade heck in sea-orm-codegen to 0.4 (#1544)

This commit is contained in:
Billy Chan 2023-03-16 19:05:58 +08:00 committed by GitHub
parent 2150e0c683
commit e903f17b15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 32 additions and 32 deletions

View File

@ -20,7 +20,7 @@ path = "src/lib.rs"
sea-query = { version = "0.28.3", default-features = false, features = ["thread-safe"] }
syn = { version = "1", default-features = false }
quote = { version = "1", default-features = false }
heck = { version = "0.3", default-features = false }
heck = { version = "0.4", default-features = false }
proc-macro2 = { version = "1", default-features = false }
tracing = { version = "0.1", default-features = false, features = ["log"] }

View File

@ -1,4 +1,4 @@
use heck::CamelCase;
use heck::ToUpperCamelCase;
use proc_macro2::TokenStream;
use quote::{format_ident, quote};
use sea_query::DynIden;
@ -14,13 +14,13 @@ pub struct ActiveEnum {
impl ActiveEnum {
pub fn impl_active_enum(&self, with_serde: &WithSerde, with_copy_enums: bool) -> TokenStream {
let enum_name = &self.enum_name.to_string();
let enum_iden = format_ident!("{}", enum_name.to_camel_case());
let enum_iden = format_ident!("{}", enum_name.to_upper_camel_case());
let values: Vec<String> = self.values.iter().map(|v| v.to_string()).collect();
let variants = values.iter().map(|v| v.trim()).map(|v| {
if v.chars().next().map(char::is_numeric).unwrap_or(false) {
format_ident!("_{}", v)
} else {
format_ident!("{}", v.to_camel_case())
format_ident!("{}", v.to_upper_camel_case())
}
});

View File

@ -1,4 +1,4 @@
use heck::{CamelCase, SnakeCase};
use heck::{ToSnakeCase, ToUpperCamelCase};
use proc_macro2::{Ident, TokenStream};
use quote::format_ident;
use quote::quote;
@ -23,7 +23,7 @@ impl Entity {
}
pub fn get_table_name_camel_case(&self) -> String {
self.table_name.to_camel_case()
self.table_name.to_upper_camel_case()
}
pub fn get_table_name_snake_case_ident(&self) -> Ident {
@ -144,10 +144,10 @@ impl Entity {
.collect()
}
pub fn get_conjunct_relations_to_camel_case(&self) -> Vec<Ident> {
pub fn get_conjunct_relations_to_upper_camel_case(&self) -> Vec<Ident> {
self.conjunct_relations
.iter()
.map(|con_rel| con_rel.get_to_camel_case())
.map(|con_rel| con_rel.get_to_upper_camel_case())
.collect()
}
@ -447,15 +447,15 @@ mod tests {
}
#[test]
fn test_get_conjunct_relations_to_camel_case() {
fn test_get_conjunct_relations_to_upper_camel_case() {
let entity = setup();
for (i, elem) in entity
.get_conjunct_relations_to_camel_case()
.get_conjunct_relations_to_upper_camel_case()
.into_iter()
.enumerate()
{
assert_eq!(elem, entity.conjunct_relations[i].get_to_camel_case());
assert_eq!(elem, entity.conjunct_relations[i].get_to_upper_camel_case());
}
}

View File

@ -1,5 +1,5 @@
use crate::{util::escape_rust_keyword, DateTimeCrate};
use heck::{CamelCase, SnakeCase};
use heck::{ToSnakeCase, ToUpperCamelCase};
use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote};
use sea_query::{BlobSize, ColumnDef, ColumnSpec, ColumnType};
@ -20,7 +20,7 @@ impl Column {
}
pub fn get_name_camel_case(&self) -> Ident {
format_ident!("{}", escape_rust_keyword(self.name.to_camel_case()))
format_ident!("{}", escape_rust_keyword(self.name.to_upper_camel_case()))
}
pub fn is_snake_case_name(&self) -> bool {
@ -71,7 +71,7 @@ impl Column {
ColumnType::Uuid => "Uuid".to_owned(),
ColumnType::Binary(_) | ColumnType::VarBinary(_) => "Vec<u8>".to_owned(),
ColumnType::Boolean => "bool".to_owned(),
ColumnType::Enum { name, .. } => name.to_string().to_camel_case(),
ColumnType::Enum { name, .. } => name.to_string().to_upper_camel_case(),
ColumnType::Array(column_type) => {
format!("Vec<{}>", write_rs_type(column_type, date_time_crate))
}
@ -173,7 +173,7 @@ impl Column {
quote! { ColumnType::custom(#s) }
}
ColumnType::Enum { name, .. } => {
let enum_ident = format_ident!("{}", name.to_string().to_camel_case());
let enum_ident = format_ident!("{}", name.to_string().to_upper_camel_case());
quote! { #enum_ident::db_type() }
}
ColumnType::Array(column_type) => {

View File

@ -1,4 +1,4 @@
use heck::{CamelCase, SnakeCase};
use heck::{ToSnakeCase, ToUpperCamelCase};
use proc_macro2::Ident;
use quote::format_ident;
@ -19,8 +19,8 @@ impl ConjunctRelation {
format_ident!("{}", escape_rust_keyword(self.to.to_snake_case()))
}
pub fn get_to_camel_case(&self) -> Ident {
format_ident!("{}", self.to.to_camel_case())
pub fn get_to_upper_camel_case(&self) -> Ident {
format_ident!("{}", self.to.to_upper_camel_case())
}
}
@ -60,11 +60,11 @@ mod tests {
}
#[test]
fn test_get_to_camel_case() {
fn test_get_to_upper_camel_case() {
let conjunct_relations = setup();
let to_vec = vec!["Cake", "Filling"];
for (con_rel, to) in conjunct_relations.into_iter().zip(to_vec) {
assert_eq!(con_rel.get_to_camel_case(), to);
assert_eq!(con_rel.get_to_upper_camel_case(), to);
}
}
}

View File

@ -1,4 +1,4 @@
use heck::{CamelCase, SnakeCase};
use heck::{ToSnakeCase, ToUpperCamelCase};
use proc_macro2::Ident;
use quote::format_ident;
@ -13,7 +13,7 @@ impl PrimaryKey {
}
pub fn get_name_camel_case(&self) -> Ident {
format_ident!("{}", self.name.to_camel_case())
format_ident!("{}", self.name.to_upper_camel_case())
}
}

View File

@ -1,5 +1,5 @@
use crate::util::unpack_table_ref;
use heck::{CamelCase, SnakeCase};
use heck::{ToSnakeCase, ToUpperCamelCase};
use proc_macro2::{Ident, TokenStream};
use quote::{format_ident, quote};
use sea_query::{ForeignKeyAction, TableForeignKey};
@ -31,7 +31,7 @@ impl Relation {
let name = if self.self_referencing {
format_ident!("SelfRef")
} else {
format_ident!("{}", self.ref_table.to_camel_case())
format_ident!("{}", self.ref_table.to_upper_camel_case())
};
if self.num_suffix > 0 {
format_ident!("{}{}", name, self.num_suffix)
@ -140,11 +140,11 @@ impl Relation {
}
pub fn get_column_camel_case(&self) -> Ident {
format_ident!("{}", self.columns[0].to_camel_case())
format_ident!("{}", self.columns[0].to_upper_camel_case())
}
pub fn get_ref_column_camel_case(&self) -> Ident {
format_ident!("{}", self.ref_columns[0].to_camel_case())
format_ident!("{}", self.ref_columns[0].to_upper_camel_case())
}
pub fn get_foreign_key_action(action: &ForeignKeyAction) -> String {

View File

@ -1,5 +1,5 @@
use crate::{util::escape_rust_keyword, ActiveEnum, Entity};
use heck::CamelCase;
use heck::ToUpperCamelCase;
use proc_macro2::TokenStream;
use quote::{format_ident, quote};
use std::{collections::BTreeMap, str::FromStr};
@ -449,7 +449,7 @@ impl EntityWriter {
.iter()
.fold(TokenStream::new(), |mut ts, col| {
if let sea_query::ColumnType::Enum { name, .. } = &col.col_type {
let enum_name = format_ident!("{}", name.to_string().to_camel_case());
let enum_name = format_ident!("{}", name.to_string().to_upper_camel_case());
ts.extend([quote! {
use super::sea_orm_active_enums::#enum_name;
}]);
@ -612,16 +612,16 @@ impl EntityWriter {
let table_name_camel_case = entity.get_table_name_camel_case_ident();
let via_snake_case = entity.get_conjunct_relations_via_snake_case();
let to_snake_case = entity.get_conjunct_relations_to_snake_case();
let to_camel_case = entity.get_conjunct_relations_to_camel_case();
let to_upper_camel_case = entity.get_conjunct_relations_to_upper_camel_case();
via_snake_case
.into_iter()
.zip(to_snake_case)
.zip(to_camel_case)
.map(|((via_snake_case, to_snake_case), to_camel_case)| {
.zip(to_upper_camel_case)
.map(|((via_snake_case, to_snake_case), to_upper_camel_case)| {
quote! {
impl Related<super::#to_snake_case::Entity> for Entity {
fn to() -> RelationDef {
super::#via_snake_case::Relation::#to_camel_case.def()
super::#via_snake_case::Relation::#to_upper_camel_case.def()
}
fn via() -> Option<RelationDef> {