Skip to content

Commit 659cf57

Browse files
committed
add support for integer types in postgres and any
1 parent edec90b commit 659cf57

File tree

13 files changed

+139
-17
lines changed

13 files changed

+139
-17
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## 0.6.35
9+
10+
- Add support for unsigned integers in the `Any` driver
11+
- Add support for unsigned integers in the `postgres` driver
12+
- Add a `max_size` method to `MySqlTypeInfo` allowing to retrieve the maximum size of the type (for example, `TINYINT(1)` has a maximum size of 1)
13+
814
## 0.6.34
915

1016
- Add support for decoding `DateTime<FixedOffset>` in the `Any` driver

Cargo.lock

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ members = [
2020

2121
[package]
2222
name = "sqlx-oldapi"
23-
version = "0.6.34"
23+
version = "0.6.35"
2424
license = "MIT OR Apache-2.0"
2525
readme = "README.md"
2626
repository = "https://github.com/lovasoa/sqlx"
@@ -125,8 +125,8 @@ bstr = ["sqlx-core/bstr"]
125125
git2 = ["sqlx-core/git2"]
126126

127127
[dependencies]
128-
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.34", path = "sqlx-core", default-features = false }
129-
sqlx-macros = { package = "sqlx-macros-oldapi", version = "0.6.34", path = "sqlx-macros", default-features = false, optional = true }
128+
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.35", path = "sqlx-core", default-features = false }
129+
sqlx-macros = { package = "sqlx-macros-oldapi", version = "0.6.35", path = "sqlx-macros", default-features = false, optional = true }
130130

131131
[dev-dependencies]
132132
anyhow = "1.0.52"

examples/postgres/axum-social-with-tests/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ edition = "2021"
88
[dependencies]
99
# Primary crates
1010
axum = { version = "0.5.13", features = ["macros"] }
11-
sqlx = { package = "sqlx-oldapi", version = "0.6.34", path = "../../../", features = ["runtime-tokio-rustls", "postgres", "time", "uuid"] }
11+
sqlx = { package = "sqlx-oldapi", version = "0.6.35", path = "../../../", features = ["runtime-tokio-rustls", "postgres", "time", "uuid"] }
1212
tokio = { version = "1.20.1", features = ["rt-multi-thread", "macros"] }
1313

1414
# Important secondary crates

sqlx-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlx-cli"
3-
version = "0.6.34"
3+
version = "0.6.35"
44
description = "Command-line utility for SQLx, the Rust SQL toolkit."
55
edition = "2021"
66
readme = "README.md"

sqlx-core/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlx-core-oldapi"
3-
version = "0.6.34"
3+
version = "0.6.35"
44
repository = "https://github.com/lovasoa/sqlx"
55
description = "Core of SQLx, the rust SQL toolkit. Not intended to be used directly."
66
license = "MIT OR Apache-2.0"
@@ -101,7 +101,7 @@ offline = ["serde", "either/serde"]
101101
paste = "1.0.6"
102102
ahash = "0.8.3"
103103
atoi = "2.0.0"
104-
sqlx-rt = { path = "../sqlx-rt", version = "0.6.34", package = "sqlx-rt-oldapi" }
104+
sqlx-rt = { path = "../sqlx-rt", version = "0.6.35", package = "sqlx-rt-oldapi" }
105105
base64 = { version = "0.22", default-features = false, optional = true, features = ["std"] }
106106
bigdecimal_ = { version = "0.4.1", optional = true, package = "bigdecimal" }
107107
rust_decimal = { version = "1.19.0", optional = true }

sqlx-core/src/any/types.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ impl_any_type!(f64);
3232
impl_any_type!(str);
3333
impl_any_type!(String);
3434

35+
impl_any_type!(u16);
36+
impl_any_type!(u32);
37+
impl_any_type!(u64);
38+
3539
// Encode
3640

3741
impl_any_encode!(bool);
@@ -46,6 +50,10 @@ impl_any_encode!(f64);
4650
impl_any_encode!(&'q str);
4751
impl_any_encode!(String);
4852

53+
impl_any_encode!(u16);
54+
impl_any_encode!(u32);
55+
impl_any_encode!(u64);
56+
4957
// Decode
5058

5159
impl_any_decode!(bool);
@@ -60,6 +68,10 @@ impl_any_decode!(f64);
6068
impl_any_decode!(&'r str);
6169
impl_any_decode!(String);
6270

71+
impl_any_decode!(u16);
72+
impl_any_decode!(u32);
73+
impl_any_decode!(u64);
74+
6375
// Conversions for Blob SQL types
6476
// Type
6577
impl_any_type!([u8]);

sqlx-core/src/mysql/type_info.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ impl MySqlTypeInfo {
5858
max_size: Some(column.max_size),
5959
}
6060
}
61+
62+
pub fn max_size(&self) -> Option<u32> {
63+
self.max_size
64+
}
6165
}
6266

6367
impl Display for MySqlTypeInfo {

sqlx-core/src/postgres/types/int.rs

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,3 +127,88 @@ impl Decode<'_, Postgres> for i64 {
127127
})
128128
}
129129
}
130+
131+
impl Type<Postgres> for u16 {
132+
fn type_info() -> PgTypeInfo {
133+
PgTypeInfo::INT4
134+
}
135+
}
136+
137+
impl PgHasArrayType for u16 {
138+
fn array_type_info() -> PgTypeInfo {
139+
PgTypeInfo::INT4_ARRAY
140+
}
141+
}
142+
143+
impl Encode<'_, Postgres> for u16 {
144+
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull {
145+
buf.extend(&i32::from(*self).to_be_bytes());
146+
IsNull::No
147+
}
148+
}
149+
150+
impl Decode<'_, Postgres> for u16 {
151+
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> {
152+
let decoded = match value.format() {
153+
PgValueFormat::Binary => BigEndian::read_i32(value.as_bytes()?),
154+
PgValueFormat::Text => value.as_str()?.parse::<i32>()?,
155+
};
156+
Ok(u16::try_from(decoded)?)
157+
}
158+
}
159+
160+
impl Type<Postgres> for u32 {
161+
fn type_info() -> PgTypeInfo {
162+
PgTypeInfo::INT8
163+
}
164+
}
165+
166+
impl PgHasArrayType for u32 {
167+
fn array_type_info() -> PgTypeInfo {
168+
PgTypeInfo::INT8_ARRAY
169+
}
170+
}
171+
172+
impl Encode<'_, Postgres> for u32 {
173+
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull {
174+
buf.extend(&i64::from(*self).to_be_bytes());
175+
IsNull::No
176+
}
177+
}
178+
179+
impl Decode<'_, Postgres> for u32 {
180+
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> {
181+
let decoded = match value.format() {
182+
PgValueFormat::Binary => BigEndian::read_i64(value.as_bytes()?),
183+
PgValueFormat::Text => value.as_str()?.parse::<i64>()?,
184+
};
185+
Ok(u32::try_from(decoded)?)
186+
}
187+
}
188+
189+
impl Type<Postgres> for u64 {
190+
fn type_info() -> PgTypeInfo {
191+
PgTypeInfo::NUMERIC
192+
}
193+
}
194+
195+
impl PgHasArrayType for u64 {
196+
fn array_type_info() -> PgTypeInfo {
197+
PgTypeInfo::NUMERIC_ARRAY
198+
}
199+
}
200+
201+
impl Encode<'_, Postgres> for u64 {
202+
fn encode_by_ref(&self, buf: &mut PgArgumentBuffer) -> IsNull {
203+
let numeric_str = self.to_string();
204+
buf.extend(numeric_str.as_bytes());
205+
IsNull::No
206+
}
207+
}
208+
209+
impl Decode<'_, Postgres> for u64 {
210+
fn decode(value: PgValueRef<'_>) -> Result<Self, BoxDynError> {
211+
let decoded = value.as_str()?.parse::<u64>()?;
212+
Ok(decoded)
213+
}
214+
}

