prisma / tiberius

TDS 7.2+ (Microsoft SQL Server) driver for Rust
Apache License 2.0
321 stars 118 forks source link

How to write wrapper for try_get? QueryIdx is private #258

Open Christoph-AK opened 1 year ago

Christoph-AK commented 1 year ago

Hey there! Thanks so much for this awesome crate!

I want to write a custom wrapper for try_get, like this:

fn get_c_opt(r: &Row, id: impl QueryIdx) -> Result<Option<String>> {
    Ok(r.try_get::<&str, _>(id)?.map(|s| s.to_string()))
}

fn get_c_or_empty(r: &Row, id: impl QueryIdx) -> Result<String> {
    Ok(get_c_opt(r, id)?.unwrap_or_default())
}

But the QueryIdx trait is not exposed, so this doesn't compile. Is there any way to work around this, or could we expose the trait?