kurtbuilds / ormlite

An ORM in Rust for developers that love SQL.
https://crates.io/crates/ormlite
MIT License
216 stars 11 forks source link

How to express more WHERE clauses in a query #18

Closed andreapavoni closed 1 year ago

andreapavoni commented 1 year ago

Hi there and thank you for this excellent library. I'm still very new to Rust and I've tried several approaches to interact with dbs (plain sqlx, diesel, SeaORM), but this one is very ergonomic and easy to use.

I've seen that with only 1 WHERE clause I can write something like:

Point::query("SELECT * FROM points WHERE x = ?")
        .bind(3i32)
        .fetch_all(&mut conn)
        .await?;

how can I express a query with 2 or more WHERE clauses, like this?

SELECT * from points WHERE x = 3 AND y = 10

thanks in advance!

gmLucario commented 1 year ago

Probably you can use another bind like sqlx

Point::query("SELECT * FROM points WHERE x = ? AND y = ?")
        .bind(3i32)
        .bind(8i32)
        .fetch_all(&mut conn)
        .await?;
andreapavoni commented 1 year ago

Yeah, I didn’t considered/tried the second bind. Thanks!

kurtbuilds commented 1 year ago

Feel free to submit a PR with a small update to the docs if you feel it'd be helpful!

I'll close this issue, as it appears resolved.