Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to cast the row.get() method result to a custom Struct? #113

Open
tausifcreates opened this issue Sep 25, 2023 · 4 comments
Open

How to cast the row.get() method result to a custom Struct? #113

tausifcreates opened this issue Sep 25, 2023 · 4 comments

Comments

@tausifcreates
Copy link

tausifcreates commented Sep 25, 2023

The docs only shows ways to cast to Node, String etc. What if I return a collect from the query which holds a list of, say a custom struct type. How do we do that?

@knutwalker
Copy link
Collaborator

I'm gonna refer to my comment from the other issue #108 (comment)

This will be possible with the serde integration, here is a unit test that deserializes a row into custom structs: https://github.com/knutwalker/neo4rs/blob/9681029210e47f55e2114f1572bfc875749cdfd7/lib/src/row.rs#L299
I would also like to add something like your example on the other issue as an example/integration test.

@tausifcreates
Copy link
Author

@knutwalker Thanks for your response! It surely will solve my pain points.

@knutwalker
Copy link
Collaborator

@tausifcreates we've just released 0.7.0-rc.1 with serde support. It's missing proper documentation, but I can see that maybe something like this works for you

#[derive(Debug, serde::Deserialize)]
struct Thing {
  some_prop: String,
  another_prop: u32,
}

// ...

let things = row.to::<Vec<Thing>>()?;
// or maybe
let things = row.get::<Vec<Things>>("column")?;

It would be great if you could give it a try and see if that works for you.

@tausifcreates
Copy link
Author

Hey thanks @knutwalker! Actually I shared the release announcement on reddit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants