Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Boxed owned query parameters#853

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sfackler merged 1 commit intorust-postgres:masterfromelpiel:boxed-dyn-ToSql
Dec 31, 2021

Conversation

elpiel
Copy link
Contributor

@elpielelpiel commentedDec 16, 2021
edited
Loading

Related issue:#843

This allows usage ofVec<Box<dyn ToSql + Sync>> &Vec<Box<dyn ToSql + Sync + Send>> to be used withClient.query_raw

use futures::TryStreamExt;fnbuild_params( ...) ->Vec<Box<(dynToSql +Sync +Send)>>{ ...}asyncfnquery_database(){let stmt = ....;let params =build_params( ...);let rows:Vec<Row> = client.query_raw(&stmt, params).await?.try_collect().await?;}

- Box<dyn ToSql + Sync>- Box<dyn ToSql + Sync + Send>
@sfackler
Copy link
Collaborator

Seems reasonable to me. Anything still need to added to this before switching it from a draft?

@elpiel
Copy link
ContributorAuthor

elpiel commentedDec 16, 2021
edited
Loading

Seems reasonable to me. Anything still need to added to this before switching it from a draft?

The onlynice to have is: Would there be an implication of the Boxed type when callingquery()?
It would be nice to be able to call thequery() method with types likeVec<Box<dyn ToSql>>

@elpielelpiel marked this pull request as ready for reviewDecember 16, 2021 12:32
@elpiel
Copy link
ContributorAuthor

elpiel commentedDec 16, 2021
edited
Loading

Here's another thing:
Would you considerimpl<T: ToSql + Send + Sync> From<T> for Box<dyn ToSql + Send + Sync> & for theBox<dyn ToSql + Sync> (not sure about this one)?

This will allow a use case in which I dynamically building the query values.
It's easy to implement for owned defined types, but not String for example.

Example use case:

struct AnalyticsQuery {pub campaign_id: Option<CampaignId>,    pub ad_unit: Option<IPFS>,    pub ad_slot: Option<IPFS>,    pub ad_slot_type: Option<String>,    pub advertiser: Option<Address>,    pub publisher: Option<Address>,    pub hostname: Option<String>,    pub country: Option<String>,    pub os_name: Option<OperatingSystem>,}}impl AnalyticsQuery {    pub fn get_key(&self, key: AllowedKey) -> Option<Box<dyn ToSql + Sync + Send>> {        match key {            AllowedKey::CampaignId => self.campaign_id.map(Into::into),            AllowedKey::AdUnit => self.ad_unit.map(Into::into),            AllowedKey::AdSlot => self.ad_slot.map(Into::into),            AllowedKey::AdSlotType => self.ad_slot_type.clone().map(Into::into),            AllowedKey::Advertiser => self.advertiser.map(Into::into),            AllowedKey::Publisher => self.publisher.map(Into::into),            AllowedKey::Hostname => self.hostname.clone().map(Into::into),            AllowedKey::Country => self.country.clone().map(Into::into),            AllowedKey::OsName => self.os_name.clone().map(Into::into),        }    }}

@elpiel
Copy link
ContributorAuthor

elpiel commentedDec 31, 2021
edited
Loading

@sfackler could you merge this PR?

PS: You can also check PR#859 which adds another impl that allows#853 (comment)

@sfacklersfackler merged commit86c914c intorust-postgres:masterDec 31, 2021
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@elpiel@sfackler

[8]ページ先頭

©2009-2025 Movatter.jp