Skip to content

Commit

Permalink
feat: Add space id filter
Browse files Browse the repository at this point in the history
  • Loading branch information
cvauclair committed Dec 12, 2024
1 parent 35ea24c commit 669495e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ tokio = { version = "1.42.0", features = ["macros", "rt-multi-thread"] }
tracing = "0.1.41"
tracing-subscriber = "0.3.19"

sdk = { version = "0.1.0", path = "../sdk" }
sink = { version = "0.1.0", path = "../sink" }

[dev-dependencies]
Expand Down
17 changes: 15 additions & 2 deletions api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,22 @@ impl Query {
&'a self,
executor: &'a Executor<'_, '_, KnowledgeGraph, S>,
id: String,
// context: &'a KnowledgeGraph,
space_id: Option<String>,
version_id: Option<String>,
) -> Option<Node> {
// let query = QueryMapper::default().select_root_node(&id, &executor.look_ahead()).build();
// tracing::info!("Query: {}", query);

Check warning on line 41 in api/src/main.rs

View workflow job for this annotation

GitHub Actions / stable / fmt

Diff in /home/runner/work/kg-node/kg-node/api/src/main.rs

let query = match (space_id, version_id) {
(Some(space_id), _) => sdk::neo4rs::query("MATCH (n {id: $id, space_id: $space_id}) RETURN n")
.param("id", id)
.param("space_id", space_id),
(None, _) => sdk::neo4rs::query("MATCH (n {id: $id}) RETURN n")
.param("id", id)
};

executor.context().0
.find_node_by_id::<HashMap<String, serde_json::Value>>(&id)
.find_node::<HashMap<String, serde_json::Value>>(query)
.await
.expect("Failed to find node")
.map(Node::from)
Expand Down Expand Up @@ -116,6 +125,10 @@ impl Node {
&self.id
}

fn space_id(&self) -> &str {
&self.space_id
}

fn types(&self) -> &[String] {
&self.types
}
Expand Down
4 changes: 2 additions & 2 deletions codegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn ts_type_from_value_type(value_type: &Node<Named>) -> TsType {
}
}

pub fn gen_type_constructor(kg: &sink::kg::Client, attributes: &[&(Node<Named>, Option<Node<Named>>)]) -> Constructor {
pub fn gen_type_constructor(attributes: &[&(Node<Named>, Option<Node<Named>>)]) -> Constructor {
let super_constructor = vec![quote_expr!("super(id, driver)")];

let constuctor_setters = attributes.iter().map(|(attr, _)| {
Expand Down Expand Up @@ -225,7 +225,7 @@ pub async fn gen_type(kg: &sink::kg::Client, entity: &Node<Named>) -> anyhow::Re
Ok(Decl::Class(class(
entity.type_name(),
attribute_class_props,
Some(gen_type_constructor(kg, &attributes)),
Some(gen_type_constructor(&attributes)),
relation_methods,
vec![],
Some(ident("Entity")),
Expand Down
2 changes: 2 additions & 0 deletions sdk/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,5 @@ pub mod relation;

pub use ids::network_ids;
pub use ids::system_ids;

pub use neo4rs;
1 change: 0 additions & 1 deletion sink/src/kg/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ impl Client {
.next()
.await?
.map(|row| {
tracing::info!("Row: {:?}", row.to::<neo4rs::Relation>());
Ok::<_, DatabaseError>(Relation::<T>::try_from(row.to::<neo4rs::Relation>()?)?)
})
.transpose()?)

Check failure on line 613 in sink/src/kg/client.rs

View workflow job for this annotation

GitHub Actions / stable / clippy

question mark operator is useless here

error: question mark operator is useless here --> sink/src/kg/client.rs:605:9 | 605 | / Ok(self.neo4j 606 | | .execute(query) 607 | | .await? 608 | | .next() ... | 612 | | }) 613 | | .transpose()?) | |__________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#needless_question_mark help: try removing question mark and `Ok()` | 605 ~ self.neo4j 606 + .execute(query) 607 + .await? 608 + .next() 609 + .await? 610 + .map(|row| { 611 + Ok::<_, DatabaseError>(Relation::<T>::try_from(row.to::<neo4rs::Relation>()?)?) 612 + }) 613 + .transpose() |
Expand Down

0 comments on commit 669495e

Please sign in to comment.