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§

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

Traits§

Functions§

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

Attribute Macros§

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

Derive Macros§