neo4j-labs / neo4rs Goto Github PK
View Code? Open in Web Editor NEWNeo4j driver for rust
Home Page: https://docs.rs/neo4rs
Neo4j driver for rust
Home Page: https://docs.rs/neo4rs
execute(query(&query_string).param("a", true))
This doesnt work because
the trait From<bool>
is not implemented for neo4rs::types::BoltType
Can this be added or is there a reason its not allowed?
Recently, I try "neo4rs"," Deadpool-bolt", "b88-bolt" to create connection pool with neo4j. My program appears
"error:UnexpectedMessage("unexpected response for RUN: Err(IOError { detail: "IO driver has terminated" })")"driver has terminated"
when many query appears in a short time. How to solve it ?
I have google the error , but I did not found any useful information.
tracing offers better telemetry especially for async and can be used with logging crates
Graph should be directly Send + Sync + Clone(~cheap)
Judging from the API surface, sqlx does not need to be strictly SQL
How to convert custom types so that they can be specified in the function param
?
i want bind json object by Query.param(). but Into<BoltType> just implemented for some basic type.
can bind whole properties for label by Query.param()? like this:
struct CustomType<T: Into<BoltType>> {
p1: T,
p2: T,
p3: T,
}
let properties = CustomType::new();
// case 1
query("CREATE (SomeLabel $properties)").param("properties", properties);
// case 2
query("CREATE (SomeLabel {data: $data})").param("data", properties);
See CVE-2020-26235 and chronotope/chrono#602. Both are fixed now, time is more lower level
could be params(impl IntoIterator<Item=(K, V)>)
or maybe impl Extend for Query
See the diff the @jexp has
Conversions to/from BoltType is not possible as the module and types are private. This is a major deal breaker for using this crate.
Query params can only be built using existing supported types.
If not already done, use bounded pull
It looks like this repository is abandoned, but quite some people seem to be happy to provide pull requests and have forks.
Would you be happy to transfer ownership of the crate to someone in case you don't plan to continue working on it?
Implementing the Error
trait has the advantage of the type working well with error handling crates like failure
or anyhow
.
e.g. in row.next -> .get("has_more")
Is there a reason for this? I see the conversion for the other direction: BoltType -> f64, but as it is, I can't use an f64 as a parameter to a query.
See python driver
Similar to what sqlx::query! does
The driver support routing (for Neo4j clusters) ?
Version support following Neo4j product drivers
Hey, all.
Sorry about the title but that's the clearest way I could think to say it. There are a few areas, such as Query, where it would be nice to either be able to access struct fields as public or have accessor methods for the private fields. I can't really think of a reason the fields would need to be private, as the data belongs to the user of the library anyway.
Also, it would be nice to be able to perform comparison operations on some of the data structs, such as PartialEq. I'm willing to help out in this area. Do you all accept pull requests? Thanks.
use anyhow::bail;
use neo4rs::Graph;
use crate::{NEO4J_PASS, NEO4J_URL, NEO4J_USER};
pub struct AppState {
pub graph: Graph,
}
impl AppState {
pub async fn new() -> anyhow::Result<Self> {
let this = match Graph::new(NEO4J_URL, NEO4J_USER, NEO4J_PASS).await {
Ok(graph) => Self { graph },
Err(err) => {
return bail!("Error creating graph instance in app state {err:?}");
}
};
let mut result = this
.graph
.execute(neo4rs::query("MATCH (p:Person {name: $name}) RETURN p").param("name", "Mark"))
.await
.unwrap();
Ok(this)
}
}
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: UnexpectedMessage("unexpected response for RUN: Ok(FailureMessage(Failure { metadata: BoltMap { value: {BoltString { value: \"code\" }: String(BoltString { value: \"Neo.ClientError.Request.InvalidFormat\" }), BoltString { value: \"message\" }: String(BoltString { value: \"Illegal struct size: Expected struct to be 3 fields but got 1\" })} } }))")', src\api\app_state.rs:23:14
docker run --name global_graph_neo -p 7474:7474 -p 7687:7687 -e "NEO4J_AUTH=neo4j/password" neo4j
OS:
windows 11
Hey, all. I apologize if this is the wrong place for this.
It took a while to confirm, but I was having problems with the driver establishing connection with a recent 5.4.0 server. When I realized the newest available crate on crates.io might be rather old, I built this from source and tested it. It works.
Does anyone know who updates the tagged releases here? Anyone know who updates crates.io? I'm willing to help out, but I'm not entirely sure where to start. Is there any official build instructions? My local build is a bit of a mess at the moment. Using a locally-built crate to resolve issues is not ideal. Thanks.
This would solve #7 and add a lot of flexibility, marcos, ...
I guess Deserialize would also be handy.
If you like, I would create a PR for it
I just realised that BoltType
is deeply rooted into your crate and also conflicts with an into implementation from any type that is Serialize
so this is probably a lot...
What I actually try to archive is converting a JSON Map (with different Value Types) to BoltType
.
But currently there seems to be no way of getting to a BoltMap
so adding a
impl<T> From<Box<T>> for BoltType where T: Into<BoltType>
for the dynamic types would not by itself help me
However converting from JSON would be easy:
impl From<serde_json::Value> for BoltType {
fn from(json: serde_json::Value) -> BoltType {
match json {
serde_json::Value::Null => BoltType::Null(BoltNull),
serde_json::Value::Bool(bool) => BoltType::Boolean(BoltBoolean::new(bool)),
serde_json::Value::Number(nr) => {
if nr.is_f64() {
BoltType::Float(BoltFloat::new(nr.as_f64().unwrap()))
}else{
BoltType::Integer(BoltInteger::new(nr.as_i64().unwrap()))
}
},
serde_json::Value::String(str) => BoltType::String(BoltString::new(&str)),
serde_json::Value::Array(arr) => {
let mut l = BoltList::with_capacity(arr.len());
for v in arr {
l.push(v.into());
}
BoltType::List(l)
},
serde_json::Value::Object(map) => {
let mut m = BoltMap::with_capacity(map.len());
for (k,v) in map {
m.put(k.into(),v.into());
}
BoltType::Map(m)
},
}
}
}
Would you be interested in a conversion from JSON? Probably behind a Feature flag, as I guess that serde_json adds a bit of weight
This is a query from the server
It have 1 result, created
is int
The code below, do the same exact query
let mut result = provider
.graph
.execute(query("MATCH(p:Post) RETURN p"))
.await
.unwrap();
let row = result.next().await.unwrap().unwrap();
let t = row.get::<i64>("created");
info!("{}", t.is_some());
result.next().await.unwrap().unwrap(); //panic
output
false
thread 'actix-rt|system:0|arbiter:7' panicked at 'called `Option::unwrap()` on a `None` value', src/main.rs:64:34
observable behaviour: it did return 1 row, however, created
is None
expected behaviour: t.is_some()==true
Enviroment: Arch Host, docker 23.0.1, image: neo4j:4.1
Cargo.toml
neo4rs = { git = "https://github.com/neo4j-labs/neo4rs" }
The same result happen up to neo4j:4.4.18
Trying to get a null
value from a row results in the following error:
Error: UnexpectedMessage("unexpected response for PULL: Err(UnknownType("b\"\\xc0\""))")
At least we could strip down from tokio/full
It is recommended to implement From
instead of Into
as From
gives us Into
automatically while the reverse it not true.
Implement de/serializing bolt results to user types. Users can use their Serialize/Deserialize types to send/receive data without having to go bolt -> rust -> user
If not already, session.run vs open/close tx under the hood
When running a query like MATCH (a)-[r]-(b) RETURN a, collect(b.name) as mylist
The node a
is accessible but the collection mylist
is not. It show's up in the Row
response as a
Row { attributes: BoltMap { value: {BoltString { value: "mylist" }: List(BoltList { value: [String(BoltString { value: "somevalue" }), String(BoltString { value: "anothervalue" })] }), BoltString { value: "a" }...
But when calling row.get("mylist")
you always get None
around 1.59 makes sense, set it in Cargo.toml. Update CI to use a Cargo.msrv.lock. Update dependencies accordingly
consider using cargo-make for its ci-flow tasks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.