Skip to content

sync upstream v0.19.7 #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 76 commits into
base: madsim
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
b46ea89
Add hostaddr support
trungda Aug 26, 2022
faedb49
Merge branch 'master' into tdinh/hostaddr
trungda Aug 27, 2022
3c9315e
IpAddr + try hostaddr first
trungda Aug 27, 2022
e30bff6
also update postgres
trungda Aug 27, 2022
6c49a45
fmt
trungda Aug 27, 2022
42fef24
explicitly handle host being None
trungda Aug 28, 2022
9b34d74
add negative test
trungda Aug 28, 2022
8ac10ff
move test to runtime
trungda Aug 31, 2022
0550bab
Merge branch 'sfackler:master' into tdinh/hostaddr
trungda Dec 27, 2022
3697f6b
Add hostaddr support
trungda Aug 26, 2022
48874dc
IpAddr + try hostaddr first
trungda Aug 27, 2022
d97bed6
also update postgres
trungda Aug 27, 2022
1a9c1d4
fmt
trungda Aug 27, 2022
58149da
explicitly handle host being None
trungda Aug 28, 2022
7a648ad
add negative test
trungda Aug 28, 2022
a70a7c3
move test to runtime
trungda Aug 31, 2022
b0596f7
Merge branch 'tdinh/hostaddr' of github.com:trungda/rust-postgres int…
trungda Dec 27, 2022
071dfa3
added a rename_all container attribute for enums and structs
JaydenElliott Mar 26, 2023
bc8ad8a
Distinguish between field and container attributes when parsing
JaydenElliott Mar 27, 2023
d509b3b
Replaced case conversion with heck
JaydenElliott Mar 27, 2023
f4b181a
Rename_all attribute documentation
JaydenElliott Mar 28, 2023
b19fdd4
Fix postgres-protocol constraint
sfackler Mar 30, 2023
45d51d7
OpenBSD misses some TCP keepalive options
niklasha Apr 4, 2023
e59a165
rustfmt
niklasha Apr 4, 2023
7dd6813
Merge pull request #1014 from niklasha/openbsd-missing-tcp-keepalive-…
sfackler Apr 4, 2023
a67fe64
refactor(types): simplify `<&str as ToSql>::to_sql`
BastiDood Apr 7, 2023
98abdf9
refactor(types): prefer `matches!` macro for readability
BastiDood Apr 7, 2023
8b9b5d0
Merge pull request #1018 from BastiDood/str-to-sql-refactor
sfackler Apr 7, 2023
e71335e
fix serialization of oidvector
sfackler May 1, 2023
8449e4d
Merge pull request #1027 from sfackler/oidvector
sfackler May 1, 2023
d92b3b0
Fix int2vector serialization
sfackler May 1, 2023
23d2524
Merge pull request #1028 from sfackler/int2vector
sfackler May 1, 2023
80adf04
allow `BorrowToSql` for non-static `Box<dyn ToSql>`
laptou May 7, 2023
066b466
Update ci.yml
sfackler May 7, 2023
22469d6
Merge pull request #1029 from laptou/master
sfackler May 7, 2023
4095490
Update criterion requirement from 0.4 to 0.5
dependabot[bot] May 24, 2023
762f67f
Merge pull request #1037 from sfackler/dependabot/cargo/criterion-0.5
sfackler May 24, 2023
64bf779
feat: add support for wasm
zebp Jun 3, 2023
2230e88
add CI job for checking wasm
zebp Jun 3, 2023
edc7fde
gate wasm support behind feature flag
zebp Jun 4, 2023
1f8fb7a
ignore dev deps in wasm ci
zebp Jun 8, 2023
635bac4
specify js feature for wasm ci
zebp Jun 9, 2023
852869d
Merge pull request #1040 from zebp/feat/wasm-support
sfackler Jun 10, 2023
6f19bb9
clean up wasm32 test
sfackler Jun 10, 2023
790af54
Merge pull request #1008 from JaydenElliott/feature/rename_all_attr
sfackler Jun 10, 2023
258fe68
feat(derive): add `#[postgres(allow_mismatch)]`
viniciusth Apr 30, 2023
4f41157
Merge pull request #945 from trungda/tdinh/hostaddr
sfackler Jul 17, 2023
b09e9cc
Add to_sql for bytes Cow as well
andrewbaxter Jul 20, 2023
34c8dc9
Fixes
Jul 20, 2023
d16a9cd
Merge pull request #1051 from andrewbaxter/patch-1
sfackler Jul 20, 2023
f7a2644
align hostaddr tls behavior with documentation
sfackler Jul 23, 2023
b575745
fix test
sfackler Jul 23, 2023
3346858
Implement load balancing
sfackler Jul 23, 2023
babc856
clippy
sfackler Jul 23, 2023
84aed63
fix wasm build
sfackler Jul 23, 2023
d451465
Merge pull request #1052 from sfackler/load-balance
sfackler Jul 23, 2023
e7eb24a
Merge pull request #1026 from viniciusth/feature/allow-mismatch
sfackler Jul 23, 2023
98814b8
Set user to executing processes' user by default.
ISibboI Aug 19, 2023
4c4059a
Propagate changes from `tokio-postgres` to `postgres`.
ISibboI Aug 19, 2023
7a5b19a
Update Rust version in CI to 1.67.0.
ISibboI Aug 19, 2023
f777f74
Merge pull request #1059 from ISibboI/master
sfackler Aug 19, 2023
a454378
Restore back compat
sfackler Aug 19, 2023
496f46c
Release postgres-protocol v0.6.6
sfackler Aug 20, 2023
43e1569
Release postgres-derive v0.4.5
sfackler Aug 20, 2023
6f7ab44
Release postgres-types v0.2.6
sfackler Aug 20, 2023
3d0a593
Release tokio-postgres v0.7.9
sfackler Aug 20, 2023
e08a38f
sync postgres config up with tokio-postgres
sfackler Aug 20, 2023
f45527f
remove bogus docs
sfackler Aug 20, 2023
75cc986
Release postgres v0.19.6
sfackler Aug 20, 2023
cb609be
Defer username default
sfackler Aug 25, 2023
b411e5c
clippy
sfackler Aug 25, 2023
016e9a3
avoid a silly clone
sfackler Aug 25, 2023
234e20b
bump ci version
sfackler Aug 25, 2023
c50fcbd
Release tokio-postgres v0.7.10
sfackler Aug 25, 2023
c5ff8cf
Release postgres v0.19.7
sfackler Aug 25, 2023
f989f42
Merge branch 'master' into madsim
xxchan Sep 9, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 29 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- uses: actions/checkout@v3
- uses: sfackler/actions/rustup@master
- uses: sfackler/actions/rustfmt@master

