5 unstable releases
0.3.1 | Mar 24, 2024 |
---|---|
0.3.0 | Mar 1, 2024 |
0.2.0 | Aug 12, 2023 |
0.1.1 | Aug 7, 2023 |
0.1.0 | Aug 6, 2023 |
#10 in #dto
27 downloads per month
Used in cypher-dto
65KB
1.5K
SLoC
cypher-dto-macros
Macros for working with the cypher-dto crate.
There are three types of macros contained:
-
Derive macros, which do most of the work.
#[derive(Node)] struct Person { id: String, name: String, #[name = "zip_code"] zip: String, } #[derive(Relation)] struct Knows;
These will implement
cypher_dto::{FieldSet, NodeEntity, RelationEntity}
for the structs.There are two helper attributes that come into scope when using the derive macros,
#[id]
, and#[name]
.#[id]
marks a field as being part of the entity's uniquely identifying set of fields. Multi-valued identifiers are supported this way. If none are specified and a field namedid
exists, that will be inferred to be the only id field. The set of id fields is given its own struct, e.g.PersonId
, that can be obtained viaperson.identifier()
orperson.into()
.#[name]
allows the property name in the database to be different than on the struct.#[name = "..."]
and#[name("...")]
are supported, and can be applied to the struct as well.A builder is also generated for each struct, e.g.
PersonBuilder
. It can be obtained viaperson.into_builder()
. -
The
#[timestamps]
macro, which will add one or two timestamp fields to the struct. By default it adds two fields,created_at
andupdated_at
, with the typeOption<DateTime<Utc>>
. Optional timestamp fields let thePerson::new()
implementation skip having them as arguments, which is how you would create a DTO in application code before it is created in the database.You can control which fields it adds by specifying certain values as a string (
#[timestamps = "..."]
and#[timestamps("...")]
are supported). The values must be ONE offull
(the default),short
(created, updated),created_at
,updated_at
,created
, orupdated
.
Dependencies
~0.6–1.2MB
~23K SLoC