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

[query] Add values_id to insert nodes #401 #402

Merged
merged 2 commits into from
Dec 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions src/agdb/query/query_id.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
#[derive(Clone)]
pub enum QueryId {
Id(u64),
Alias(String),
}

impl From<&str> for QueryId {
fn from(value: &str) -> Self {
Self::from(value.to_string())
}
}

impl From<String> for QueryId {
fn from(value: String) -> Self {
Self::Alias(value)
}
}

impl From<u64> for QueryId {
fn from(value: u64) -> Self {
Self::Id(value)
}
}
1 change: 1 addition & 0 deletions src/agdb/query/query_ids.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::query_id::QueryId;
use super::search_query::SearchQuery;

pub enum QueryIds {
Id(QueryId),
Ids(Vec<QueryId>),
Search(SearchQuery),
}
8 changes: 8 additions & 0 deletions src/agdb/query_builder/insert_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use super::insert_node_alias::InsertNodeAlias;
use super::insert_node_values::InsertNodeValues;
use crate::db::db_key_value::DbKeyValue;
use crate::query::insert_nodes_query::InsertNodesQuery;
use crate::query::query_id::QueryId;
use crate::query::query_ids::QueryIds;
use crate::query::query_values::QueryValues;
use crate::Query;

Expand All @@ -20,6 +22,12 @@ impl InsertNode {
InsertNodeValues(self.0)
}

pub fn values_id(mut self, id: QueryId) -> InsertNodeValues {
self.0.values = QueryValues::Query(QueryIds::Id(id));

InsertNodeValues(self.0)
}

pub fn query(self) -> Query {
Query::InsertNodes(self.0)
}
Expand Down
8 changes: 8 additions & 0 deletions src/agdb/query_builder/insert_node_alias.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use super::insert_node_values::InsertNodeValues;
use crate::query::insert_nodes_query::InsertNodesQuery;
use crate::query::query_id::QueryId;
use crate::query::query_ids::QueryIds;
use crate::query::query_values::QueryValues;
use crate::DbKeyValue;
use crate::Query;
Expand All @@ -16,4 +18,10 @@ impl InsertNodeAlias {

InsertNodeValues(self.0)
}

pub fn values_id(mut self, id: QueryId) -> InsertNodeValues {
self.0.values = QueryValues::Query(QueryIds::Ids(vec![id]));

InsertNodeValues(self.0)
}
}
14 changes: 14 additions & 0 deletions src/agdb/query_builder/insert_nodes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ use super::insert_nodes_aliases::InsertNodesAliases;
use super::insert_nodes_count::InsertNodesCount;
use super::insert_nodes_values::InsertNodesValues;
use crate::query::insert_nodes_query::InsertNodesQuery;
use crate::query::query_id::QueryId;
use crate::query::query_ids::QueryIds;
use crate::query::query_values::QueryValues;
use crate::DbKeyValue;

Expand All @@ -25,4 +27,16 @@ impl InsertNodes {

InsertNodesValues(self.0)
}

pub fn values_id(mut self, id: QueryId) -> InsertNodesValues {
self.0.values = QueryValues::Query(QueryIds::Id(id));

InsertNodesValues(self.0)
}

pub fn values_ids(mut self, ids: &[QueryId]) -> InsertNodesValues {
self.0.values = QueryValues::Query(QueryIds::Ids(ids.to_vec()));

InsertNodesValues(self.0)
}
}
14 changes: 14 additions & 0 deletions src/agdb/query_builder/insert_nodes_aliases.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::query::insert_nodes_query::InsertNodesQuery;
use crate::query::query_id::QueryId;
use crate::query::query_ids::QueryIds;
use crate::query::query_values::QueryValues;
use crate::DbKeyValue;
use crate::Query;
Expand All @@ -17,4 +19,16 @@ impl InsertNodesAliases {

InsertNodesValues(self.0)
}

pub fn values_id(mut self, id: QueryId) -> InsertNodesValues {
self.0.values = QueryValues::Query(QueryIds::Id(id));

InsertNodesValues(self.0)
}

pub fn values_ids(mut self, ids: &[QueryId]) -> InsertNodesValues {
self.0.values = QueryValues::Query(QueryIds::Ids(ids.to_vec()));

InsertNodesValues(self.0)
}
}
17 changes: 17 additions & 0 deletions tests/insert_node_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,14 @@ fn insert_node_values() {
.query();
}

#[test]
fn insert_node_values_id() {
let _query = QueryBuilder::insert()
.node()
.values_id("alias".into())
.query();
}

#[test]
fn insert_node_alias_values() {
let _query = QueryBuilder::insert()
Expand All @@ -26,3 +34,12 @@ fn insert_node_alias_values() {
.values(&[("key", "value").into()])
.query();
}

#[test]
fn insert_node_alias_values_id() {
let _query = QueryBuilder::insert()
.node()
.alias("alias1")
.values_id("alias2".into())
.query();
}
34 changes: 34 additions & 0 deletions tests/insert_nodes_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,24 @@ fn insert_nodes_aliases_values() {
.query();
}

#[test]
fn insert_nodes_aliases_values_id() {
let _query = QueryBuilder::insert()
.nodes()
.aliases(&["alias1".to_string(), "alias2".to_string()])
.values_id("alias3".into())
.query();
}

#[test]
fn insert_nodes_aliases_values_ids() {
let _query = QueryBuilder::insert()
.nodes()
.aliases(&["alias1".to_string(), "alias2".to_string()])
.values_ids(&["alias3".into(), 4.into()])
.query();
}

#[test]
fn insert_nodes_count() {
let _query = QueryBuilder::insert().nodes().count(2).query();
Expand Down Expand Up @@ -57,3 +75,19 @@ fn insert_nodes_values() {
])
.query();
}

#[test]
fn insert_nodes_values_id() {
let _query = QueryBuilder::insert()
.nodes()
.values_id("alias3".into())
.query();
}

#[test]
fn insert_nodes_values_ids() {
let _query = QueryBuilder::insert()
.nodes()
.values_ids(&["alias3".into(), 4.into()])
.query();
}