Skip to content

Commit

Permalink
doc:
Browse files Browse the repository at this point in the history
  • Loading branch information
imagineDevit committed Apr 11, 2023
1 parent af92db1 commit bd507f4
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/src/inner_attributes/options.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Options

_**Options**_ attribute marks a field as a select option (order and pagination options). The decorated fied must be of type [edgedb_query::queries::select::SelectOptions](https://github.com/imagineDevit/edgedb/blob/main/edgedb-query/src/queries/select.rs)
_**Options**_ attribute marks a field as a select option (order and pagination options). The decorated fied must be of type [edgedb_query::queries::select::SelectOptions](https://docs.rs/edgedb-query/0.2.2/edgedb_query/queries/select/struct.SelectOptions.html)

#[options]

Expand Down
2 changes: 1 addition & 1 deletion docs/src/inner_attributes/unless_conflict.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Unless Conflict

_**Unless Conflict**_ attribute represents a [unless conflict else ](https://www.edgedb.com/docs/edgeql/insert#conflicts) statement.<br> The decorated field must by of type
[edgedb_query::queries::conflict::UnlessConflict](https://github.com/imagineDevit/edgedb/blob/main/edgedb-query/src/queries/conflict.rs) or [edgedb_query::queries::conflict::UnlessConflictElse<T: ToEdgeQuery>](https://github.com/imagineDevit/edgedb/blob/main/edgedb-query/src/queries/conflict.rs).
[edgedb_query::queries::conflict::UnlessConflict](https://docs.rs/edgedb-query/0.2.2/edgedb_query/queries/conflict/struct.UnlessConflict.html) or [edgedb_query::queries::conflict::UnlessConflictElse<T: ToEdgeQuery>](https://docs.rs/edgedb-query/0.2.2/edgedb_query/queries/conflict/struct.UnlessConflictElse.html).

#[unless_conflict(on)]

Expand Down
2 changes: 1 addition & 1 deletion docs/src/query-macros/insert-query.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ To handle this case we need to use an [_unless conflict_](https://www.edgedb.com

The new field _handle_conflict_ decorated with [#[unless_conflict]](../inner_attributes/unless_conflict.md) tag add a ``` unless conflict on .user_name``` statement to the query.

It is possible to add an else query to the unless conflict statement by using a [edgedb_query::queries::conflict::UnlessConflictElse<T: ToEdgeQuery>](https://github.com/imagineDevit/edgedb/blob/main/edgedb-query/src/queries/conflict.rs) type instead of an UnlessConflict type.
It is possible to add an else query to the unless conflict statement by using a [edgedb_query::queries::conflict::UnlessConflictElse<T: ToEdgeQuery>](https://docs.rs/edgedb-query/0.2.2/edgedb_query/queries/conflict/struct.UnlessConflictElse.html) type instead of an UnlessConflict type.

````rust
#[insert_query(module="models", table="Person", result="Person")]
Expand Down
63 changes: 58 additions & 5 deletions docs/src/query-macros/query-macros.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,62 @@

Queries attributes (except #[file_query] ) take three arguments 👇

| Argument | Optional | Description |
|----------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| module | yes | The name of the edgeDB module on which the query is executed.<br> <br/> _**By default**_: 'default' |
| table | no | The name of the edgeDB table on which the query is executed.<br> |
| result | yes | The query result type.<br> <br/>_**By default**_: [BasicResult](https://github.com/imagineDevit/edgedb/blob/main/edgedb-query/src/models/query_result.rs) |
| Argument | Optional | Description |
|----------|----------|--------------------------------------------------------------------------------------------------------------------------------------------------------------|
| module | yes | The name of the edgeDB module on which the query is executed.<br> <br/> _**By default**_: 'default' |
| table | no | The name of the edgeDB table on which the query is executed.<br> |
| result | yes | The query result type.<br> <br/>_**By default**_: [BasicResult](https://docs.rs/edgedb-query/0.2.2/edgedb_query/models/query_result/struct.BasicResult.html) |

When a struct is decorated with one of those queries macro attributes, several trait implementations are created for this one:

- [ToEdgeQl](https://docs.rs/edgedb-query/0.2.2/edgedb_query/trait.ToEdgeQl.html)
- [ToEdgeValue](https://docs.rs/edgedb-query/0.2.2/edgedb_query/trait.ToEdgeValue.html)
- [ToEdgeQuery](https://docs.rs/edgedb-query/0.2.2/edgedb_query/models/edge_query/trait.ToEdgeQuery.html)
- [ToEdgeScalar](https://docs.rs/edgedb-query/0.2.2/edgedb_query/trait.ToEdgeScalar.html)
- [ToString]()


The following example shows how to get a parameterized query from a struct decorated with a query macro attribute ( #[insert_query] for example) :


Consider the following struct 👇:

```rust
#[insert_query(module="humans", table="Person")]
pub struct InsertPerson {
pub name: String,
pub age: i8
}
```

To get a parameterized query from this struct, we can write the following code:

```rust
#[tokio::main]
fn main() -> Result<()>{
let insert_person = InsertPerson {
name: "John".to_string(),
age: 20
};

let edge_query: EdgeQuery = insert_person.to_edge_query();

}

```

`to_edge_query()` ( from [ToEdgeQuery](https://docs.rs/edgedb-query/0.2.2/edgedb_query/models/edge_query/trait.ToEdgeQuery.html) trait ) method returns a [EdgeQuery](https://docs.rs/edgedb-query/0.2.2/edgedb_query/models/edge_query/struct.EdgeQuery.html) struct that contains the query string and the query parameters.

The query's cardinality (`Cardinality::Many` by default) can also be set while getting the query by calling `to_edge_query_with_cardinality()` method instead of `to_edge_query()`.

```rust
let edge_query: EdgeQuery = insert_person.to_edge_query_with_cardinality(Cardinality::One);
```

With the got query, we can now execute request using edgedb-client like this:

```rust
if let EdgeQuery{ query, args: Some(params), .. } = edge_query {
let result: BasicResult = client.query_required_single(query.as_str(), params).await?;
}
```

0 comments on commit bd507f4

Please sign in to comment.