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

Add snake_case rename support for Type macro #261

Merged
merged 1 commit into from
Apr 18, 2020
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
3 changes: 3 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions sqlx-macros/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async-std = { version = "1.5.0", default-features = false, optional = true }
tokio = { version = "0.2.13", default-features = false, features = [ "rt-threaded" ], optional = true }
dotenv = { version = "0.15.0", default-features = false }
futures = { version = "0.3.4", default-features = false, features = [ "executor" ] }
heck = "0.3"
proc-macro2 = { version = "1.0.9", default-features = false }
sqlx = { version = "0.3.4", default-features = false, path = "../sqlx-core", package = "sqlx-core" }
serde_json = { version = "1.0", features = [ "raw_value" ], optional = true }
Expand Down
2 changes: 2 additions & 0 deletions sqlx-macros/src/derives/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ macro_rules! try_set {
#[derive(Copy, Clone)]
pub enum RenameAll {
LowerCase,
SnakeCase,
}

pub struct SqlxContainerAttributes {
Expand Down Expand Up @@ -68,6 +69,7 @@ pub fn parse_container_attributes(input: &[Attribute]) -> syn::Result<SqlxContai
}) if path.is_ident("rename_all") => {
let val = match &*val.value() {
"lowercase" => RenameAll::LowerCase,
"snake_case" => RenameAll::SnakeCase,

_ => fail!(meta, "unexpected value for rename_all"),
};
Expand Down
2 changes: 2 additions & 0 deletions sqlx-macros/src/derives/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ pub(crate) use r#type::expand_derive_type;
pub(crate) use row::expand_derive_from_row;

use self::attributes::RenameAll;
use heck::SnakeCase;
use std::iter::FromIterator;
use syn::DeriveInput;

Expand All @@ -30,5 +31,6 @@ pub(crate) fn expand_derive_type_encode_decode(
pub(crate) fn rename_all(s: &str, pattern: RenameAll) -> String {
match pattern {
RenameAll::LowerCase => s.to_lowercase(),
RenameAll::SnakeCase => s.to_snake_case(),
}
}