From 5299e096fd17bbb9eab5b4bb61352338c62bad8f Mon Sep 17 00:00:00 2001 From: Michael Vlach Date: Mon, 16 Sep 2024 22:29:43 +0200 Subject: [PATCH] [db] Allow aliases as slice or array #1273 (#1274) aliases from array or slice --- agdb/src/query.rs | 2 +- agdb/src/query/query_aliases.rs | 39 ++++++++++++++++--- agdb/src/query_builder.rs | 4 +- agdb/src/query_builder/insert.rs | 4 +- agdb/tests/db_test.rs | 6 +-- agdb/tests/efficient_agdb.rs | 2 +- agdb/tests/insert_aliases_test.rs | 6 +-- agdb/tests/insert_edges_test.rs | 18 ++++----- agdb/tests/insert_nodes_test.rs | 12 +++--- agdb/tests/insert_values_test.rs | 2 +- agdb/tests/remove_aliases_test.rs | 14 ++----- agdb/tests/remove_nodes_test.rs | 2 +- agdb/tests/remove_values_test.rs | 4 +- agdb/tests/search_where_test.rs | 4 +- agdb/tests/select_aliases_test.rs | 8 ++-- agdb/tests/select_edge_count_test.rs | 14 +++---- agdb/tests/select_test.rs | 4 +- agdb/tests/select_values_test.rs | 4 +- agdb_server/src/api.rs | 10 ++--- agdb_server/src/db_pool.rs | 2 +- .../routes/admin_db_backup_restore_test.rs | 6 +-- .../tests/routes/admin_db_copy_test.rs | 4 +- .../tests/routes/db_backup_restore_test.rs | 6 +-- agdb_server/tests/routes/db_copy_test.rs | 4 +- agdb_server/tests/routes/db_exec_test.rs | 2 +- .../docs/references/efficient-agdb.en-US.md | 2 +- .../pages/docs/references/queries.en-US.md | 10 ++--- examples/app_db/src/main.rs | 7 +--- examples/indexes/src/main.rs | 7 +--- examples/joins/src/main.rs | 2 +- examples/schema_migration/src/main.rs | 7 +--- examples/server_client_rust/src/main.rs | 2 +- examples/strong_types/src/main.rs | 7 +--- 33 files changed, 114 insertions(+), 113 deletions(-) diff --git a/agdb/src/query.rs b/agdb/src/query.rs index 107f16155..0520662c7 100644 --- a/agdb/src/query.rs +++ b/agdb/src/query.rs @@ -215,7 +215,7 @@ mod tests { let queries: Vec = vec![ QueryBuilder::insert().nodes().count(2).query().into(), QueryBuilder::insert() - .aliases(vec!["node1", "node2"]) + .aliases(["node1", "node2"]) .ids(vec![1, 2]) .query() .into(), diff --git a/agdb/src/query/query_aliases.rs b/agdb/src/query/query_aliases.rs index 2cdf2533f..e32a83b6b 100644 --- a/agdb/src/query/query_aliases.rs +++ b/agdb/src/query/query_aliases.rs @@ -3,15 +3,21 @@ /// [`QueryBuilder`]. pub struct QueryAliases(pub Vec); -impl From> for QueryAliases { - fn from(value: Vec) -> Self { - QueryAliases(value) +impl> From> for QueryAliases { + fn from(value: Vec) -> Self { + QueryAliases(value.into_iter().map(|v| v.into()).collect()) } } -impl From> for QueryAliases { - fn from(value: Vec<&str>) -> Self { - QueryAliases(value.iter().map(|v| v.to_string()).collect()) +impl + Clone> From<&[T]> for QueryAliases { + fn from(value: &[T]) -> Self { + QueryAliases(value.iter().map(|v| v.clone().into()).collect()) + } +} + +impl, const N: usize> From<[T; N]> for QueryAliases { + fn from(value: [T; N]) -> Self { + QueryAliases(value.into_iter().map(|v| v.into()).collect()) } } @@ -26,3 +32,24 @@ impl From for QueryAliases { QueryAliases(vec![value]) } } + +impl From<&String> for QueryAliases { + fn from(value: &String) -> Self { + QueryAliases(vec![value.clone()]) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn query_aliases() { + let _aliases = QueryAliases::from(vec!["a".to_string()]); + let _aliases = QueryAliases::from(["a", "b"]); + let _aliases = QueryAliases::from(["a", "b"].as_slice()); + let _aliases = QueryAliases::from("a"); + let _aliases = QueryAliases::from("a".to_string()); + let _aliases = QueryAliases::from(&"a".to_string()); + } +} diff --git a/agdb/src/query_builder.rs b/agdb/src/query_builder.rs index e43023d7c..a7c3fbbc9 100644 --- a/agdb/src/query_builder.rs +++ b/agdb/src/query_builder.rs @@ -54,7 +54,7 @@ impl QueryBuilder { /// QueryBuilder::insert().nodes(); /// QueryBuilder::insert().edges(); /// QueryBuilder::insert().aliases("a"); - /// QueryBuilder::insert().aliases(vec!["a", "b"]); + /// QueryBuilder::insert().aliases(["a", "b"]); /// QueryBuilder::insert().element(&MyValue { db_id: Some(DbId(1)), key: "a".to_string(), }); /// QueryBuilder::insert().elements(&[MyValue { db_id: Some(DbId(1)), key: "a".to_string(), }]); /// QueryBuilder::insert().index("k"); @@ -77,7 +77,7 @@ impl QueryBuilder { /// QueryBuilder::remove().ids(QueryBuilder::search().from(1).query()); /// QueryBuilder::remove().index("k"); /// QueryBuilder::remove().aliases("a"); - /// QueryBuilder::remove().aliases(vec!["a", "b"]); + /// QueryBuilder::remove().aliases(["a", "b"]); /// QueryBuilder::remove().values(vec!["k".into()]); /// ``` pub fn remove() -> Remove { diff --git a/agdb/src/query_builder/insert.rs b/agdb/src/query_builder/insert.rs index 246367c27..cfffe806f 100644 --- a/agdb/src/query_builder/insert.rs +++ b/agdb/src/query_builder/insert.rs @@ -29,7 +29,7 @@ impl Insert { /// use agdb::QueryBuilder; /// /// QueryBuilder::insert().aliases("a").ids(1); - /// QueryBuilder::insert().aliases(vec!["a", "b"]).ids(vec![1, 2]); + /// QueryBuilder::insert().aliases(["a", "b"]).ids(vec![1, 2]); /// ``` pub fn aliases>(self, names: T) -> InsertAliases { InsertAliases(InsertAliasesQuery { @@ -110,7 +110,7 @@ impl Insert { /// /// QueryBuilder::insert().nodes().count(1); /// QueryBuilder::insert().nodes().aliases("a"); - /// QueryBuilder::insert().nodes().aliases(vec!["a", "b"]); + /// QueryBuilder::insert().nodes().aliases(["a", "b"]); /// QueryBuilder::insert().nodes().ids(1); /// QueryBuilder::insert().nodes().ids(vec![1, 2]); /// QueryBuilder::insert().nodes().ids("a"); diff --git a/agdb/tests/db_test.rs b/agdb/tests/db_test.rs index 41a78a8b7..557a03a76 100644 --- a/agdb/tests/db_test.rs +++ b/agdb/tests/db_test.rs @@ -102,7 +102,7 @@ fn data_persistence() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias", "alias2"]) + .aliases(["alias", "alias2"]) .values_uniform(values.clone()) .query(), ) @@ -185,7 +185,7 @@ fn data_remove_persistence() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias", "alias2"]) + .aliases(["alias", "alias2"]) .values_uniform(vec![("key", 100).into()]) .query(), ) @@ -493,7 +493,7 @@ fn queries_as_reference() { let query = QueryBuilder::insert() .nodes() - .aliases(vec!["root", "users"]) + .aliases(["root", "users"]) .query(); db.exec_mut(&query).unwrap(); diff --git a/agdb/tests/efficient_agdb.rs b/agdb/tests/efficient_agdb.rs index 8bc8bf92d..d6ec4313c 100644 --- a/agdb/tests/efficient_agdb.rs +++ b/agdb/tests/efficient_agdb.rs @@ -50,7 +50,7 @@ fn create_db() -> Result>, QueryError> { t.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["root", "users", "posts"]) + .aliases(["root", "users", "posts"]) .query(), )?; t.exec_mut( diff --git a/agdb/tests/insert_aliases_test.rs b/agdb/tests/insert_aliases_test.rs index 9b8de04f5..17d75c0c6 100644 --- a/agdb/tests/insert_aliases_test.rs +++ b/agdb/tests/insert_aliases_test.rs @@ -11,7 +11,7 @@ fn insert_aliases_of() { db.exec_mut(QueryBuilder::insert().nodes().count(2).query(), 2); db.exec_mut( QueryBuilder::insert() - .aliases(vec![String::from("alias"), String::from("alias2")]) + .aliases([String::from("alias"), String::from("alias2")]) .ids(vec![1, 2]) .query(), 2, @@ -25,7 +25,7 @@ fn insert_aliases_of_alias() { db.exec_mut(QueryBuilder::insert().nodes().count(1).query(), 1); db.exec_mut( QueryBuilder::insert() - .aliases(vec!["alias1", "alias2"]) + .aliases(["alias1", "alias2"]) .ids(vec![QueryId::from("alias"), 2.into()]) .query(), 2, @@ -41,7 +41,7 @@ fn insert_aliases_rollback() { |t| -> Result<(), QueryError> { t.exec_mut( QueryBuilder::insert() - .aliases(vec!["alias1", "alias2"]) + .aliases(["alias1", "alias2"]) .ids(vec![QueryId::from("alias"), 2.into()]) .query(), )?; diff --git a/agdb/tests/insert_edges_test.rs b/agdb/tests/insert_edges_test.rs index e339be8f6..fc018d32b 100644 --- a/agdb/tests/insert_edges_test.rs +++ b/agdb/tests/insert_edges_test.rs @@ -38,7 +38,7 @@ fn insert_edges_from_to() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2", "alias3", "alias4"]) + .aliases(["alias1", "alias2", "alias3", "alias4"]) .query(), 4, ); @@ -59,7 +59,7 @@ fn insert_edges_from_to_each() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2", "alias3"]) + .aliases(["alias1", "alias2", "alias3"]) .query(), 3, ); @@ -79,7 +79,7 @@ fn insert_edges_from_to_values() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2", "alias3", "alias4"]) + .aliases(["alias1", "alias2", "alias3", "alias4"]) .query(), 4, ); @@ -120,7 +120,7 @@ fn insert_edges_from_to_each_values() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2", "alias3", "alias4"]) + .aliases(["alias1", "alias2", "alias3", "alias4"]) .query(), 4, ); @@ -176,7 +176,7 @@ fn insert_edges_from_to_each_values_uniform() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2", "alias3", "alias4"]) + .aliases(["alias1", "alias2", "alias3", "alias4"]) .query(), 4, ); @@ -227,7 +227,7 @@ fn insert_edges_from_to_values_bad_length() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2", "alias3", "alias4"]) + .aliases(["alias1", "alias2", "alias3", "alias4"]) .query(), 4, ); @@ -248,7 +248,7 @@ fn insert_edges_from_to_values_each_bad_length() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2", "alias3", "alias4"]) + .aliases(["alias1", "alias2", "alias3", "alias4"]) .query(), 4, ); @@ -270,7 +270,7 @@ fn insert_edges_from_to_values_asymmetric() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2", "alias3"]) + .aliases(["alias1", "alias2", "alias3"]) .query(), 3, ); @@ -311,7 +311,7 @@ fn insert_edges_from_to_values_uniform() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2", "alias3"]) + .aliases(["alias1", "alias2", "alias3"]) .query(), 3, ); diff --git a/agdb/tests/insert_nodes_test.rs b/agdb/tests/insert_nodes_test.rs index 583fabf68..00459275a 100644 --- a/agdb/tests/insert_nodes_test.rs +++ b/agdb/tests/insert_nodes_test.rs @@ -41,7 +41,7 @@ fn insert_nodes_aliases() { db.exec_mut_ids( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2"]) + .aliases(["alias1", "alias2"]) .query(), &[1, 2], ); @@ -59,7 +59,7 @@ fn insert_nodes_aliases_values() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2"]) + .aliases(["alias1", "alias2"]) .values(vec![ vec![("key", "value").into(), ("key2", "value2").into()], vec![("key", "value3").into()], @@ -95,7 +95,7 @@ fn insert_nodes_aliases_values_rollback() { .exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2"]) + .aliases(["alias1", "alias2"]) .values(vec![ vec![("key", "value").into(), ("key2", "value2").into()], vec![("key", "value3").into()], @@ -143,7 +143,7 @@ fn insert_nodes_aliases_values_uniform() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2"]) + .aliases(["alias1", "alias2"]) .values_uniform(vec![("key", "value").into(), ("key2", "value2").into()]) .query(), 2, @@ -243,7 +243,7 @@ fn insert_nodes_existing_aliases_values() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["new_alias", "alias", "alias3"]) + .aliases(["new_alias", "alias", "alias3"]) .values(vec![ vec![("some_key", "value").into()], vec![("key", 10).into(), ("new_key", 100).into()], @@ -279,7 +279,7 @@ fn insert_nodes_aliases_values_mismatched_length() { db.exec_mut_error( QueryBuilder::insert() .nodes() - .aliases(vec!["alias", "alias2"]) + .aliases(["alias", "alias2"]) .values(vec![vec![("key", 1).into()]]) .query(), "Aliases (2) and values (1) must have compatible lenghts (2 <= 1)", diff --git a/agdb/tests/insert_values_test.rs b/agdb/tests/insert_values_test.rs index 39185efbb..1beb06547 100644 --- a/agdb/tests/insert_values_test.rs +++ b/agdb/tests/insert_values_test.rs @@ -111,7 +111,7 @@ fn insert_values_uniform_ids() { db.exec_mut_ids( QueryBuilder::insert() .nodes() - .aliases(vec!["alias", "alias2"]) + .aliases(["alias", "alias2"]) .query(), &[1, 2], ); diff --git a/agdb/tests/remove_aliases_test.rs b/agdb/tests/remove_aliases_test.rs index 3b1e89a2f..3fc0e11df 100644 --- a/agdb/tests/remove_aliases_test.rs +++ b/agdb/tests/remove_aliases_test.rs @@ -11,14 +11,12 @@ fn remove_aliases() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias", "alias2"]) + .aliases(["alias", "alias2"]) .query(), 2, ); db.exec_mut( - QueryBuilder::remove() - .aliases(vec!["alias", "alias2"]) - .query(), + QueryBuilder::remove().aliases(["alias", "alias2"]).query(), -2, ); } @@ -29,18 +27,14 @@ fn remove_aliases_rollback() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias", "alias2"]) + .aliases(["alias", "alias2"]) .query(), 2, ); db.transaction_mut_error( |t| -> Result { - t.exec_mut( - QueryBuilder::remove() - .aliases(vec!["alias", "alias2"]) - .query(), - )?; + t.exec_mut(QueryBuilder::remove().aliases(["alias", "alias2"]).query())?; t.exec(QueryBuilder::select().ids("alias2").query()) }, "Alias 'alias2' not found".into(), diff --git a/agdb/tests/remove_nodes_test.rs b/agdb/tests/remove_nodes_test.rs index 5a73dca61..df6ae5387 100644 --- a/agdb/tests/remove_nodes_test.rs +++ b/agdb/tests/remove_nodes_test.rs @@ -28,7 +28,7 @@ fn remove_nodes() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias", "alias2"]) + .aliases(["alias", "alias2"]) .query(), 2, ); diff --git a/agdb/tests/remove_values_test.rs b/agdb/tests/remove_values_test.rs index da4cdda34..709691977 100644 --- a/agdb/tests/remove_values_test.rs +++ b/agdb/tests/remove_values_test.rs @@ -11,7 +11,7 @@ fn remove_values_ids() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias", "alias2"]) + .aliases(["alias", "alias2"]) .values_uniform(vec![("key1", "value1").into()]) .query(), 2, @@ -102,7 +102,7 @@ fn remove_missing_key() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias", "alias2"]) + .aliases(["alias", "alias2"]) .values_uniform(vec![("key1", "value1").into(), ("key2", 100).into()]) .query(), 2, diff --git a/agdb/tests/search_where_test.rs b/agdb/tests/search_where_test.rs index 98a2ba5b3..34f607d4a 100644 --- a/agdb/tests/search_where_test.rs +++ b/agdb/tests/search_where_test.rs @@ -13,7 +13,7 @@ fn create_db() -> TestDb { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["root", "users", "docs"]) + .aliases(["root", "users", "docs"]) .query(), 3, ); @@ -477,7 +477,7 @@ fn search_from_to_where_filter() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["start", "end"]) + .aliases(["start", "end"]) .query(), 2, ); diff --git a/agdb/tests/select_aliases_test.rs b/agdb/tests/select_aliases_test.rs index f8ec2c631..6881ad1e7 100644 --- a/agdb/tests/select_aliases_test.rs +++ b/agdb/tests/select_aliases_test.rs @@ -29,7 +29,7 @@ fn select_aliases_ids() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2"]) + .aliases(["alias1", "alias2"]) .query(), 2, ); @@ -58,7 +58,7 @@ fn select_aliases_aliases() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2"]) + .aliases(["alias1", "alias2"]) .query(), 2, ); @@ -91,7 +91,7 @@ fn select_aliases_search() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2", "alias3", "alias4", "alias5"]) + .aliases(["alias1", "alias2", "alias3", "alias4", "alias5"]) .query(), 5, ); @@ -143,7 +143,7 @@ fn select_all_aliases() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2", "alias3"]) + .aliases(["alias1", "alias2", "alias3"]) .query(), 3, ); diff --git a/agdb/tests/select_edge_count_test.rs b/agdb/tests/select_edge_count_test.rs index 37b786085..13dcd8315 100644 --- a/agdb/tests/select_edge_count_test.rs +++ b/agdb/tests/select_edge_count_test.rs @@ -13,7 +13,7 @@ fn select_edge_count_ids() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["from", "to"]) + .aliases(["from", "to"]) .query(), 2, ); @@ -49,7 +49,7 @@ fn select_edge_count_from_ids() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["from", "to"]) + .aliases(["from", "to"]) .query(), 2, ); @@ -85,7 +85,7 @@ fn select_edge_count_to_ids() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["from", "to"]) + .aliases(["from", "to"]) .query(), 2, ); @@ -121,7 +121,7 @@ fn select_edge_count_multi() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["node1", "node2", "node3"]) + .aliases(["node1", "node2", "node3"]) .query(), 3, ); @@ -168,7 +168,7 @@ fn select_edge_count_search() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["node1", "node2", "node3"]) + .aliases(["node1", "node2", "node3"]) .query(), 3, ); @@ -207,7 +207,7 @@ fn select_edge_count_non_nodes() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["from", "to"]) + .aliases(["from", "to"]) .query(), 2, ); @@ -233,7 +233,7 @@ fn select_edge_count_invalid_query() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["from", "to"]) + .aliases(["from", "to"]) .query(), 2, ); diff --git a/agdb/tests/select_test.rs b/agdb/tests/select_test.rs index 0d75e9e72..8d6505bac 100644 --- a/agdb/tests/select_test.rs +++ b/agdb/tests/select_test.rs @@ -16,7 +16,7 @@ fn select_from_ids() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias", "alias2"]) + .aliases(["alias", "alias2"]) .query(), 2, ); @@ -54,7 +54,7 @@ fn select_from_search() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2", "alias3", "alias4", "alias5"]) + .aliases(["alias1", "alias2", "alias3", "alias4", "alias5"]) .query(), 5, ); diff --git a/agdb/tests/select_values_test.rs b/agdb/tests/select_values_test.rs index 4c015d1a4..21ad30a8a 100644 --- a/agdb/tests/select_values_test.rs +++ b/agdb/tests/select_values_test.rs @@ -11,7 +11,7 @@ fn select_values_ids() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2"]) + .aliases(["alias1", "alias2"]) .values(vec![ vec![ ("key", "value").into(), @@ -55,7 +55,7 @@ fn select_values_ids_missing_key() { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["alias1", "alias2"]) + .aliases(["alias1", "alias2"]) .values(vec![ vec![ ("key", "value").into(), diff --git a/agdb_server/src/api.rs b/agdb_server/src/api.rs index 8558edbb4..d62cbf58e 100644 --- a/agdb_server/src/api.rs +++ b/agdb_server/src/api.rs @@ -174,7 +174,7 @@ mod tests { let queries = queries![ QueryBuilder::insert().aliases("a").ids(1).query(), QueryBuilder::insert().aliases("a").ids("b").query(), -QueryBuilder::insert().aliases(vec!["a", "b"]).ids(vec![1, 2]).query(), +QueryBuilder::insert().aliases(["a", "b"]).ids(vec![1, 2]).query(), QueryBuilder::insert().edges().from(1).to(2).query(), QueryBuilder::insert().edges().from("a").to("b").query(), QueryBuilder::insert().edges().from("a").to(vec![1, 2]).query(), @@ -193,9 +193,9 @@ QueryBuilder::insert().edges().ids(QueryBuilder::search().from(1).where_().edge( QueryBuilder::insert().index("key").query(), QueryBuilder::insert().nodes().count(2).query(), QueryBuilder::insert().nodes().count(2).values_uniform(vec![("k", "v").into(), (1, 10).into()]).query(), -QueryBuilder::insert().nodes().aliases(vec!["a", "b"]).query(), -QueryBuilder::insert().nodes().aliases(vec!["a", "b"]).values(vec![vec![("k", 1).into()], vec![("k", 2).into()]]).query(), -QueryBuilder::insert().nodes().aliases(vec!["a", "b"]).values_uniform(vec![("k", "v").into(), (1, 10).into()]).query(), +QueryBuilder::insert().nodes().aliases(["a", "b"]).query(), +QueryBuilder::insert().nodes().aliases(["a", "b"]).values(vec![vec![("k", 1).into()], vec![("k", 2).into()]]).query(), +QueryBuilder::insert().nodes().aliases(["a", "b"]).values_uniform(vec![("k", "v").into(), (1, 10).into()]).query(), QueryBuilder::insert().nodes().values(vec![vec![("k", 1).into()], vec![("k", 2).into()]]).query(), QueryBuilder::insert().nodes().ids(1).count(1).query(), QueryBuilder::insert().nodes().ids(vec![1, 2]).count(1).query(), @@ -212,7 +212,7 @@ QueryBuilder::insert().values(vec![vec![("k", "v").into(), (1, 10).into()], vec! QueryBuilder::insert().values_uniform(vec![("k", "v").into(), (1, 10).into()]).ids(vec![1, 2]).query(), QueryBuilder::insert().values_uniform(vec![("k", "v").into(), (1, 10).into()]).ids(QueryBuilder::search().from("a").query()).query(), QueryBuilder::remove().aliases("a").query(), -QueryBuilder::remove().aliases(vec!["a", "b"]).query(), +QueryBuilder::remove().aliases(["a", "b"]).query(), QueryBuilder::remove().ids(1).query(), QueryBuilder::remove().ids("a").query(), QueryBuilder::remove().ids(vec![1, 2]).query(), diff --git a/agdb_server/src/db_pool.rs b/agdb_server/src/db_pool.rs index ed5121e9d..e09a83d5c 100644 --- a/agdb_server/src/db_pool.rs +++ b/agdb_server/src/db_pool.rs @@ -122,7 +122,7 @@ impl DbPool { t.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["users", "dbs"]) + .aliases(["users", "dbs"]) .query(), )?; diff --git a/agdb_server/tests/routes/admin_db_backup_restore_test.rs b/agdb_server/tests/routes/admin_db_backup_restore_test.rs index 367cf72b8..c38463174 100644 --- a/agdb_server/tests/routes/admin_db_backup_restore_test.rs +++ b/agdb_server/tests/routes/admin_db_backup_restore_test.rs @@ -17,7 +17,7 @@ async fn backup() -> anyhow::Result<()> { server.api.admin_db_add(owner, db, DbType::Mapped).await?; let queries = &vec![QueryBuilder::insert() .nodes() - .aliases(vec!["root"]) + .aliases(["root"]) .query() .into()]; server.api.admin_db_exec(owner, db, queries).await?; @@ -59,7 +59,7 @@ async fn backup_overwrite() -> anyhow::Result<()> { server.api.admin_db_add(owner, db, DbType::Mapped).await?; let queries = &vec![QueryBuilder::insert() .nodes() - .aliases(vec!["root"]) + .aliases(["root"]) .query() .into()]; server.api.admin_db_exec(owner, db, queries).await?; @@ -102,7 +102,7 @@ async fn backup_of_backup() -> anyhow::Result<()> { server.api.admin_db_add(owner, db, DbType::Mapped).await?; let queries = &vec![QueryBuilder::insert() .nodes() - .aliases(vec!["root"]) + .aliases(["root"]) .query() .into()]; server.api.admin_db_exec(owner, db, queries).await?; diff --git a/agdb_server/tests/routes/admin_db_copy_test.rs b/agdb_server/tests/routes/admin_db_copy_test.rs index 888aac911..1369e309f 100644 --- a/agdb_server/tests/routes/admin_db_copy_test.rs +++ b/agdb_server/tests/routes/admin_db_copy_test.rs @@ -17,7 +17,7 @@ async fn copy() -> anyhow::Result<()> { server.api.admin_db_add(owner, db, DbType::Mapped).await?; let queries = &vec![QueryBuilder::insert() .nodes() - .aliases(vec!["root"]) + .aliases(["root"]) .query() .into()]; server.api.admin_db_exec(owner, db, queries).await?; @@ -53,7 +53,7 @@ async fn copy_to_different_user() -> anyhow::Result<()> { server.api.admin_db_add(owner, db, DbType::Mapped).await?; let queries = &vec![QueryBuilder::insert() .nodes() - .aliases(vec!["root"]) + .aliases(["root"]) .query() .into()]; server.api.admin_db_exec(owner, db, queries).await?; diff --git a/agdb_server/tests/routes/db_backup_restore_test.rs b/agdb_server/tests/routes/db_backup_restore_test.rs index 537136da9..dfbb6144a 100644 --- a/agdb_server/tests/routes/db_backup_restore_test.rs +++ b/agdb_server/tests/routes/db_backup_restore_test.rs @@ -19,7 +19,7 @@ async fn backup() -> anyhow::Result<()> { server.api.db_add(owner, db, DbType::Mapped).await?; let queries = &vec![QueryBuilder::insert() .nodes() - .aliases(vec!["root"]) + .aliases(["root"]) .query() .into()]; server.api.db_exec(owner, db, queries).await?; @@ -62,7 +62,7 @@ async fn backup_overwrite() -> anyhow::Result<()> { server.api.db_add(owner, db, DbType::Mapped).await?; let queries = &vec![QueryBuilder::insert() .nodes() - .aliases(vec!["root"]) + .aliases(["root"]) .query() .into()]; server.api.db_exec(owner, db, queries).await?; @@ -106,7 +106,7 @@ async fn backup_of_backup() -> anyhow::Result<()> { server.api.db_add(owner, db, DbType::Mapped).await?; let queries = &vec![QueryBuilder::insert() .nodes() - .aliases(vec!["root"]) + .aliases(["root"]) .query() .into()]; server.api.db_exec(owner, db, queries).await?; diff --git a/agdb_server/tests/routes/db_copy_test.rs b/agdb_server/tests/routes/db_copy_test.rs index c16c67fb8..6a4f5bf20 100644 --- a/agdb_server/tests/routes/db_copy_test.rs +++ b/agdb_server/tests/routes/db_copy_test.rs @@ -19,7 +19,7 @@ async fn copy() -> anyhow::Result<()> { server.api.db_add(owner, db, DbType::Mapped).await?; let queries = &vec![QueryBuilder::insert() .nodes() - .aliases(vec!["root"]) + .aliases(["root"]) .query() .into()]; server.api.db_exec(owner, db, queries).await?; @@ -59,7 +59,7 @@ async fn copy_from_different_user() -> anyhow::Result<()> { .await?; let queries = &vec![QueryBuilder::insert() .nodes() - .aliases(vec!["root"]) + .aliases(["root"]) .query() .into()]; server.api.admin_db_exec(owner, db, queries).await?; diff --git a/agdb_server/tests/routes/db_exec_test.rs b/agdb_server/tests/routes/db_exec_test.rs index ebd7d46bf..8e13546a5 100644 --- a/agdb_server/tests/routes/db_exec_test.rs +++ b/agdb_server/tests/routes/db_exec_test.rs @@ -137,7 +137,7 @@ async fn write_queries() -> anyhow::Result<()> { let queries = &vec![ QueryBuilder::insert().nodes().count(2).query().into(), QueryBuilder::insert() - .aliases(vec!["node1", "node2"]) + .aliases(["node1", "node2"]) .ids(vec![1, 2]) .query() .into(), diff --git a/agdb_web/pages/docs/references/efficient-agdb.en-US.md b/agdb_web/pages/docs/references/efficient-agdb.en-US.md index 943b991a0..dee48690c 100644 --- a/agdb_web/pages/docs/references/efficient-agdb.en-US.md +++ b/agdb_web/pages/docs/references/efficient-agdb.en-US.md @@ -18,7 +18,7 @@ fn create_db() -> Result>, QueryError> { t.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["root", "users", "posts"]) + .aliases(["root", "users", "posts"]) .query(), )?; t.exec_mut( diff --git a/agdb_web/pages/docs/references/queries.en-US.md b/agdb_web/pages/docs/references/queries.en-US.md index d6ac70d79..448ce09ff 100644 --- a/agdb_web/pages/docs/references/queries.en-US.md +++ b/agdb_web/pages/docs/references/queries.en-US.md @@ -362,7 +362,7 @@ pub struct QueryResult { ```rs QueryBuilder::insert().aliases("a").ids(1).query(); QueryBuilder::insert().aliases("a").ids("b").query(); // alias "b" is replaced with "a" -QueryBuilder::insert().aliases(vec!["a", "b"]).ids(vec![1, 2]).query(); +QueryBuilder::insert().aliases(["a", "b"]).ids(vec![1, 2]).query(); ``` @@ -473,9 +473,9 @@ pub struct QueryResult { ```rs QueryBuilder::insert().nodes().count(2).query(); QueryBuilder::insert().nodes().count(2).values_uniform(vec![("k", "v").into(), (1, 10).into()]).query(); -QueryBuilder::insert().nodes().aliases(vec!["a", "b"]).query(); -QueryBuilder::insert().nodes().aliases(vec!["a", "b"]).values(vec![vec![("k", 1).into()], vec![("k", 2).into()]]).query(); -QueryBuilder::insert().nodes().aliases(vec!["a", "b"]).values_uniform(vec![("k", "v").into(), (1, 10).into()]).query(); +QueryBuilder::insert().nodes().aliases(["a", "b"]).query(); +QueryBuilder::insert().nodes().aliases(["a", "b"]).values(vec![vec![("k", 1).into()], vec![("k", 2).into()]]).query(); +QueryBuilder::insert().nodes().aliases(["a", "b"]).values_uniform(vec![("k", "v").into(), (1, 10).into()]).query(); QueryBuilder::insert().nodes().values(vec![vec![("k", 1).into()], vec![("k", 2).into()]]).query(); QueryBuilder::insert().nodes().ids(1).count(1).query(); QueryBuilder::insert().nodes().ids(vec![1, 2]).count(1).query(); @@ -565,7 +565,7 @@ pub struct QueryResult { ```rs QueryBuilder::remove().aliases("a").query(); -QueryBuilder::remove().aliases(vec!["a", "b"]).query(); +QueryBuilder::remove().aliases(["a", "b"]).query(); ``` diff --git a/examples/app_db/src/main.rs b/examples/app_db/src/main.rs index 7fe3d358b..0c89b36fb 100644 --- a/examples/app_db/src/main.rs +++ b/examples/app_db/src/main.rs @@ -9,12 +9,7 @@ fn main() -> Result<(), QueryError> { // Inserts root node for users with an alias. You can loosely // think of it akin to a table in relational databases. - db.exec_mut( - QueryBuilder::insert() - .nodes() - .aliases(vec!["users"]) - .query(), - )?; + db.exec_mut(QueryBuilder::insert().nodes().aliases(["users"]).query())?; // Inserts the raw data by providing list of keys and values // for each node. Notice we can easily create sparse data diff --git a/examples/indexes/src/main.rs b/examples/indexes/src/main.rs index 215f01454..00a149d24 100644 --- a/examples/indexes/src/main.rs +++ b/examples/indexes/src/main.rs @@ -24,12 +24,7 @@ fn main() -> Result<(), QueryError> { // Inserts root node for users with an alias. You can loosely // think of it akin to a table in relational databases. - db.exec_mut( - QueryBuilder::insert() - .nodes() - .aliases(vec!["users"]) - .query(), - )?; + db.exec_mut(QueryBuilder::insert().nodes().aliases(["users"]).query())?; // Create many users tied to the users node with keys "username" and "token" // so they get registered into the indexes. Note that indexes can be created diff --git a/examples/joins/src/main.rs b/examples/joins/src/main.rs index 94df4453e..f2dadbd61 100644 --- a/examples/joins/src/main.rs +++ b/examples/joins/src/main.rs @@ -18,7 +18,7 @@ fn main() -> Result<(), QueryError> { db.exec_mut( QueryBuilder::insert() .nodes() - .aliases(vec!["user", "dbs"]) + .aliases(["user", "dbs"]) .query(), )?; diff --git a/examples/schema_migration/src/main.rs b/examples/schema_migration/src/main.rs index 07d1b236d..8cebd4251 100644 --- a/examples/schema_migration/src/main.rs +++ b/examples/schema_migration/src/main.rs @@ -55,12 +55,7 @@ fn main() -> Result<(), QueryError> { let mut db = DbMemory::new("agdb_example")?; // Inserts root nodes for users. - db.exec_mut( - QueryBuilder::insert() - .nodes() - .aliases(vec!["users"]) - .query(), - )?; + db.exec_mut(QueryBuilder::insert().nodes().aliases(["users"]).query())?; let mut users = vec![]; diff --git a/examples/server_client_rust/src/main.rs b/examples/server_client_rust/src/main.rs index 86f66b82b..32b361960 100644 --- a/examples/server_client_rust/src/main.rs +++ b/examples/server_client_rust/src/main.rs @@ -42,7 +42,7 @@ async fn main() -> Result<(), anyhow::Error> { let queries = vec![ QueryBuilder::insert() .nodes() - .aliases(vec!["users"]) + .aliases(["users"]) .query() .into(), QueryBuilder::insert().nodes().values(&users).query().into(), diff --git a/examples/strong_types/src/main.rs b/examples/strong_types/src/main.rs index 8abd78fb2..73f427b8c 100644 --- a/examples/strong_types/src/main.rs +++ b/examples/strong_types/src/main.rs @@ -61,12 +61,7 @@ fn main() -> Result<(), QueryError> { // Inserts root node for users with an alias. You can loosely // think of it akin to a table in relational databases. - db.exec_mut( - QueryBuilder::insert() - .nodes() - .aliases(vec!["users"]) - .query(), - )?; + db.exec_mut(QueryBuilder::insert().nodes().aliases(["users"]).query())?; // Prepare some data to be inserted into the database. In this // case a couple of users.