A CRUD library for Holochain zomes that implement the CEPS pattern (Chained, Entry, Permalink, State-based)
For information on which versions of this package work for each Holochain release, see docs/HolochainVersionMap.md
Example of adding to Cargo.toml
toml
[dependencies]
hc_crud_ceps = "0.3.0"
Example of importing into your Rust file
rust
use hc_crud::{
now, get_origin_address, fetch_element, fetch_element_latest,
create_entity, get_entity, update_entity, delete_entity, get_entities,
Entity, Collection, EntryModel, EntityType,
};
These imports and structs are assumed for all examples ```rust use hdk::prelude::*; use hccrud::{ now, createentity, getentity, updateentity, deleteentity, getentities, Entity, Collection, EntryModel, EntityType, };
pub struct PostEntry {
pub title: String,
pub message: String,
pub publishedat: Option
impl EntryModel for PostEntry { fn get_type(&self) -> EntityType { EntityType::new( "post", "entry" ) } } ```
Example ```rust let input = PostEntry { title: String::from("Greeting"), message: String::from("Hello world!"), publishedat: Some(1633108520744), lastupdated: None, };
let postentity = createentity( &input )?; ```
Example
rust
let post_entity = get_entity( &entity.id )?;
Example
rust
let post_entity = update_entity( &entity.address, |mut previous: PostEntry, _| {
previous.message = String::from("Hello, world!");
previous.last_updated = Some( now()? );
Ok(previous)
})?;
Example
rust
delete_entity::<PostEntry>( &entity.id )?;
Create a 1-to-many relationship for post entries to have comment entries.
The following examples use this additional struct ```rust
pub struct CommentEntry {
pub message: String,
pub publishedat: Option
impl EntryModel for CommentEntry { fn get_type(&self) -> EntityType { EntityType::new( "comment", "entry" ) } } ```
Create a CommentEntry
and link it to the PostEntry
```rust
const TAG_COMMENT: &'static str = "comment";
let input = CommentEntry { message: String::from("Where is the sun?"), publishedat: Some( now()? ), lastupdated: None, };
let commententity = createentity( &input )?;
commententity.linkfrom( &postentity.id, TAGCOMMENT.into() )?; ```
Get a Collection
for a specific base and tag
rust
let collection = get_entities::<PostEntry, CommentEntry>( &post_entity.id, TAG_COMMENT.into() )?;
See CONTRIBUTING.md