# Basic Usage
This guide assumes you already have a Rust binary setup with Diesel and Juniper. For guidiance on setting up either, see their respective docs.
Install Botanist and it's codegen library in
cargo.toml
:botanist = "0.1" botanist_codegen = "0.1"
Find your Juniper Context and implement the
BotanistContext
trait with something like the following:impl BotanistContext for Context { type DB = diesel::pg::Pg; type Connection = diesel::r2d2::PooledConnection<...>; fn get_connection(&self) -> &Self::Connection { &self.connection } }
Types
It's important to note that both the
DB
type and theConnection
type must be defined in the trait implementation. TheDB
type should reference your underlying Diesel database type (in this example Postgres/Pg
). The connection type should reference the type of connection you'll provide to Botanist in theget_connection
function (in this example a type ofPooledConnection
).Add the
botanist_object
attribute andtable_name
to your Diesel models.Note
It's important to note that the
botanist_attribute
must have a context type specified viaContext = <Your Context Type>
.#[botanist_object(Context = Context)] #[table_name = "heros"] pub struct Hero { pub id: Uuid, pub name: String, }
Finally, add
botanist_query
andbotanist_mutation
to your query and mutation structs respectively.pub struct Query; pub struct Mutation; #[botanist_query( Hero, Context = Context, PrimaryKey = Uuid, )] impl Query {} #[botanist_mutation( Hero, Context = Context, PrimaryKey = Uuid, )] impl Mutation {}
All types (Diesel models) that should be queryable must be listed in
botanist_query
. Types (Diesel models) that should have mutations generated for them must be listed inbotanist_mutation
. Bothbotanist_query
andbotanist_mutation
must specify the context type (Context = <Your Context Type>
) and primary key type (PrimaryKey = <Your Primary Key Type>
). Any resolvers or mutations you explicitly write into theQuery
orMutation
struct implementations will be preserved.