Skip to content

Commit

Permalink
[query] Add select keys #427 (#428)
Browse files Browse the repository at this point in the history
* Create select_keys.rs

* add select_keys
  • Loading branch information
michaelvlach authored Jan 10, 2023
1 parent 0a030c2 commit c4510fb
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/agdb/query_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ mod select_id_from;
mod select_id_to;
mod select_key_count;
mod select_key_count_from;
mod select_keys;
mod select_keys_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 @@ -3,11 +3,13 @@ use super::select_alias::SelectAlias;
use super::select_aliases::SelectAliases;
use super::select_id::SelectId;
use super::select_key_count::SelectKeyCount;
use super::select_keys::SelectKeys;
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;
use crate::query::select_keys_query::SelectKeysQuery;

pub struct Select {}

Expand Down Expand Up @@ -57,6 +59,10 @@ impl Select {
})
}

pub fn keys(self) -> SelectKeys {
SelectKeys(SelectKeysQuery(QueryIds::Id(0.into())))
}

pub fn key_count(self) -> SelectKeyCount {
SelectKeyCount(SelectKeyCountQuery(QueryIds::Id(0.into())))
}
Expand Down
30 changes: 30 additions & 0 deletions src/agdb/query_builder/select_keys.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use super::select_keys_from::SelectKeysFrom;
use crate::query::query_id::QueryId;
use crate::query::query_ids::QueryIds;
use crate::query::search_query::SearchQuery;
use crate::query::select_keys_query::SelectKeysQuery;

pub struct SelectKeys(pub SelectKeysQuery);

impl SelectKeys {
#[allow(clippy::wrong_self_convention)]
pub fn from(mut self, id: QueryId) -> SelectKeysFrom {
self.0 .0 = QueryIds::Id(id);

SelectKeysFrom(self.0)
}

#[allow(clippy::wrong_self_convention)]
pub fn from_ids(mut self, ids: &[QueryId]) -> SelectKeysFrom {
self.0 .0 = QueryIds::Ids(ids.to_vec());

SelectKeysFrom(self.0)
}

#[allow(clippy::wrong_self_convention)]
pub fn from_query(mut self, query: SearchQuery) -> SelectKeysFrom {
self.0 .0 = QueryIds::Search(query);

SelectKeysFrom(self.0)
}
}
9 changes: 9 additions & 0 deletions src/agdb/query_builder/select_keys_from.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
use crate::query::select_keys_query::SelectKeysQuery;

pub struct SelectKeysFrom(pub SelectKeysQuery);

impl SelectKeysFrom {
pub fn query(self) -> SelectKeysQuery {
self.0
}
}
22 changes: 22 additions & 0 deletions tests/select_keys.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
use agdb::QueryBuilder;

#[test]
fn select_keys_from() {
let _query = QueryBuilder::select().keys().from("alias".into()).query();
}

#[test]
fn select_keys_from_ids() {
let _query = QueryBuilder::select()
.keys()
.from_ids(&["alias".into()])
.query();
}

#[test]
fn select_keys_from_query() {
let _query = QueryBuilder::select()
.keys()
.from_query(QueryBuilder::select().id().from("alias".into()).query())
.query();
}

0 comments on commit c4510fb

Please sign in to comment.