clippy:
name: clippy
runs-on: ubuntu-latest
Expand All @@ -47,6 +47,33 @@ jobs:
key: clippy-target-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}y
- run: cargo clippy --all --all-targets

check-wasm32:
name: check-wasm32
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: sfackler/actions/rustup@master
- run: echo "version=$(rustc --version)" >> $GITHUB_OUTPUT
id: rust-version
- run: rustup target add wasm32-unknown-unknown
- uses: actions/cache@v3
with:
path: ~/.cargo/registry/index
key: index-${{ runner.os }}-${{ github.run_number }}
restore-keys: |
index-${{ runner.os }}-
- run: cargo generate-lockfile
- uses: actions/cache@v3
with:
path: ~/.cargo/registry/cache
key: registry-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}
- run: cargo fetch
- uses: actions/cache@v3
with:
path: target
key: check-wasm32-target-${{ runner.os }}-${{ steps.rust-version.outputs.version }}-${{ hashFiles('Cargo.lock') }}
- run: cargo check --target wasm32-unknown-unknown --manifest-path tokio-postgres/Cargo.toml --no-default-features --features js

test:
name: test
runs-on: ubuntu-latest
Expand All @@ -55,7 +82,7 @@ jobs:
- run: docker compose up -d
- uses: sfackler/actions/rustup@master
with:
version: 1.64.0
version: 1.70.0
- run: echo "version=$(rustc --version)" >> $GITHUB_OUTPUT
id: rust-version
- uses: actions/cache@v3
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ members = [
"postgres-types",
"tokio-postgres",
]
resolver = "2"

[profile.release]
debug = 2
31 changes: 31 additions & 0 deletions postgres-derive-test/src/compile-fail/invalid-allow-mismatch.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use postgres_types::{FromSql, ToSql};

#[derive(ToSql, Debug)]
#[postgres(allow_mismatch)]
struct ToSqlAllowMismatchStruct {
a: i32,
}

#[derive(FromSql, Debug)]
#[postgres(allow_mismatch)]
struct FromSqlAllowMismatchStruct {
a: i32,
}

#[derive(ToSql, Debug)]
#[postgres(allow_mismatch)]
struct ToSqlAllowMismatchTupleStruct(i32, i32);

#[derive(FromSql, Debug)]
#[postgres(allow_mismatch)]
struct FromSqlAllowMismatchTupleStruct(i32, i32);

#[derive(FromSql, Debug)]
#[postgres(transparent, allow_mismatch)]
struct TransparentFromSqlAllowMismatchStruct(i32);

#[derive(FromSql, Debug)]
#[postgres(allow_mismatch, transparent)]
struct AllowMismatchFromSqlTransparentStruct(i32);

fn main() {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
error: #[postgres(allow_mismatch)] may only be applied to enums
--> src/compile-fail/invalid-allow-mismatch.rs:4:1
|
4 | / #[postgres(allow_mismatch)]
5 | | struct ToSqlAllowMismatchStruct {
6 | | a: i32,
7 | | }
| |_^

error: #[postgres(allow_mismatch)] may only be applied to enums
--> src/compile-fail/invalid-allow-mismatch.rs:10:1
|
10 | / #[postgres(allow_mismatch)]
11 | | struct FromSqlAllowMismatchStruct {
12 | | a: i32,
13 | | }
| |_^

error: #[postgres(allow_mismatch)] may only be applied to enums
--> src/compile-fail/invalid-allow-mismatch.rs:16:1
|
16 | / #[postgres(allow_mismatch)]
17 | | struct ToSqlAllowMismatchTupleStruct(i32, i32);
| |_______________________________________________^

error: #[postgres(allow_mismatch)] may only be applied to enums
--> src/compile-fail/invalid-allow-mismatch.rs:20:1
|
20 | / #[postgres(allow_mismatch)]
21 | | struct FromSqlAllowMismatchTupleStruct(i32, i32);
| |_________________________________________________^

error: #[postgres(transparent)] is not allowed with #[postgres(allow_mismatch)]
--> src/compile-fail/invalid-allow-mismatch.rs:24:25
|
24 | #[postgres(transparent, allow_mismatch)]
| ^^^^^^^^^^^^^^

error: #[postgres(allow_mismatch)] is not allowed with #[postgres(transparent)]
--> src/compile-fail/invalid-allow-mismatch.rs:28:28
|
28 | #[postgres(allow_mismatch, transparent)]
| ^^^^^^^^^^^
43 changes: 43 additions & 0 deletions postgres-derive-test/src/composites.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,49 @@ fn name_overrides() {
);
}

#[test]
fn rename_all_overrides() {
#[derive(FromSql, ToSql, Debug, PartialEq)]
#[postgres(name = "inventory_item", rename_all = "SCREAMING_SNAKE_CASE")]
struct InventoryItem {
name: String,
supplier_id: i32,
#[postgres(name = "Price")]
price: Option<f64>,
}

let mut conn = Client::connect("user=postgres host=localhost port=5433", NoTls).unwrap();
conn.batch_execute(
"CREATE TYPE pg_temp.inventory_item AS (
\"NAME\" TEXT,
\"SUPPLIER_ID\" INT,
\"Price\" DOUBLE PRECISION
);",
)
.unwrap();

let item = InventoryItem {
name: "foobar".to_owned(),
supplier_id: 100,
price: Some(15.50),
};

let item_null = InventoryItem {
name: "foobar".to_owned(),
supplier_id: 100,
price: None,
};

test_type(
&mut conn,
"inventory_item",
&[
(item, "ROW('foobar', 100, 15.50)"),
(item_null, "ROW('foobar', 100, NULL)"),
],
);
}

#[test]
fn wrong_name() {
#[derive(FromSql, ToSql, Debug, PartialEq)]
Expand Down
101 changes: 100 additions & 1 deletion postgres-derive-test/src/enums.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::test_type;
use postgres::{Client, NoTls};
use postgres::{error::DbError, Client, NoTls};
use postgres_types::{FromSql, ToSql, WrongType};
use std::error::Error;

Expand Down Expand Up @@ -53,6 +53,35 @@ fn name_overrides() {
);
}

#[test]
fn rename_all_overrides() {
#[derive(Debug, ToSql, FromSql, PartialEq)]
#[postgres(name = "mood", rename_all = "snake_case")]
enum Mood {
VerySad,
#[postgres(name = "okay")]
Ok,
VeryHappy,
}

let mut conn = Client::connect("user=postgres host=localhost port=5433", NoTls).unwrap();
conn.execute(
"CREATE TYPE pg_temp.mood AS ENUM ('very_sad', 'okay', 'very_happy')",
&[],
)
.unwrap();

test_type(
&mut conn,
"mood",
&[
(Mood::VerySad, "'very_sad'"),
(Mood::Ok, "'okay'"),
(Mood::VeryHappy, "'very_happy'"),
],
);
}

