Skip to content

Commit

Permalink
Merge pull request #109 from blackbeam/release-0.31.0
Browse files Browse the repository at this point in the history
Release 0.31.0
  • Loading branch information
blackbeam authored Oct 13, 2023
2 parents 4f9e378 + af6ef1b commit 112dba5
Show file tree
Hide file tree
Showing 36 changed files with 593 additions and 416 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,10 @@ jobs:
run: cargo fmt -- --check
- name: Features subsets
run: |
ruby -e "fs=['bigdecimal02', 'bigdecimal', 'bigdecimal04', 'chrono', 'rust_decimal', 'time02', 'time', 'frunk', 'derive', 'binlog']; \
ruby -e "fs=['bigdecimal02', 'bigdecimal03', 'bigdecimal', 'chrono', 'rust_decimal', 'time02', 'time', 'frunk', 'derive', 'binlog']; \
(1..fs.length).each do |n| puts fs.combination(n).to_a.map {|x| x.join(\" \")}.join(\"\n\"); end" \
| while read -r line; do \
echo "$line" && cargo check --quiet --tests --no-default-features --features "flate2/zlib test $line"; \
rm -rf target/debug/incremental; \
echo "$line" && cargo check --quiet --tests --no-default-features --features "flate2/zlib test $line" --profile features-subsets; \
done
- name: Build
run: cargo build
Expand Down
18 changes: 12 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ keywords = ["mysql", "database"]
categories = ["database"]

# * Invoke `cargo readme > README.md` if relevant!
version = "0.30.6"
version = "0.31.0"

edition = "2018"
exclude = [
Expand All @@ -34,10 +34,10 @@ base64 = "0.21"
bigdecimal02 = { package = "bigdecimal", version = "0.2", features = [
"serde",
], optional = true }
bigdecimal = { version = "0.3", optional = true }
bigdecimal04 = { package = "bigdecimal", version = "0.4", optional = true }
bigdecimal03 = { package = "bigdecimal", version = "0.3", optional = true }
bigdecimal = { version = "0.4", optional = true }
bitflags = "2.3"
bitvec = "1.0"
bitvec = { version = "1.0", optional = true }
byteorder = "1"
bytes = "1.0"
chrono = { version = "0.4.20", default-features = false, features = [
Expand Down Expand Up @@ -84,6 +84,12 @@ subprocess = "0.2"
[profile.bench]
debug = true

[profile.features-subsets]
inherits = "test"
debug = false
strip = "debuginfo"
incremental = false

[features]
default = [
"flate2/zlib",
Expand All @@ -96,7 +102,7 @@ default = [
]
test = ["derive"]
derive = ["mysql-common-derive"]
binlog = []
binlog = ["bitvec"]
nightly = ["test"]

[package.metadata.docs.rs]
Expand All @@ -109,7 +115,7 @@ features = [
"rust_decimal",
"chrono",
"bigdecimal02",
"bigdecimal04",
"bigdecimal03",
"bigdecimal",
"derive",
"binlog",
Expand Down
13 changes: 8 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ column and protocol type correspondence:
| [`decimal::Decimal`] | MySql int, uint or bytes parsed using `Decimal::from_str`.<br>⚠️ Note that this type doesn't support full range of MySql `DECIMAL` type. |
| [`bigdecimal::BigDecimal`] (v0.2.x) | MySql int, uint, floats or bytes parsed using `BigDecimal::parse_bytes`.<br>⚠️ Note that range of this type is greater than supported by MySql `DECIMAL` type but it'll be serialized anyway. |
| [`bigdecimal::BigDecimal`] (v0.3.x) | MySql int, uint, floats or bytes parsed using `BigDecimal::parse_bytes`.<br>⚠️ Note that range of this type is greater than supported by MySql `DECIMAL` type but it'll be serialized anyway. |
| [`bigdecimal::BigDecimal`] (v0.4.x) | MySql int, uint, floats or bytes parsed using `BigDecimal::parse_bytes`.<br>⚠️ Note that range of this type is greater than supported by MySql `DECIMAL` type but it'll be serialized anyway. |
| `num_bigint::{BigInt, BigUint}` | MySql int, uint or bytes parsed using `_::parse_bytes`.<br>⚠️ Note that range of this type is greater than supported by MySql integer types but it'll be serialized anyway (as decimal bytes string). |

Also crate provides from-row convertion for the following list of types (see `FromRow` trait):
Expand All @@ -63,20 +64,22 @@ Also crate provides from-row convertion for the following list of types (see `Fr
| `Row` | Trivial conversion for `Row` itself. |
| `T: FromValue` | For rows with a single column. |
| `(T1: FromValue [, ..., T12: FromValue])` | Row to a tuple of arity 1-12. |
| [`frunk::Hlist!`] types | Usefull to overcome tuple arity limitation |
| [`frunk::hlist::HList`] types | Usefull to overcome tuple arity limitation |

### Crate features

| Feature | Description | Default |
| -------------- | ---------------------------------------------------- | ------- |
| `bigdecimal02` | Enables `bigdecimal` v0.2.x types support | 🔴 |
| `bigdecimal` | Enables `bigdecimal` v0.3.x types support | 🟢 |
| `bigdecimal03` | Enables `bigdecimal` v0.3.x types support | 🔴 |
| `bigdecimal` | Enables `bigdecimal` v0.4.x types support | 🟢 |
| `chrono` | Enables `chrono` types support | 🔴 |
| `rust_decimal` | Enables `rust_decimal` types support | 🟢 |
| `time02` | Enables `time` v0.2.x types support | 🔴 |
| `time` | Enables `time` v0.3.x types support | 🟢 |
| `frunk` | Enables `FromRow` for `frunk::Hlist!` types | 🟢 |
| `derive` | Enables [`FromValue` and `FromRow` derive macros][2] | 🟢 |
| `binlog` | Binlog-related functionality | 🟢 |

## Derive Macros

Expand All @@ -92,7 +95,7 @@ Supported derivations:

##### Container attributes:

* `#[mysql(crate_name = "some_name")]` – overrides an attemt to guess a crate that provides
* `#[mysql(crate_name = "some_name")]` – overrides an attempt to guess a crate that provides
required traits
* `#[mysql(rename_all = ...)]` – rename all the variants according to the given case
convention. The possible values are "lowercase", "UPPERCASE", "PascalCase", "camelCase",
Expand Down Expand Up @@ -139,7 +142,7 @@ Also note, that to support `FromRow` the wrapped value must satisfy `Into<Value>

##### Container attributes:

* `#[mysql(crate_name = "some_name")]` – overrides an attemt to guess a crate to import types from
* `#[mysql(crate_name = "some_name")]` – overrides an attempt to guess a crate to import types from
* `#[mysql(bound = "Foo: Bar, Baz: Quux")]` – use the following additional bounds
* `#[mysql(deserialize_with = "some::path")]` – use the following function to deserialize
the wrapped value. Expected signature is `fn (Value) -> Result<Wrapped, FromValueError>`.
Expand Down Expand Up @@ -227,7 +230,7 @@ Supported derivations:

#### Container attributes:

* `#[mysql(crate_name = "some_name")]` – overrides an attemt to guess a crate that provides
* `#[mysql(crate_name = "some_name")]` – overrides an attempt to guess a crate that provides
required traits
* `#[mysql(rename_all = ...)]` – rename all column names according to the given case
convention. The possible values are "lowercase", "UPPERCASE", "PascalCase", "camelCase",
Expand Down
18 changes: 9 additions & 9 deletions derive/src/from_row/structs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ impl ToTokens for GenericStruct<'_> {
Crate::Found(ref name) => syn::Ident::new(name, Span::call_site()),
};

let impl_generics = (generics.params.len() > 0).then(|| {
let impl_generics = (!generics.params.is_empty()).then(|| {
let generics = self.generics.params.iter();
quote::quote!(< #(#generics,)* >)
});

let ident_generics = (generics.params.len() > 0).then(|| {
let ident_generics = (!generics.params.is_empty()).then(|| {
let generics = self.generics.params.iter().map(|g| match g {
syn::GenericParam::Type(x) => {
let ident = &x.ident;
Expand All @@ -92,14 +92,14 @@ impl ToTokens for GenericStruct<'_> {
});

let table_name_constant = item_attrs.table_name.as_ref().map(|name| {
let lit = syn::LitStr::new(&*name, name.span());
let lit = syn::LitStr::new(name, name.span());
quote::quote!(const TABLE_NAME: &'static str = #lit;)
});

let fields_attrs = fields
.named
.iter()
.map(|f| <attrs::field::Mysql as FromAttributes>::from_attributes(&*f.attrs))
.map(|f| <attrs::field::Mysql as FromAttributes>::from_attributes(&f.attrs))
.collect::<Result<Vec<_>, _>>()
.map_err(|e: darling::Error| abort!(crate::Error::from(e)))
.unwrap();
Expand Down Expand Up @@ -131,7 +131,7 @@ impl ToTokens for GenericStruct<'_> {

let filed_name_constant = fields.named.iter().zip(&fields_names).map(|(f, name)| {
let ident = f.ident.as_ref().unwrap().unraw();
let lit = syn::LitStr::new(&*name, f.span());
let lit = syn::LitStr::new(name, f.span());
let const_name = syn::Ident::new(
&format!("{}_FIELD", heck::AsShoutySnakeCase(ident.to_string())),
f.span(),
Expand All @@ -148,16 +148,16 @@ impl ToTokens for GenericStruct<'_> {
.enumerate()
.map(|(i, ((f, attrs), name))| {
let ident = f.ident.as_ref().unwrap();
let ref ty = f.ty;
let lit = syn::LitStr::new(&name, ident.span());
let ty = &f.ty;
let lit = syn::LitStr::new(name, ident.span());

let place = field_ident
.iter()
.zip(&fields_attrs)
.zip(&fields_names)
.take(i)
.map(|((f, attrs), name)| {
let lit = syn::LitStr::new(&name, f.span());
let lit = syn::LitStr::new(name, f.span());
if attrs.json {
quote::quote!(
row.place(*indexes.get(#lit).unwrap(), #f.rollback())
Expand Down Expand Up @@ -206,7 +206,7 @@ impl ToTokens for GenericStruct<'_> {
.zip(&fields_attrs)
.map(|(f, attrs)| {
let ident = f.ident.as_ref().unwrap();
let ref ty = f.ty;
let ty = &f.ty;
if attrs.json {
quote::quote!(#ident: #ident.commit().0)
} else {
Expand Down
28 changes: 14 additions & 14 deletions derive/src/from_value/enums/attrs/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@ pub enum EnumRepr {
}

impl EnumRepr {
const I8_IDENT: &str = "i8";
const U8_IDENT: &str = "u8";
const I16_IDENT: &str = "i16";
const U16_IDENT: &str = "u16";
const I32_IDENT: &str = "i32";
const U32_IDENT: &str = "u32";
const I64_IDENT: &str = "i64";
const U64_IDENT: &str = "u64";
const I128_IDENT: &str = "i128";
const U128_IDENT: &str = "u128";
const ISIZE_IDENT: &str = "isize";
const USIZE_IDENT: &str = "usize";
const I8_IDENT: &'static str = "i8";
const U8_IDENT: &'static str = "u8";
const I16_IDENT: &'static str = "i16";
const U16_IDENT: &'static str = "u16";
const I32_IDENT: &'static str = "i32";
const U32_IDENT: &'static str = "u32";
const I64_IDENT: &'static str = "i64";
const U64_IDENT: &'static str = "u64";
const I128_IDENT: &'static str = "i128";
const U128_IDENT: &'static str = "u128";
const ISIZE_IDENT: &'static str = "isize";
const USIZE_IDENT: &'static str = "usize";

pub fn span(&self) -> Span {
match self {
Expand Down Expand Up @@ -197,13 +197,13 @@ impl Default for EnumRepr {
impl FromMeta for EnumRepr {
fn from_list(items: &[darling::ast::NestedMeta]) -> darling::Result<Self> {
Ok(items
.into_iter()
.iter()
.filter_map(|x| match x {
darling::ast::NestedMeta::Meta(syn::Meta::Path(path)) => Some(path),
_ => None,
})
.filter_map(|x| x.get_ident())
.find_map(|x| Self::from_ident(x))
.find_map(Self::from_ident)
.unwrap_or_default())
}
}
43 changes: 19 additions & 24 deletions derive/src/from_value/enums/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@ pub fn impl_from_value_for_enum(
data_enum: &syn::DataEnum,
) -> crate::Result<TokenStream> {
let item_attrs = <container::Mysql as FromAttributes>::from_attributes(attrs).expect("foo");
let meta = attrs.into_iter().map(|attr| &attr.meta).collect::<Vec<_>>();
let meta = attrs.iter().map(|attr| &attr.meta).collect::<Vec<_>>();

let repr = meta
.iter()
.find_map(|x| match x {
syn::Meta::List(y) if y.path.is_ident("repr") => Some(x),
_ => None,
})
.find(|x| matches!(x, syn::Meta::List(y) if y.path.is_ident("repr")))
.map(|x| <container::Repr as FromMeta>::from_meta(x))
.transpose()?
.unwrap_or_default();
Expand Down Expand Up @@ -233,26 +230,24 @@ impl ToTokens for Enum {
Ok(#ir_name(#parsed_name::Parsed(#container_name::#ident, v)))
}
)
} else if discriminant < &BigInt::default() {
quote::quote!(
#crat::Value::Bytes(ref x) if x == #s => {
Ok(#ir_name(#parsed_name::Parsed(#container_name::#ident, v)))
}
#crat::Value::Int(#n) => {
Ok(#ir_name(#parsed_name::Ready(#container_name::#ident)))
}
)
} else {
if discriminant < &BigInt::default() {
quote::quote!(
#crat::Value::Bytes(ref x) if x == #s => {
Ok(#ir_name(#parsed_name::Parsed(#container_name::#ident, v)))
}
#crat::Value::Int(#n) => {
Ok(#ir_name(#parsed_name::Ready(#container_name::#ident)))
}
)
} else {
quote::quote!(
#crat::Value::Bytes(ref x) if x == #s => {
Ok(#ir_name(#parsed_name::Parsed(#container_name::#ident, v)))
}
#crat::Value::Int(#n) | #crat::Value::UInt(#n) => {
Ok(#ir_name(#parsed_name::Ready(#container_name::#ident)))
}
)
}
quote::quote!(
#crat::Value::Bytes(ref x) if x == #s => {
Ok(#ir_name(#parsed_name::Parsed(#container_name::#ident, v)))
}
#crat::Value::Int(#n) | #crat::Value::UInt(#n) => {
Ok(#ir_name(#parsed_name::Ready(#container_name::#ident)))
}
)
}
},
);
Expand Down
9 changes: 3 additions & 6 deletions derive/src/from_value/structs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,11 @@ pub fn impl_from_value_for_struct(
}
};

let meta = attrs.into_iter().map(|attr| &attr.meta).collect::<Vec<_>>();
let meta = attrs.iter().map(|attr| &attr.meta).collect::<Vec<_>>();

let item_attrs = meta
.iter()
.find_map(|x| match x {
syn::Meta::List(y) if y.path.is_ident("mysql") => Some(x),
_ => None,
})
.find(|x| matches!(x, syn::Meta::List(y) if y.path.is_ident("mysql")))
.map(|x| <attrs::container::Mysql as FromMeta>::from_meta(x))
.transpose()?
.unwrap_or_default();
Expand Down Expand Up @@ -240,7 +237,7 @@ impl ToTokens for NewType<'_> {
});

let additional_bounds = {
let additional_bounds = self.item_attrs.bound.iter().map(|x| x.0.iter()).flatten();
let additional_bounds = self.item_attrs.bound.iter().flat_map(|x| x.0.iter());
quote::quote!(#(#additional_bounds,)*)
};

Expand Down
2 changes: 1 addition & 1 deletion derive/src/warn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub fn print_warning(
writeln!(&mut buffer, " | ")?;

let content = format!("{content}");
for line in content.split("\n") {
for line in content.split('\n') {
write!(&mut buffer, " | ")?;
buffer.set_color(&white)?;
writeln!(&mut buffer, "{}", line)?;
Expand Down
2 changes: 1 addition & 1 deletion src/binlog/consts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ impl TryFrom<u64> for Gno {
type Error = InvalidGno;

fn try_from(value: u64) -> Result<Self, Self::Error> {
if value == 0 || (Self::MIN_GNO <= value && value <= Self::MAX_GNO) {
if value == 0 || (Self::MIN_GNO..Self::MAX_GNO).contains(&value) {
Ok(Self(value))
} else {
Err(InvalidGno(value))
Expand Down
4 changes: 2 additions & 2 deletions src/binlog/decimal/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl Decimal {
}

// is it negative or not
let mask = if buffer.get(0).copied().unwrap_or(0) & 0x80 == 0 {
let mask = if buffer.first().copied().unwrap_or(0) & 0x80 == 0 {
// positive, so mask should do noghing
0
} else {
Expand Down Expand Up @@ -324,7 +324,7 @@ impl FromStr for Decimal {
from = &from[1..];
}

let point_idx = from.find('.').unwrap_or_else(|| from.len());
let point_idx = from.find('.').unwrap_or(from.len());
let (mut integral, mut fractional) = from.split_at(point_idx);
fractional = fractional.get(1..).unwrap_or(fractional);

Expand Down
2 changes: 1 addition & 1 deletion src/binlog/events/anonymous_gtid_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ impl<'de> MyDeserialize<'de> for AnonymousGtidEvent {
}
}

impl<'de> MySerialize for AnonymousGtidEvent {
impl MySerialize for AnonymousGtidEvent {
fn serialize(&self, buf: &mut Vec<u8>) {
self.0.serialize(buf)
}
Expand Down
4 changes: 2 additions & 2 deletions src/binlog/events/gtid_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ impl<'de> MyDeserialize<'de> for GtidEvent {
}
}

impl<'de> MySerialize for GtidEvent {
impl MySerialize for GtidEvent {
fn serialize(&self, buf: &mut Vec<u8>) {
self.flags.serialize(&mut *buf);
self.sid.serialize(&mut *buf);
Expand Down Expand Up @@ -373,7 +373,7 @@ impl<'a> BinlogStruct<'a> for GtidEvent {
len += S(7); // original_commit_timestamp
}

len += S(crate::misc::lenenc_int_len(*self.tx_length as u64) as usize); // tx_length
len += S(crate::misc::lenenc_int_len(*self.tx_length) as usize); // tx_length
len += S(4); // immediate_server_version
if self.immediate_server_version != self.original_server_version {
len += S(4); // original_server_version
Expand Down
Loading

0 comments on commit 112dba5

Please sign in to comment.