Skip to content
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

Is there UUID support? #10

Open
onx2 opened this issue Jul 16, 2021 · 3 comments
Open

Is there UUID support? #10

onx2 opened this issue Jul 16, 2021 · 3 comments

Comments

@onx2
Copy link

onx2 commented Jul 16, 2021

Is there now (or in the future) UUID support or should I just convert to a string?

pub async fn find_by_id(ctx: &Context<'_>, id: Uuid) -> Result<Option<Organization>> {
    let pool = ctx.data::<PgPool>()?;

    let sql = SqlBuilder::select_from(ORGANIZATION_TABLE_NAME)
        .field("*")
        // Right now I need to convert to a string
        .and_where("id = $1".bind(&id.to_string()))
        .sql()?;

    Ok(sqlx::query_as::<_, Organization>(sql.as_str())
        .fetch_optional(pool)
        .await?)
}

Also, would you recommend using .and_where("id = $1".bind(&SqlName::new(id).safe())) to prevent sql injection since the id is passed from the client or is my understanding of SqlName incorrect?

@mike-lloyd03
Copy link

@onx2 Did you ever sort this out? I'm in the same boat.

@onx2
Copy link
Author

onx2 commented Mar 3, 2023

@mike-lloyd03 I didn't put any effort into resolving this issue because I was just playing around with some personal projects. For my professional work I've been using Diesel. You could also check out sqlx which would be a closer comparison to this package than diesel.

If you want to stick with this package you might be able to submit a PR but it looks like it isn't maintained anymore (last commit). Your best bet is probably forking and maybe modifying arg.rs to support UUID.

@mike-lloyd03
Copy link

mike-lloyd03 commented Mar 4, 2023

Believe it or not, I'm actually using this to generate the sql that I pass into sqlx. The and_when function saves a lot of redundancy. But I didn't realize isn't been over 2 years since last it was updated. I might just go back to writing my own queries.

But also uuid.to_string() seems to work fine.

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

No branches or pull requests

2 participants