Skip to content

Conversation

JosiahParry
Copy link

@JosiahParry JosiahParry commented Aug 25, 2025

Does your PR solve an issue?

Fixes: #3997

This PR adds implementations for Decode and Encode for Json<T> with support for Any.

Is this a breaking change?

No, this is not a breaking change. It adds new functionality only.

@JosiahParry JosiahParry marked this pull request as ready for review August 25, 2025 18:18
@abonander abonander changed the title feat: implement decode and encode for json feat: implement json for Any driver Aug 25, 2025
@abonander abonander changed the title feat: implement json for Any driver feat: support json in Any driver Aug 25, 2025
Copy link
Collaborator

@abonander abonander left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd love to land this feature, though unfortunately it's a little more complicated than it may have seemed initially.

@JosiahParry
Copy link
Author

@abonander thank you for your feedback! I've gone ahead and made your suggested changes. However, when the thorough Postgres test suite starts there appears to be a syntax error or something similar.

My knowledge of postgres is fairly limited unfortunately.

---- it_encodes_decodes_json stdout ----
Error: error returned from database: syntax error at or near ")"
Caused by:
syntax error at or near ")"

The test uses the following queries:

    sqlx::query("create temporary table json_test (data TEXT)")
    sqlx::query("insert into json_test (data) values (?)")

should (?) be replaced with ($1)? Or do you suspect something different?

I'll look into spinning up my own postgres server for testing

@JosiahParry JosiahParry requested a review from abonander August 26, 2025 01:00
@iamjpotts
Copy link
Contributor

@abonander thank you for your feedback! I've gone ahead and made your suggested changes. However, when the thorough Postgres test suite starts there appears to be a syntax error or something similar.

My knowledge of postgres is fairly limited unfortunately.

---- it_encodes_decodes_json stdout ----
Error: error returned from database: syntax error at or near ")"
Caused by:
syntax error at or near ")"

The test uses the following queries:

    sqlx::query("create temporary table json_test (data TEXT)")
    sqlx::query("insert into json_test (data) values (?)")

should (?) be replaced with ($1)? Or do you suspect something different?

I'll look into spinning up my own postgres server for testing

That's likely fixed by using $x syntax instead of ? on postgres.

Here's an example from #3960:

    #[cfg(feature = "postgres")]
    const SQL: &str =
        "SELECT 'Hello, world!' as string where 'Hello, world!' in ($1, $2, $3, $4, $5, $6, $7)";

    #[cfg(not(feature = "postgres"))]
    const SQL: &str =
        "SELECT 'Hello, world!' as string where 'Hello, world!' in (?, ?, ?, ?, ?, ?, ?)";

@JosiahParry

This comment was marked as outdated.

@iamjpotts
Copy link
Contributor

Was the Cargo.toml file reformatting intentional?

@JosiahParry
Copy link
Author

Was the Cargo.toml file reformatting intentional?

@iamjpotts nope! Zed formatting my apologies. I'll revert.

@JosiahParry
Copy link
Author

Reverted and showing no change! Thanks everyone for your help and patience:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: support Json for AnyPool
3 participants