| Crates.io | zenode |
| lib.rs | zenode |
| version | 0.3.4 |
| created_at | 2022-09-21 21:29:29.013502+00 |
| updated_at | 2022-10-20 22:59:11.071423+00 |
| description | Abstraction layer on top of p2panda and graphql to easily create schemas and perform operations on a p2panda node |
| homepage | https://github.com/Gers2017/zenode |
| repository | https://github.com/Gers2017/zenode |
| max_upload_size | |
| id | 671190 |
| size | 33,218 |
This project is an abstraction layer between the client and the p2panda node by providing tools to easily perform operations on a p2panda node.
In order to run this you first need to install aquadoggo
git clone https://github.com/p2panda/aquadoggo.git
RUST_LOG=aquadoggo=info cargo run
The Operator struct is the main wrapper around the p2panda library and the graphql layer.
To create a new Operator use Operator::default() or Operator::new().
Operator::default() reads the ENDPOINT environment variable, if is not present it uses http://localhost:2020/graphql as default endpoint.
Run the following to test Zenode (aquadoggo must be running in the background):
cargo test
use zenode::{field, Operator};
use zenode::FieldType::*;
// create an Operator
let op = Operator::default();
// create a schema
let id = op.create_schema(
"POKEMON",
"Pokemon schema",
&mut [
field_def("pokemon_id", Int), // same as field("pokemon_id", "int")
field_def("pokemon_name", Str),
]
).await?;
// generate schema_id
let schema_id = format!("POKEMON_{}", id);
// create an instance
let instance_id = op.create_instance(&schema_id, &mut [
field("pokemon_id", "1"), field("pokemon_name", "Bulbasaur")
]).await?;
// update the instance
let update_id = op.update_instance(&schema_id, &instance_id, &mut [
field("pokemon_name", "Charmander")
]).await?;
// finally delete the instance
let _delete_id = op.delete_instance(&schema_id, &update_id).await?;
let op = Operator::default();
let mut puppy_builder = SchemaBuilder::new("puppy", "Puppy schema", &op)
.field("name", Str)
.field("cuteness", Int);
puppy_builder.build().await?;
let tiramisu_id = puppy_builder
.instantiate(&mut [field("name", "Tiramisu"), field("cuteness", "200")])
.await?;