-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: support json in Any
driver
#3998
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
base: main
Are you sure you want to change the base?
Conversation
Any
driver
Any
driverAny
driver
There was a problem hiding this 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.
@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.
The test uses the following queries: sqlx::query("create temporary table json_test (data TEXT)")
sqlx::query("insert into json_test (data) values (?)") should I'll look into spinning up my own postgres server for testing |
That's likely fixed by using 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 (?, ?, ?, ?, ?, ?, ?)"; |
This comment was marked as outdated.
This comment was marked as outdated.
Was the |
@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 :) |
There are now some minor code conflicts due to recent changes to simplify arguments - removal of the lifetime parameter on the S/b easy fix, mostly lifetime parameter deletion. |
89a3a32
to
34bf530
Compare
"runtime-tokio", | ||
"migrate", | ||
"any", | ||
"json" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@abonander this is the one change that I am somewhat concerned about being "breaking." This change is required because the sqlx-cli is pulling in the json feature even though default-features = false
is specified. This causes some weirdness in the compilation only for sqlx-cli and I cannot figure out how to resolve it.
You can see this with cargo tree -p sqlx-cli --format "{p} {f}" -i sqlx-core
. The json
and any
features are being pulled in but the json feature isn't added into the dependency tree in Cargo.toml
. This is the only way I could resolve the sqlx-cli issues.
sqlx-core v0.9.0-alpha.1 (sqlx/sqlx-core) _rt-tokio,_tls-native-tls,any,crc,default,json,migrate,native-tls,offline,serde,serde_json,sha2,sqlx-toml,tokio,tokio-stream,toml
├── sqlx v0.9.0-alpha.1 (sqlx) _rt-tokio,_sqlite,any,json,migrate,mysql,postgres,runtime-tokio,sqlite,sqlite-bundled,sqlite-deserialize,sqlite-load-extension,sqlite-unlock-notify,sqlx-mysql,sqlx-postgres,sqlx-sqlite,sqlx-toml,tls-native-tls
│ └── sqlx-cli v0.9.0-alpha.1 (sqlx/sqlx-cli) _sqlite,completions,default,mysql,native-tls,postgres,sqlite,sqlx-toml
├── sqlx-mysql v0.9.0-alpha.1 (sqlx/sqlx-mysql) any,json,migrate,serde
│ └── sqlx v0.9.0-alpha.1 (sqlx) _rt-tokio,_sqlite,any,json,migrate,mysql,postgres,runtime-tokio,sqlite,sqlite-bundled,sqlite-deserialize,sqlite-load-extension,sqlite-unlock-notify,sqlx-mysql,sqlx-postgres,sqlx-sqlite,sqlx-toml,tls-native-tls (*)
├── sqlx-postgres v0.9.0-alpha.1 (sqlx/sqlx-postgres) any,json,migrate
│ └── sqlx v0.9.0-alpha.1 (sqlx) _rt-tokio,_sqlite,any,json,migrate,mysql,postgres,runtime-tokio,sqlite,sqlite-bundled,sqlite-deserialize,sqlite-load-extension,sqlite-unlock-notify,sqlx-mysql,sqlx-postgres,sqlx-sqlite,sqlx-toml,tls-native-tls (*)
└── sqlx-sqlite v0.9.0-alpha.1 (sqlx/sqlx-sqlite) any,bundled,deserialize,json,load-extension,migrate,serde,sqlx-toml,unlock-notify
└── sqlx v0.9.0-alpha.1 (sqlx) _rt-tokio,_sqlite,any,json,migrate,mysql,postgres,runtime-tokio,sqlite,sqlite-bundled,sqlite-deserialize,sqlite-load-extension,sqlite-unlock-notify,sqlx-mysql,sqlx-postgres,sqlx-sqlite,sqlx-toml,tls-native-tls (*)
Synced with If there are suggested alternative approaches I'm happy to make the change! |
Does your PR solve an issue?
Fixes: #3997
This PR adds implementations for Decode and Encode for
Json<T>
with support forAny
.Is this a breaking change?
No, this is not a breaking change. It adds new functionality only.