Crate cypher_dto

Crate cypher_dto 

Source
Expand description

A collection of traits and macros for working Data Transfer Objects (DTOs) Cypher and Neo4j.

It works with key-value pairs; only structs with named fields are supported.

This library introduces the Identifier concept, that DTOs can be identified by a subset of their fields. A [dto::WithId] is an “ordinary” DTO that has an [dto::Identifier]. Identifiers are also DTOs, but they cannot have an Identifier themselves.

{ #[derive(Node)] struct Person { name: String, } assert_eq!(Person::typename(), “Person”); assert_eq!(Person::field_names(), [“name”]); assert_eq!(Person::as_query_fields(), “name: $name”); assert_eq!(Person::as_query_obj(), “Person { name: $name }”); } { #[derive(Node)] #[name = “Person2”] struct Person { #[name = “name2”] name: String, } assert_eq!(Person::typename(), “Person2”); assert_eq!(Person::field_names(), [“name2”]); assert_eq!(Person::as_query_fields(), “name2: $name2”); assert_eq!(Person::as_query_obj(), “Person2 { name2: $name2 }”); }

The derive macro will implement [dto::WithId] on the attributed struct, and create a [dto::Identifier] struct named e.g. FooId. The ID struct will use the same [typename()] as the attributed struct, and include any fields that are marked #[id] on it.

If no fields are marked #[id], then the id field(s) are inferred:

  • If there is a field named id, that will be the singular ID field in e.g. FooId.
  • Otherwise, all fields from the attributed struct will also be on the ID struct.

Dynamically added methods:

  1. fn into_values(self) - returns a tuple of all the values in the struct.

Enums§

Error
Neo4jMap
An abstraction over the different types of returned values from Neo4j.
RelationBound
When creating a relationship, the query has to MATCH, CREATE, or MERGE the start and end nodes.
StampMode
Controls which timestamps are hardcoded in a query (e.g. datetime()), and which use placeholders (e.g. $created_at).
Stamps
The standard timestamps an object uses, and their field names.

Traits§

FieldSet
The full or partial fields on a node or relationship that may have timestamps.
NodeEntity
A node [Entity].
NodeId
The identifying fields of a NodeEntity.
RelationEntity
A relationship entity.
RelationId
The identifying fields of a RelationEntity.

Functions§

format_param
Formats a parameter name with or without a prefix. For example, foo would become prefix_foo.
format_query_fields
Utility function for formatting part of a cypher [Query].

Attribute Macros§

timestamps
Adds created/updated timestamp fields to a struct, using [Option<DateTime<Utc>>] as the type.

Derive Macros§

Node
Derives the NodeEntity and related traits.
Relation
Derives the RelationEntity and related traits.