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 select key count #425 #426

Merged
merged 2 commits into from
Jan 9, 2023
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
2 changes: 2 additions & 0 deletions src/agdb/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
6 changes: 6 additions & 0 deletions src/agdb/query_builder/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {}

Expand Down Expand Up @@ -54,4 +56,8 @@ impl Select {
conditions: vec![],
})
}

pub fn key_count(self) -> SelectKeyCount {
SelectKeyCount(SelectKeyCountQuery(QueryIds::Id(0.into())))
}
}
30 changes: 30 additions & 0 deletions src/agdb/query_builder/select_key_count.rs
Original file line number Diff line number Diff line change
@@ -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)
}
}
9 changes: 9 additions & 0 deletions src/agdb/query_builder/select_key_count_from.rs
Original file line number Diff line number Diff line change
@@ -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
}
}
25 changes: 25 additions & 0 deletions tests/select_key_count_test.rs
Original file line number Diff line number Diff line change
@@ -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();
}