Merge pull request #264 from SeaQL/fix-case-transform

Unify case-transform using the same crate
This commit is contained in:
Chris Tsang 2021-10-21 19:20:05 +08:00 committed by GitHub
commit e256034756
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 71 additions and 6 deletions

View File

@ -208,22 +208,36 @@ jobs:
strategy: strategy:
matrix: matrix:
os: [ubuntu-latest] os: [ubuntu-latest]
path: [86] path: [86, 249, 262]
steps: steps:
- uses: actions/checkout@v2 - uses: actions/checkout@v2
with:
fetch-depth: 0
- uses: actions-rs/toolchain@v1 - id: git-log
run: echo "::set-output name=message::$(git log --no-merges -1 --oneline)"
- if: "contains(steps.git-log.outputs.message, '[issues]')"
uses: actions-rs/toolchain@v1
with: with:
profile: minimal profile: minimal
toolchain: stable toolchain: stable
override: true override: true
- uses: actions-rs/cargo@v1 - if: "contains(steps.git-log.outputs.message, '[issues]')"
uses: actions-rs/cargo@v1
with: with:
command: build command: build
args: > args: >
--manifest-path issues/${{ matrix.path }}/Cargo.toml --manifest-path issues/${{ matrix.path }}/Cargo.toml
- if: "contains(steps.git-log.outputs.message, '[issues]')"
uses: actions-rs/cargo@v1
with:
command: test
args: >
--manifest-path issues/${{ matrix.path }}/Cargo.toml
sqlite: sqlite:
name: SQLite name: SQLite
runs-on: ubuntu-20.04 runs-on: ubuntu-20.04

12
issues/262/Cargo.toml Normal file
View File

@ -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
issues/262/src/cake.rs Normal file
View File

@ -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");
}
}

14
issues/262/src/main.rs Normal file
View File

@ -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")
.await
.unwrap();
async_std::task::spawn(async move {
cake::Entity::find().one(&db).await.unwrap();
})
.await;
}

View File

@ -21,4 +21,3 @@ syn = { version = "^1", default-features = false, features = [ "full", "derive",
quote = "^1" quote = "^1"
heck = "^0.3" heck = "^0.3"
proc-macro2 = "^1" proc-macro2 = "^1"
convert_case = "0.4"

View File

@ -1,5 +1,5 @@
use crate::util::{escape_rust_keyword, trim_starting_raw_identifier}; 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 proc_macro2::{Ident, Span, TokenStream};
use quote::quote; use quote::quote;
use syn::{ use syn::{
@ -62,7 +62,7 @@ pub fn expand_derive_entity_model(data: Data, attrs: Vec<Attribute>) -> syn::Res
for field in fields.named { for field in fields.named {
if let Some(ident) = &field.ident { if let Some(ident) = &field.ident {
let mut field_name = Ident::new( 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(), Span::call_site(),
); );