this post was submitted on 07 Aug 2023
6 points (87.5% liked)

Rust

5744 readers
89 users here now

Welcome to the Rust community! This is a place to discuss about the Rust programming language.

Wormhole

[email protected]

Credits

  • The icon is a modified version of the official rust logo (changing the colors to a gradient and black background)

founded 1 year ago
MODERATORS
 

Hi everyone! I started learning rust about 3 months ago and had a sort of working version of this for my own needs, but spent some time (maybe lots) cleaning it up, testing it, and making it worthy of publishing.

https://crates.io/crates/cypher-dto

It's for working with Neo4j (cypher query language). It aims to assist in creating manual queries but provides unitary CRUD operations for nodes and relationships out of the box. Some other niceties:

Generates new(), getter methods, and a builder struct, and copies doc comments to them.

Has 'smart' handling of created/updated timestamp fields.

Supports multi-valued primary keys; uses the term "identifier" for that set of fields.

top 2 comments
sorted by: hot top controversial new old
[โ€“] RunAwayFrog 3 points 1 year ago* (last edited 1 year ago) (1 children)
  • I would drop the derive shorthands, and drop the Cypher prefix from the derive macros. They are already namespaced under the crate.
  • Regarding the ty::new() impls, I'm not a hardline devotee of the builder pattern, but when there are multiple private fields of the same type, I would absolutely prefer it, to remove the possibility of field-value confusion at construction.

I didn't dig deeper because I noticed you posted this to Reddit first ๐Ÿ˜‰

[โ€“] [email protected] 1 points 1 year ago* (last edited 1 year ago)

Thanks for the feedback.

  • I'll definitely drop the Cypher prefix, and think it's a good idea to at least move the shorthand attribute macros to a crate feature. The readmes would use derive instead of the shorthand mostly.
  • ty::new() just uses the types in the struct (plus &str for String and &[T] for Vec). The extra builder struct is to help with updates, where you may want to just change a couple of fields, or bind it to editable UI fields.

I didn't realize how strong the rust presence is here. Experienced-devs on reddit is hard to go without :)