# 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
BotanistContexttrait 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
DBtype and theConnectiontype must be defined in the trait implementation. TheDBtype 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_connectionfunction (in this example a type ofPooledConnection).Add the
botanist_objectattribute andtable_nameto your Diesel models.Note
It's important to note that the
botanist_attributemust 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_queryandbotanist_mutationto 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_queryandbotanist_mutationmust 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 theQueryorMutationstruct implementations will be preserved.