Repository: SeaQL/sea-query (language: rust)

Issue:
`WithQuery` not usable with `SqlxBinder`
<!--

Welcome! Thanks for reporting bugs!

Do you want to ask a question? Are you looking for support?
Please ask us on
- Discord: https://discord.com/invite/uCPdDXzbdv
- GitHub Discussion

-->

## Description

`SqlxBinder` is implemented for `SelectStatement`, `UpdateStatement`, `InsertStatement`, `DeleteStatement` only. If you try to use a `WithQuery` there is no `.build_sqlx` method.

It seems like an oversight caused by being named With*Query* instead of With*Statement*. Copying and pasting the two line implementation of the `build_sqlx` method works, but `SqlxBinder` can't be implemented from outside `sea-query-binder` because of foreign trait implementation rules.

## Steps to Reproduce

1. Copy the example from [`SelectStatement::with()`](https://docs.rs/sea-query/latest/sea_query/query/struct.SelectStatement.html#method.with) into a project that uses sea-query-binder.
2. Replace the assertions at the bottom with `query.build_sqlx` as seen in [examples/sqlx_postgres/src/main.rs](https://github.com/SeaQL/sea-query/blob/48f7fddd506f557888e5beb656041c86124efe4b/examples/sqlx_postgres/src/main.rs).
3. Try to build.

### Expected Behavior

The code compiles and appropriate SQL is generated.

### Actual Behavior

A compilation error occurs because `.with()` returns a `WithQuery`, and `SqlxBinder` is not implemented for `WithQuery`.

### Reproduces How Often

Always

## Versions

```
❯ cargo tree | grep sea-
├── sea-query v0.28.2
│   ├── sea-query-attr v0.1.1 (proc-macro)
│   ├── sea-query-derive v0.3.0 (proc-macro)
├── sea-query-binder v0.3.0
│   ├── sea-query v0.28.2 (*)
```

DB is Postgresql 13.5.

## Additional Information

<!-- please provide a minimal reproducible example, if possible. Any other additional information that might be helpful. -->



Discussion / hints:
Hi, thank you for your report. Do you also have the time to draft a PR? I am keen to resolve this.
@matt-phylum hello! Can you show your query? 
This is the example query from the documentation:

```rust
let base_query = SelectStatement::new()
    .column(Alias::new("id"))
    .expr(1i32)
    .column(Alias::new("next"))
    .column(Alias::new("value"))
    .from(Alias::new("table"))
    .to_owned();

let cte_referencing = SelectStatement::new()
    .column(Alias::new("id"))
    .expr(Expr::col(Alias::new("depth")).add(1i32))
    .column(Alias::new("next"))
    .column(Alias::new("value"))
    .from(Alias::new("table"))
    .join(
        JoinType::InnerJoin,
        Alias::new("cte_traversal"),
        Expr::col((Alias::new("cte_traversal"), Alias::new("next")))
            .equals((Alias::new("table"), Alias::new("id"))),
    )
    .to_owned();

let common_table_expression = CommonTableExpression::new()
    .query(
        base_query
            .clone()
            .union(UnionType::All, cte_referencing)
            .to_owned(),
    )
    .columns([
        Alias::new("id"),
        Alias::new("depth"),
        Alias::new("next"),
        Alias::new("value"),
    ])
    .table_name(Alias::new("cte_traversal"))
    .to_owned();

let select = SelectStatement::new()
    .column(ColumnRef::Asterisk)
    .from(Alias::new("cte_traversal"))
    .to_owned();

let with_clause = WithClause::new()
    .recursive(true)
    .cte(common_table_expression)
    .cycle(Cycle::new_from_expr_set_using(
        SimpleExpr::Column(ColumnRef::Column(Alias::new("id").into_iden())),
        Alias::new("looped"),
        Alias::new("traversal_path"),
    ))
    .to_owned();

let query = select.with(with_clause).to_owned();

// Builds:
select.build_sqlx(PostgresQueryBuilder);
// Does not build:
query.build_sqlx(PostgresQueryBuilder);
```

Fix patch:
diff --git a/sea-query-binder/src/sqlx.rs b/sea-query-binder/src/sqlx.rs
index 6302a302f..ee1990295 100644
--- a/sea-query-binder/src/sqlx.rs
+++ b/sea-query-binder/src/sqlx.rs
@@ -25,3 +25,4 @@ impl_sqlx_binder!(SelectStatement);
 impl_sqlx_binder!(UpdateStatement);
 impl_sqlx_binder!(InsertStatement);
 impl_sqlx_binder!(DeleteStatement);
+impl_sqlx_binder!(WithQuery);
diff --git a/sea-query-postgres/src/lib.rs b/sea-query-postgres/src/lib.rs
index 4e6794e45..a5cdf6757 100644
--- a/sea-query-postgres/src/lib.rs
+++ b/sea-query-postgres/src/lib.rs
@@ -47,6 +47,7 @@ impl_postgres_binder!(SelectStatement);
 impl_postgres_binder!(UpdateStatement);
 impl_postgres_binder!(InsertStatement);
 impl_postgres_binder!(DeleteStatement);
+impl_postgres_binder!(WithQuery);
 
 impl ToSql for PostgresValue {
     fn to_sql(
diff --git a/sea-query-rusqlite/src/lib.rs b/sea-query-rusqlite/src/lib.rs
index 3d17abb85..286ac7868 100644
--- a/sea-query-rusqlite/src/lib.rs
+++ b/sea-query-rusqlite/src/lib.rs
@@ -47,6 +47,7 @@ impl_rusqlite_binder!(SelectStatement);
 impl_rusqlite_binder!(UpdateStatement);
 impl_rusqlite_binder!(InsertStatement);
 impl_rusqlite_binder!(DeleteStatement);
+impl_rusqlite_binder!(WithQuery);
 
 impl ToSql for RusqliteValue {
     fn to_sql(&self) -> Result<ToSqlOutput<'_>> {


Test patch: