diff --git a/src/agdb/query_builder.rs b/src/agdb/query_builder.rs index d623ef949..6609de00f 100644 --- a/src/agdb/query_builder.rs +++ b/src/agdb/query_builder.rs @@ -36,6 +36,8 @@ mod select_aliases_of; mod select_id; mod select_id_from; mod select_id_to; +mod select_key_count; +mod select_key_count_from; mod select_limit; mod select_offset; diff --git a/src/agdb/query_builder/select.rs b/src/agdb/query_builder/select.rs index eacd1162d..e9900d5c0 100644 --- a/src/agdb/query_builder/select.rs +++ b/src/agdb/query_builder/select.rs @@ -2,10 +2,12 @@ use super::search::Search; use super::select_alias::SelectAlias; use super::select_aliases::SelectAliases; use super::select_id::SelectId; +use super::select_key_count::SelectKeyCount; use crate::query::query_id::QueryId; use crate::query::query_ids::QueryIds; use crate::query::search_query::SearchQuery; use crate::query::select_aliases_query::SelectAliasesQuery; +use crate::query::select_key_count_query::SelectKeyCountQuery; pub struct Select {} @@ -54,4 +56,8 @@ impl Select { conditions: vec![], }) } + + pub fn key_count(self) -> SelectKeyCount { + SelectKeyCount(SelectKeyCountQuery(QueryIds::Id(0.into()))) + } } diff --git a/src/agdb/query_builder/select_key_count.rs b/src/agdb/query_builder/select_key_count.rs new file mode 100644 index 000000000..e36508476 --- /dev/null +++ b/src/agdb/query_builder/select_key_count.rs @@ -0,0 +1,30 @@ +use super::select_key_count_from::SelectKeyCountFrom; +use crate::query::query_id::QueryId; +use crate::query::query_ids::QueryIds; +use crate::query::search_query::SearchQuery; +use crate::query::select_key_count_query::SelectKeyCountQuery; + +pub struct SelectKeyCount(pub SelectKeyCountQuery); + +impl SelectKeyCount { + #[allow(clippy::wrong_self_convention)] + pub fn from(mut self, id: QueryId) -> SelectKeyCountFrom { + self.0 .0 = QueryIds::Id(id); + + SelectKeyCountFrom(self.0) + } + + #[allow(clippy::wrong_self_convention)] + pub fn from_ids(mut self, ids: &[QueryId]) -> SelectKeyCountFrom { + self.0 .0 = QueryIds::Ids(ids.to_vec()); + + SelectKeyCountFrom(self.0) + } + + #[allow(clippy::wrong_self_convention)] + pub fn from_query(mut self, query: SearchQuery) -> SelectKeyCountFrom { + self.0 .0 = QueryIds::Search(query); + + SelectKeyCountFrom(self.0) + } +} diff --git a/src/agdb/query_builder/select_key_count_from.rs b/src/agdb/query_builder/select_key_count_from.rs new file mode 100644 index 000000000..e538e754f --- /dev/null +++ b/src/agdb/query_builder/select_key_count_from.rs @@ -0,0 +1,9 @@ +use crate::query::select_key_count_query::SelectKeyCountQuery; + +pub struct SelectKeyCountFrom(pub SelectKeyCountQuery); + +impl SelectKeyCountFrom { + pub fn query(self) -> SelectKeyCountQuery { + self.0 + } +} diff --git a/tests/select_key_count_test.rs b/tests/select_key_count_test.rs new file mode 100644 index 000000000..1b0cadff4 --- /dev/null +++ b/tests/select_key_count_test.rs @@ -0,0 +1,25 @@ +use agdb::QueryBuilder; + +#[test] +fn select_key_count_from() { + let _query = QueryBuilder::select() + .key_count() + .from("alias".into()) + .query(); +} + +#[test] +fn select_key_count_from_ids() { + let _query = QueryBuilder::select() + .key_count() + .from_ids(&["alias".into()]) + .query(); +} + +#[test] +fn select_key_count_from_query() { + let _query = QueryBuilder::select() + .key_count() + .from_query(QueryBuilder::select().id().from("alias".into()).query()) + .query(); +}