# `edgedb_codegen`
> Generate fully typed rust code from your EdgeDB schema and inline queries.
[![Crate][crate-image]][crate-link] [![Docs][docs-image]][docs-link] [![Status][ci-status-image]][ci-status-link] [![Unlicense][unlicense-image]][unlicense-link] [![codecov][codecov-image]][codecov-link]
## Installation
To install the `edgedb_codegen` crate you can use the following command.
```bash
cargo add edgedb_codegen
```
Or directly add the following to your `Cargo.toml` file.
```toml
edgedb_codegen = "0.2"
```
Follow the [Quickstart Guide](https://docs.edgedb.com/get-started/quickstart) to make sure your edgedb instance is running. The macro relies on the running `edgedb` instance to parse the output of the provided query string.
## Usage
When working with `edgedb` you often need to write queries and also provide the typed for both the input and output. Your code is only checked at runtime which increases the risk of bugs and errors.
Fortunately, `edgedb` has a query language that is typed and can be converted into types and queried for correctness at compile time.
### Inline Queries
```rust
use edgedb_codegen::edgedb_query;
use edgedb_errors::Error;
use edgedb_tokio::create_client;
// Creates a module called `simple` with a function called `query` and structs
// for the `Input` and `Output`.
edgedb_query!(
simple,
"select { hello := \"world\", custom := $custom }"
);
#[tokio::main]
async fn main() -> Result<(), Error> {
let client = create_client().await?;
let input = simple::Input {
custom: String::from("custom"),
};
// For queries the following code can be used.
let output = simple::query(&client, &input).await?;
Ok(())
}
```
The macro above generates the following code:
```rust
pub mod simple {
use ::edgedb_codegen::exports as e;
/// Execute the desired query.
#[cfg(feature = "query")]
pub async fn query(
client: &e::edgedb_tokio::Client,
props: &Input,
) -> core::result::Result