Skip to content

Commit 230eeef

Browse files
committed
Merge branch 'snake-case-support' of git://github.com/shssoichiro/sqlx into shssoichiro-snake-case-support
2 parents 16229fd + 8b78680 commit 230eeef

File tree

4 files changed

+6
-0
lines changed

4 files changed

+6
-0
lines changed

Cargo.lock

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

sqlx-macros/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ async-std = { version = "1.5.0", default-features = false, optional = true }
3939
tokio = { version = "0.2.13", default-features = false, features = [ "rt-threaded" ], optional = true }
4040
dotenv = { version = "0.15.0", default-features = false }
4141
futures = { version = "0.3.4", default-features = false, features = [ "executor" ] }
42+
heck = "0.3"
4243
proc-macro2 = { version = "1.0.9", default-features = false }
4344
sqlx = { version = "0.3.4", default-features = false, path = "../sqlx-core", package = "sqlx-core" }
4445
serde_json = { version = "1.0", features = [ "raw_value" ], optional = true }

sqlx-macros/src/derives/attributes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ macro_rules! try_set {
2929
#[derive(Copy, Clone)]
3030
pub enum RenameAll {
3131
LowerCase,
32+
SnakeCase,
3233
}
3334

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

7274
_ => fail!(meta, "unexpected value for rename_all"),
7375
};

sqlx-macros/src/derives/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub(crate) use r#type::expand_derive_type;
1010
pub(crate) use row::expand_derive_from_row;
1111

1212
use self::attributes::RenameAll;
13+
use heck::SnakeCase;
1314
use std::iter::FromIterator;
1415
use syn::DeriveInput;
1516

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

0 commit comments

Comments
 (0)