feat: support json in `Any` driver
Does your PR solve an issue?
Fixes: https://github.com/launchbadge/sqlx/issues/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.
@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
@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 https://github.com/launchbadge/sqlx/pull/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 (?, ?, ?, ?, ?, ?, ?)";
CI is now failing due to a conflict with main as https://github.com/launchbadge/sqlx/pull/3859 was merged yesterday.
Does #3859 supersede this?
Edit: i've had to revert one of the impls from #3859 for compatibility
Was the Cargo.toml file reformatting intentional?
Was the
Cargo.tomlfile reformatting intentional?
@iamjpotts nope! Zed formatting my apologies. I'll revert.
Reverted and showing no change! Thanks everyone for your help and patience:)
Please let me know if any other changes are needed for this pr! Thanks :)
Please let me know if any other changes are needed for this pr! Thanks :)
@josiahparry
There are now some minor code conflicts due to recent changes to simplify arguments - removal of the lifetime parameter on the Arguments trait and some related changes.
S/b easy fix, mostly lifetime parameter deletion.
Synced with main! There is one change that had to be made to the Cargo.toml. I've added a comment and hope it was clear.
If there are suggested alternative approaches I'm happy to make the change!
Please let me know if any further action is needed for this PR! Thanks :)
@iamjpotts please let me know if the changes to address Arguments changes in main look good for y'all!
@iamjpotts please let me know if the changes to address Arguments changes in main look good for y'all!
You're good from an Arguments perspective.
Though I can't speak for @abonander I did skim thru the current version of the changes and nothing jumped out at me for adding feedback on.
I did see your question about the json feature on the cli crate, but that's a @abonander question.
@abonander please let me know what other changes are needed to the PR :)
I wouldn't ping Bonander. The pr does have visibility to him.
If you need to incorporate this change right away into some project you're working on, it's possible to configure your own Cargo.toml to point to your branch on your fork instead of pointing to a version on crates.io.