zenode

Crates.iozenode
lib.rszenode
version0.3.4
sourcesrc
created_at2022-09-21 21:29:29.013502
updated_at2022-10-20 22:59:11.071423
descriptionAbstraction layer on top of p2panda and graphql to easily create schemas and perform operations on a p2panda node
homepagehttps://github.com/Gers2017/zenode
repositoryhttps://github.com/Gers2017/zenode
max_upload_size
id671190
size33,218
Gers (Gers2017)

documentation

README

Zenode

What is this project

This project is an abstraction layer between the client and the p2panda node by providing tools to easily perform operations on a p2panda node.

Before you start

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

Quick start

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?;

Experimental Schema Builder

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?;

Features

  • Create schemas
  • Crate fields
  • Crate instance
  • Update instance
  • Delete instance
  • Read endpoint from env
  • Better field to json
  • Save schema_id
  • Link schema name with schema_id
  • Serializable query string
Commit count: 32

cargo fmt