agdb/query_builder/
remove.rs

1use crate::DbValue;
2use crate::QueryIds;
3use crate::RemoveAliasesQuery;
4use crate::RemoveQuery;
5use crate::RemoveValuesQuery;
6use crate::SearchQuery;
7use crate::SelectValuesQuery;
8use crate::db::db_value::DbValues;
9use crate::query::query_aliases::QueryAliases;
10use crate::query_builder::remove_aliases::RemoveAliases;
11use crate::query_builder::remove_ids::RemoveIds;
12use crate::query_builder::remove_index::RemoveIndex;
13use crate::query_builder::remove_values::RemoveValues;
14use crate::query_builder::search::Search;
15
16/// Remove builder to choose what to delete from the database.
17#[cfg_attr(feature = "api", derive(agdb::ApiDefImpl))]
18pub struct Remove {}
19
20#[cfg_attr(feature = "api", agdb::impl_def())]
21impl Remove {
22    /// List of aliases to delete from the database. It is not an error
23    /// if any of the aliases does not exist in the database.
24    pub fn aliases<T: Into<QueryAliases>>(self, names: T) -> RemoveAliases {
25        RemoveAliases(RemoveAliasesQuery(Into::<QueryAliases>::into(names).0))
26    }
27
28    /// Id, list of ids or search of the database elements to delete
29    /// from the database.
30    ///
31    /// NOTE: all properties (key-value pairs) associated
32    /// with the elements will be also deleted. If deleting nodes its outgoing
33    /// and incoming edges will also be deleted along with their properties.
34    ///
35    /// It is not an error if not all of the ids exist in the database.
36    pub fn ids<T: Into<QueryIds>>(self, ids: T) -> RemoveIds {
37        RemoveIds(RemoveQuery(ids.into()))
38    }
39
40    /// Index to be removed from the database.
41    pub fn index<T: Into<DbValue>>(self, key: T) -> RemoveIndex {
42        RemoveIndex(key.into())
43    }
44
45    /// Remove the elements found using the search query.
46    /// Equivalent to `ids(QueryIds::Search(search)/*...*/)`.
47    pub fn search(self) -> Search<RemoveQuery> {
48        Search(RemoveQuery(QueryIds::Search(SearchQuery::new())))
49    }
50
51    /// List of keys to delete from ids selected in the next step. It is not an
52    /// error if not all of the keys exist on the elements.
53    ///
54    /// Options:
55    ///
56    /// ```
57    /// use agdb::QueryBuilder;
58    ///
59    /// QueryBuilder::remove().values("k").ids(1);
60    /// QueryBuilder::remove().values("k").ids([1, 2]);
61    /// QueryBuilder::remove().values("k").ids(QueryBuilder::search().from(1).query());
62    /// ```
63    pub fn values<T: Into<DbValues>>(self, keys: T) -> RemoveValues {
64        RemoveValues(RemoveValuesQuery(SelectValuesQuery {
65            keys: Into::<DbValues>::into(keys).0,
66            ids: QueryIds::Ids(vec![]),
67        }))
68    }
69}