mirror of
https://github.com/launchbadge/sqlx.git
synced 2025-11-12 19:35:25 +00:00
Rename sqlx(rename) attribute to sqlx(type_name)
This commit is contained in:
parent
74835bfe58
commit
fd8b2b7f8a
@ -17,6 +17,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
.fetch_all(&mut conn).await?;
|
.fetch_all(&mut conn).await?;
|
||||||
```
|
```
|
||||||
|
|
||||||
|
- [[#940]] Rename the `#[sqlx(rename)]` attribute used to specify the type name on the database
|
||||||
|
side to `#[sqlx(type_name)]` [[@jplatte]].
|
||||||
|
|
||||||
## 0.4.2 - 2020-12-19
|
## 0.4.2 - 2020-12-19
|
||||||
|
|
||||||
- [[#908]] Fix `whoami` crash on FreeBSD platform [[@fundon]] [[@AldaronLau]]
|
- [[#908]] Fix `whoami` crash on FreeBSD platform [[@fundon]] [[@AldaronLau]]
|
||||||
|
|||||||
@ -110,7 +110,7 @@
|
|||||||
//!
|
//!
|
||||||
//! ```rust,ignore
|
//! ```rust,ignore
|
||||||
//! #[derive(sqlx::Type)]
|
//! #[derive(sqlx::Type)]
|
||||||
//! #[sqlx(rename = "inventory_item")]
|
//! #[sqlx(type_name = "inventory_item")]
|
||||||
//! struct InventoryItem {
|
//! struct InventoryItem {
|
||||||
//! name: String,
|
//! name: String,
|
||||||
//! supplier_id: i32,
|
//! supplier_id: i32,
|
||||||
@ -135,7 +135,7 @@
|
|||||||
//!
|
//!
|
||||||
//! ```rust,ignore
|
//! ```rust,ignore
|
||||||
//! #[derive(sqlx::Type)]
|
//! #[derive(sqlx::Type)]
|
||||||
//! #[sqlx(rename = "mood", rename_all = "lowercase")]
|
//! #[sqlx(type_name = "mood", rename_all = "lowercase")]
|
||||||
//! enum Mood { Sad, Ok, Happy }
|
//! enum Mood { Sad, Ok, Happy }
|
||||||
//! ```
|
//! ```
|
||||||
//!
|
//!
|
||||||
|
|||||||
@ -128,7 +128,7 @@ pub use json::Json;
|
|||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```rust,ignore
|
||||||
/// #[derive(sqlx::Type)]
|
/// #[derive(sqlx::Type)]
|
||||||
/// #[sqlx(rename = "color")] // only for PostgreSQL to match a type definition
|
/// #[sqlx(type_name = "color")] // only for PostgreSQL to match a type definition
|
||||||
/// #[sqlx(rename_all = "lowercase")]
|
/// #[sqlx(rename_all = "lowercase")]
|
||||||
/// enum Color { Red, Green, Blue }
|
/// enum Color { Red, Green, Blue }
|
||||||
/// ```
|
/// ```
|
||||||
@ -141,7 +141,7 @@ pub use json::Json;
|
|||||||
///
|
///
|
||||||
/// ```rust,ignore
|
/// ```rust,ignore
|
||||||
/// #[derive(sqlx::Type)]
|
/// #[derive(sqlx::Type)]
|
||||||
/// #[sqlx(rename = "interface_type")]
|
/// #[sqlx(type_name = "interface_type")]
|
||||||
/// struct InterfaceType {
|
/// struct InterfaceType {
|
||||||
/// name: String,
|
/// name: String,
|
||||||
/// supplier_id: i32,
|
/// supplier_id: i32,
|
||||||
|
|||||||
@ -39,7 +39,7 @@ pub enum RenameAll {
|
|||||||
|
|
||||||
pub struct SqlxContainerAttributes {
|
pub struct SqlxContainerAttributes {
|
||||||
pub transparent: bool,
|
pub transparent: bool,
|
||||||
pub rename: Option<String>,
|
pub type_name: Option<String>,
|
||||||
pub rename_all: Option<RenameAll>,
|
pub rename_all: Option<RenameAll>,
|
||||||
pub repr: Option<Ident>,
|
pub repr: Option<Ident>,
|
||||||
}
|
}
|
||||||
@ -52,7 +52,7 @@ pub struct SqlxChildAttributes {
|
|||||||
pub fn parse_container_attributes(input: &[Attribute]) -> syn::Result<SqlxContainerAttributes> {
|
pub fn parse_container_attributes(input: &[Attribute]) -> syn::Result<SqlxContainerAttributes> {
|
||||||
let mut transparent = None;
|
let mut transparent = None;
|
||||||
let mut repr = None;
|
let mut repr = None;
|
||||||
let mut rename = None;
|
let mut type_name = None;
|
||||||
let mut rename_all = None;
|
let mut rename_all = None;
|
||||||
|
|
||||||
for attr in input
|
for attr in input
|
||||||
@ -94,7 +94,9 @@ pub fn parse_container_attributes(input: &[Attribute]) -> syn::Result<SqlxContai
|
|||||||
path,
|
path,
|
||||||
lit: Lit::Str(val),
|
lit: Lit::Str(val),
|
||||||
..
|
..
|
||||||
}) if path.is_ident("rename") => try_set!(rename, val.value(), value),
|
}) if path.is_ident("type_name") => {
|
||||||
|
try_set!(type_name, val.value(), value)
|
||||||
|
}
|
||||||
|
|
||||||
u => fail!(u, "unexpected attribute"),
|
u => fail!(u, "unexpected attribute"),
|
||||||
},
|
},
|
||||||
@ -120,7 +122,7 @@ pub fn parse_container_attributes(input: &[Attribute]) -> syn::Result<SqlxContai
|
|||||||
Ok(SqlxContainerAttributes {
|
Ok(SqlxContainerAttributes {
|
||||||
transparent: transparent.unwrap_or(false),
|
transparent: transparent.unwrap_or(false),
|
||||||
repr,
|
repr,
|
||||||
rename,
|
type_name,
|
||||||
rename_all,
|
rename_all,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@ -83,7 +83,7 @@ fn expand_derive_has_sql_type_transparent(
|
|||||||
let mut tts = proc_macro2::TokenStream::new();
|
let mut tts = proc_macro2::TokenStream::new();
|
||||||
|
|
||||||
if cfg!(feature = "postgres") {
|
if cfg!(feature = "postgres") {
|
||||||
let ty_name = attr.rename.unwrap_or_else(|| ident.to_string());
|
let ty_name = attr.type_name.unwrap_or_else(|| ident.to_string());
|
||||||
|
|
||||||
tts.extend(quote!(
|
tts.extend(quote!(
|
||||||
impl sqlx::Type< sqlx::postgres::Postgres > for #ident #ty_generics {
|
impl sqlx::Type< sqlx::postgres::Postgres > for #ident #ty_generics {
|
||||||
@ -142,7 +142,7 @@ fn expand_derive_has_sql_type_strong_enum(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if cfg!(feature = "postgres") {
|
if cfg!(feature = "postgres") {
|
||||||
let ty_name = attributes.rename.unwrap_or_else(|| ident.to_string());
|
let ty_name = attributes.type_name.unwrap_or_else(|| ident.to_string());
|
||||||
|
|
||||||
tts.extend(quote!(
|
tts.extend(quote!(
|
||||||
impl sqlx::Type< sqlx::Postgres > for #ident {
|
impl sqlx::Type< sqlx::Postgres > for #ident {
|
||||||
@ -180,7 +180,7 @@ fn expand_derive_has_sql_type_struct(
|
|||||||
let mut tts = proc_macro2::TokenStream::new();
|
let mut tts = proc_macro2::TokenStream::new();
|
||||||
|
|
||||||
if cfg!(feature = "postgres") {
|
if cfg!(feature = "postgres") {
|
||||||
let ty_name = attributes.rename.unwrap_or_else(|| ident.to_string());
|
let ty_name = attributes.type_name.unwrap_or_else(|| ident.to_string());
|
||||||
|
|
||||||
tts.extend(quote!(
|
tts.extend(quote!(
|
||||||
impl sqlx::Type< sqlx::Postgres > for #ident {
|
impl sqlx::Type< sqlx::Postgres > for #ident {
|
||||||
|
|||||||
@ -21,7 +21,7 @@ enum Weak {
|
|||||||
|
|
||||||
// "Strong" enums can map to TEXT (25)
|
// "Strong" enums can map to TEXT (25)
|
||||||
#[derive(PartialEq, Debug, sqlx::Type)]
|
#[derive(PartialEq, Debug, sqlx::Type)]
|
||||||
#[sqlx(rename = "text")]
|
#[sqlx(type_name = "text")]
|
||||||
#[sqlx(rename_all = "lowercase")]
|
#[sqlx(rename_all = "lowercase")]
|
||||||
enum Strong {
|
enum Strong {
|
||||||
One,
|
One,
|
||||||
@ -33,7 +33,7 @@ enum Strong {
|
|||||||
|
|
||||||
// rename_all variants
|
// rename_all variants
|
||||||
#[derive(PartialEq, Debug, sqlx::Type)]
|
#[derive(PartialEq, Debug, sqlx::Type)]
|
||||||
#[sqlx(rename = "color_lower")]
|
#[sqlx(type_name = "color_lower")]
|
||||||
#[sqlx(rename_all = "lowercase")]
|
#[sqlx(rename_all = "lowercase")]
|
||||||
enum ColorLower {
|
enum ColorLower {
|
||||||
Red,
|
Red,
|
||||||
@ -42,7 +42,7 @@ enum ColorLower {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, sqlx::Type)]
|
#[derive(PartialEq, Debug, sqlx::Type)]
|
||||||
#[sqlx(rename = "color_snake")]
|
#[sqlx(type_name = "color_snake")]
|
||||||
#[sqlx(rename_all = "snake_case")]
|
#[sqlx(rename_all = "snake_case")]
|
||||||
enum ColorSnake {
|
enum ColorSnake {
|
||||||
RedGreen,
|
RedGreen,
|
||||||
@ -50,7 +50,7 @@ enum ColorSnake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, sqlx::Type)]
|
#[derive(PartialEq, Debug, sqlx::Type)]
|
||||||
#[sqlx(rename = "color_upper")]
|
#[sqlx(type_name = "color_upper")]
|
||||||
#[sqlx(rename_all = "UPPERCASE")]
|
#[sqlx(rename_all = "UPPERCASE")]
|
||||||
enum ColorUpper {
|
enum ColorUpper {
|
||||||
Red,
|
Red,
|
||||||
@ -59,7 +59,7 @@ enum ColorUpper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, sqlx::Type)]
|
#[derive(PartialEq, Debug, sqlx::Type)]
|
||||||
#[sqlx(rename = "color_screaming_snake")]
|
#[sqlx(type_name = "color_screaming_snake")]
|
||||||
#[sqlx(rename_all = "SCREAMING_SNAKE_CASE")]
|
#[sqlx(rename_all = "SCREAMING_SNAKE_CASE")]
|
||||||
enum ColorScreamingSnake {
|
enum ColorScreamingSnake {
|
||||||
RedGreen,
|
RedGreen,
|
||||||
@ -67,7 +67,7 @@ enum ColorScreamingSnake {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, sqlx::Type)]
|
#[derive(PartialEq, Debug, sqlx::Type)]
|
||||||
#[sqlx(rename = "color_kebab_case")]
|
#[sqlx(type_name = "color_kebab_case")]
|
||||||
#[sqlx(rename_all = "kebab-case")]
|
#[sqlx(rename_all = "kebab-case")]
|
||||||
enum ColorKebabCase {
|
enum ColorKebabCase {
|
||||||
RedGreen,
|
RedGreen,
|
||||||
@ -75,7 +75,7 @@ enum ColorKebabCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, sqlx::Type)]
|
#[derive(PartialEq, Debug, sqlx::Type)]
|
||||||
#[sqlx(rename = "color_mixed_case")]
|
#[sqlx(type_name = "color_mixed_case")]
|
||||||
#[sqlx(rename_all = "camelCase")]
|
#[sqlx(rename_all = "camelCase")]
|
||||||
enum ColorCamelCase {
|
enum ColorCamelCase {
|
||||||
RedGreen,
|
RedGreen,
|
||||||
@ -83,7 +83,7 @@ enum ColorCamelCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq, Debug, sqlx::Type)]
|
#[derive(PartialEq, Debug, sqlx::Type)]
|
||||||
#[sqlx(rename = "color_camel_case")]
|
#[sqlx(type_name = "color_camel_case")]
|
||||||
#[sqlx(rename_all = "PascalCase")]
|
#[sqlx(rename_all = "PascalCase")]
|
||||||
enum ColorPascalCase {
|
enum ColorPascalCase {
|
||||||
RedGreen,
|
RedGreen,
|
||||||
@ -92,7 +92,7 @@ enum ColorPascalCase {
|
|||||||
|
|
||||||
// "Strong" enum can map to a custom type
|
// "Strong" enum can map to a custom type
|
||||||
#[derive(PartialEq, Debug, sqlx::Type)]
|
#[derive(PartialEq, Debug, sqlx::Type)]
|
||||||
#[sqlx(rename = "mood")]
|
#[sqlx(type_name = "mood")]
|
||||||
#[sqlx(rename_all = "lowercase")]
|
#[sqlx(rename_all = "lowercase")]
|
||||||
enum Mood {
|
enum Mood {
|
||||||
Ok,
|
Ok,
|
||||||
@ -103,7 +103,7 @@ enum Mood {
|
|||||||
// Records must map to a custom type
|
// Records must map to a custom type
|
||||||
// Note that all types are types in Postgres
|
// Note that all types are types in Postgres
|
||||||
#[derive(PartialEq, Debug, sqlx::Type)]
|
#[derive(PartialEq, Debug, sqlx::Type)]
|
||||||
#[sqlx(rename = "inventory_item")]
|
#[sqlx(type_name = "inventory_item")]
|
||||||
struct InventoryItem {
|
struct InventoryItem {
|
||||||
name: String,
|
name: String,
|
||||||
supplier_id: Option<i32>,
|
supplier_id: Option<i32>,
|
||||||
@ -112,12 +112,12 @@ struct InventoryItem {
|
|||||||
|
|
||||||
// Custom range type
|
// Custom range type
|
||||||
#[derive(sqlx::Type, Debug, PartialEq)]
|
#[derive(sqlx::Type, Debug, PartialEq)]
|
||||||
#[sqlx(rename = "float_range")]
|
#[sqlx(type_name = "float_range")]
|
||||||
struct FloatRange(PgRange<f64>);
|
struct FloatRange(PgRange<f64>);
|
||||||
|
|
||||||
// Custom domain type
|
// Custom domain type
|
||||||
#[derive(sqlx::Type, Debug)]
|
#[derive(sqlx::Type, Debug)]
|
||||||
#[sqlx(rename = "int4rangeL0pC")]
|
#[sqlx(type_name = "int4rangeL0pC")]
|
||||||
struct RangeInclusive(PgRange<i32>);
|
struct RangeInclusive(PgRange<i32>);
|
||||||
|
|
||||||
test_type!(transparent<Transparent>(Postgres,
|
test_type!(transparent<Transparent>(Postgres,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user