Skip to content

Commit

Permalink
Merge branch 'shssoichiro-snake-case-support'
Browse files Browse the repository at this point in the history
  • Loading branch information
mehcode committed Apr 18, 2020
2 parents 16229fd + 230eeef commit 145218f
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 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
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
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
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(),
}
}

0 comments on commit 145218f

Please sign in to comment.