#[test]
fn wrong_name() {
#[derive(Debug, ToSql, FromSql, PartialEq)]
Expand Down Expand Up @@ -102,3 +131,73 @@ fn missing_variant() {
let err = conn.execute("SELECT $1::foo", &[&Foo::Bar]).unwrap_err();
assert!(err.source().unwrap().is::<WrongType>());
}

#[test]
fn allow_mismatch_enums() {
#[derive(Debug, ToSql, FromSql, PartialEq)]
#[postgres(allow_mismatch)]
enum Foo {
Bar,
}

let mut conn = Client::connect("user=postgres host=localhost port=5433", NoTls).unwrap();
conn.execute("CREATE TYPE pg_temp.\"Foo\" AS ENUM ('Bar', 'Baz')", &[])
.unwrap();

let row = conn.query_one("SELECT $1::\"Foo\"", &[&Foo::Bar]).unwrap();
assert_eq!(row.get::<_, Foo>(0), Foo::Bar);
}

#[test]
fn missing_enum_variant() {
#[derive(Debug, ToSql, FromSql, PartialEq)]
#[postgres(allow_mismatch)]
enum Foo {
Bar,
Buz,
}

let mut conn = Client::connect("user=postgres host=localhost port=5433", NoTls).unwrap();
conn.execute("CREATE TYPE pg_temp.\"Foo\" AS ENUM ('Bar', 'Baz')", &[])
.unwrap();

let err = conn
.query_one("SELECT $1::\"Foo\"", &[&Foo::Buz])
.unwrap_err();
assert!(err.source().unwrap().is::<DbError>());
}

#[test]
fn allow_mismatch_and_renaming() {
#[derive(Debug, ToSql, FromSql, PartialEq)]
#[postgres(name = "foo", allow_mismatch)]
enum Foo {
#[postgres(name = "bar")]
Bar,
#[postgres(name = "buz")]
Buz,
}

let mut conn = Client::connect("user=postgres host=localhost port=5433", NoTls).unwrap();
conn.execute("CREATE TYPE pg_temp.foo AS ENUM ('bar', 'baz', 'buz')", &[])
.unwrap();

let row = conn.query_one("SELECT $1::foo", &[&Foo::Buz]).unwrap();
assert_eq!(row.get::<_, Foo>(0), Foo::Buz);
}

#[test]
fn wrong_name_and_allow_mismatch() {
#[derive(Debug, ToSql, FromSql, PartialEq)]
#[postgres(allow_mismatch)]
enum Foo {
Bar,
}

let mut conn = Client::connect("user=postgres host=localhost port=5433", NoTls).unwrap();
conn.execute("CREATE TYPE pg_temp.foo AS ENUM ('Bar', 'Baz')", &[])
.unwrap();

let err = conn.query_one("SELECT $1::foo", &[&Foo::Bar]).unwrap_err();
assert!(err.source().unwrap().is::<WrongType>());
}
7 changes: 7 additions & 0 deletions postgres-derive/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Change Log

## v0.4.5 - 2023-08-19

### Added

* Added a `rename_all` option for enum and struct derives.
* Added an `allow_mismatch` option to disable strict enum variant checks against the Postgres type.

## v0.4.4 - 2023-03-27

### Changed
Expand Down
3 changes: 2 additions & 1 deletion postgres-derive/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "postgres-derive"
version = "0.4.4"
version = "0.4.5"
authors = ["Steven Fackler <[email protected]>"]
license = "MIT/Apache-2.0"
edition = "2018"
Expand All @@ -15,3 +15,4 @@ test = false
syn = "2.0"
proc-macro2 = "1.0"
quote = "1.0"
heck = "0.4"
42 changes: 24 additions & 18 deletions postgres-derive/src/accepts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,31 +31,37 @@ pub fn domain_body(name: &str, field: &syn::Field) -> TokenStream {
}
}

pub fn enum_body(name: &str, variants: &[Variant]) -> TokenStream {
pub fn enum_body(name: &str, variants: &[Variant], allow_mismatch: bool) -> TokenStream {
let num_variants = variants.len();
let variant_names = variants.iter().map(|v| &v.name);

quote! {
if type_.name() != #name {
return false;
if allow_mismatch {
quote! {
type_.name() == #name
}
} else {
quote! {
if type_.name() != #name {
return false;
}

match *type_.kind() {
::postgres_types::Kind::Enum(ref variants) => {
if variants.len() != #num_variants {
return false;
}

variants.iter().all(|v| {
match &**v {
#(
#variant_names => true,
)*
_ => false,
match *type_.kind() {
::postgres_types::Kind::Enum(ref variants) => {
if variants.len() != #num_variants {
return false;
}
})

variants.iter().all(|v| {
match &**v {
#(
#variant_names => true,
)*
_ => false,
}
})
}
_ => false,
}
_ => false,
}
}
}
Expand Down
Loading