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

Unify case-transform using the same crate #264

Merged
merged 4 commits into from
Oct 21, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 7 additions & 1 deletion .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
path: [86]
path: [86, 249, 262]
steps:
- uses: actions/checkout@v2

Expand All @@ -224,6 +224,12 @@ jobs:
args: >
--manifest-path issues/${{ matrix.path }}/Cargo.toml

- uses: actions-rs/cargo@v1
with:
command: test
args: >
--manifest-path issues/${{ matrix.path }}/Cargo.toml

sqlite:
name: SQLite
runs-on: ubuntu-20.04
Expand Down
12 changes: 12 additions & 0 deletions issues/262/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
[workspace]
# A separate workspace

[package]
name = "sea-orm-issues-262"
version = "0.1.0"
edition = "2018"
publish = false

[dependencies]
sea-orm = { path = "../../", features = [ "sqlx-all", "runtime-async-std-native-tls", "debug-print" ] }
async-std = { version = "^1", features = ["attributes"] }
26 changes: 26 additions & 0 deletions issues/262/src/cake.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use sea_orm::entity::prelude::*;

#[derive(Clone, Debug, PartialEq, DeriveEntityModel)]
#[sea_orm(table_name = "cake")]
pub struct Model {
#[sea_orm(primary_key)]
pub id: i32,
pub md5hash: String,
pub md5_hash: String,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
pub enum Relation {}

impl ActiveModelBehavior for ActiveModel {}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_case_transform_1() {
assert_eq!(Column::Md5hash.to_string().as_str(), "md5hash");
assert_eq!(Column::Md5Hash.to_string().as_str(), "md5_hash");
}
}
tyt2y3 marked this conversation as resolved.
Show resolved Hide resolved
14 changes: 14 additions & 0 deletions issues/262/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
mod cake;
use sea_orm::*;

#[async_std::main]
pub async fn main() {
let db = Database::connect("mysql://sea:sea@localhost/bakery")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can get away with a mock. It makes compilation much faster

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure we can

.await
.unwrap();

async_std::task::spawn(async move {
cake::Entity::find().one(&db).await.unwrap();
})
.await;
}
1 change: 0 additions & 1 deletion sea-orm-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ syn = { version = "^1", default-features = false, features = [ "full", "derive",
quote = "^1"
heck = "^0.3"
proc-macro2 = "^1"
convert_case = "0.4"
4 changes: 2 additions & 2 deletions sea-orm-macros/src/derives/entity_model.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::util::{escape_rust_keyword, trim_starting_raw_identifier};
use convert_case::{Case, Casing};
use heck::CamelCase;
use proc_macro2::{Ident, Span, TokenStream};
use quote::quote;
use syn::{
Expand Down Expand Up @@ -62,7 +62,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
for field in fields.named {
if let Some(ident) = &field.ident {
let mut field_name = Ident::new(
&trim_starting_raw_identifier(&ident).to_case(Case::Pascal),
&trim_starting_raw_identifier(&ident).to_camel_case(),
Span::call_site(),
);

Expand Down