sqlx-macros/Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "sqlx-macros-oldapi"
3-
version = "0.6.34"
3+
version = "0.6.35"
44
repository = "https://github.com/lovasoa/sqlx"
55
description = "Macros for SQLx, the rust SQL toolkit. Not intended to be used directly."
66
license = "MIT OR Apache-2.0"
@@ -75,8 +75,8 @@ heck = { version = "0.5" }
7575
either = "1.6.1"
7676
once_cell = "1.9.0"
7777
proc-macro2 = { version = "1.0.36", default-features = false }
78-
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.34", default-features = false, features = ["any"], path = "../sqlx-core" }
79-
sqlx-rt = { version = "0.6.34", default-features = false, path = "../sqlx-rt", package = "sqlx-rt-oldapi" }
78+
sqlx-core = { package = "sqlx-core-oldapi", version = "0.6.35", default-features = false, features = ["any"], path = "../sqlx-core" }
79+
sqlx-rt = { version = "0.6.35", default-features = false, path = "../sqlx-rt", package = "sqlx-rt-oldapi" }
8080
serde = { version = "1.0.132", features = ["derive"], optional = true }
8181
serde_json = { version = "1.0.73", optional = true }
8282
sha2 = { version = "0.10.0", optional = true }

0 commit comments

Comments
 (0)