pub struct Query(/* private fields */);
Expand description
A Firestore query.
https://firebase.google.com/docs/firestore/reference/rpc/google.firestore.v1#structuredquery
§Examples
use firestore_structured_query::{FieldPath, Filter, Query};
use googleapis_tonic_google_firestore_v1::google::firestore::v1::{
structured_query, value::ValueType, ArrayValue, Cursor, StructuredQuery, Value,
};
let _ = StructuredQuery::from(
// or Query::collection_group(...)
Query::collection("collection_id1")
.select([FieldPath::raw("field1"), FieldPath::raw("field2")])
.r#where(Filter::and([
// field filters
FieldPath::raw("field1").less_than(Value { value_type: Some(ValueType::IntegerValue(1)) })?,
FieldPath::raw("field2").less_than_or_equal(Value { value_type: Some(ValueType::IntegerValue(2)) })?,
FieldPath::raw("field3").greater_than(Value { value_type: Some(ValueType::IntegerValue(3)) })?,
FieldPath::raw("field4").greater_than_or_equal(Value { value_type: Some(ValueType::IntegerValue(4)) })?,
FieldPath::raw("field5").equal(Value { value_type: Some(ValueType::IntegerValue(5)) })?,
FieldPath::raw("field6").not_equal(Value { value_type: Some(ValueType::IntegerValue(6)) })?,
FieldPath::raw("field7").array_contains(Value { value_type: Some(ValueType::IntegerValue(7)) })?,
FieldPath::raw("field8").r#in(Value { value_type: Some(ValueType::ArrayValue(ArrayValue { values: vec![Value { value_type: Some(ValueType::IntegerValue(8)) }] })) })?,
FieldPath::raw("field9").array_contains_any(Value { value_type: Some(ValueType::ArrayValue(ArrayValue { values: vec![Value { value_type: Some(ValueType::IntegerValue(9)) }] })) })?,
FieldPath::raw("field10").not_in(Value { value_type: Some(ValueType::ArrayValue(ArrayValue { values: vec![Value { value_type: Some(ValueType::IntegerValue(10)) }] })) })?,
// unary filters
FieldPath::raw("field11").is_nan()?,
FieldPath::raw("field12").is_not_nan()?,
FieldPath::raw("field13").is_not_null()?,
FieldPath::raw("field14").is_null()?,
// composite filters
Filter::and([
FieldPath::raw("f").equal(Value { value_type: Some(ValueType::StringValue("a".to_string())) })?,
FieldPath::raw("f").equal(Value { value_type: Some(ValueType::StringValue("b".to_string())) })?,
]),
Filter::or([
FieldPath::raw("f").equal(Value { value_type: Some(ValueType::StringValue("a".to_string())) })?,
FieldPath::raw("f").equal(Value { value_type: Some(ValueType::StringValue("b".to_string())) })?,
]),
]))
.order_by([
FieldPath::raw("field1").ascending(),
FieldPath::raw("field2").descending(),
])
// .start_after(...)
.start_at([
Value { value_type: Some(ValueType::IntegerValue(1))},
Value { value_type: Some(ValueType::IntegerValue(2))},
])
// .end_before(...)
.end_at([
Value { value_type: Some(ValueType::IntegerValue(1))},
Value { value_type: Some(ValueType::IntegerValue(2))},
])
.offset(1_i32)
.limit(2_i32),
);
Implementations§
Source§impl Query
impl Query
Sourcepub fn collection<S>(collection_id: S) -> Self
pub fn collection<S>(collection_id: S) -> Self
Creates a new Query
for a collection.
The query that internally holds a CollectionSelector
with all_descendants
set to false
.
§Examples
use firestore_structured_query::Query;
use googleapis_tonic_google_firestore_v1::google::firestore::v1::{structured_query, StructuredQuery};
let query1 = Query::collection("collection_id1");
assert_eq!(
StructuredQuery::from(query1),
StructuredQuery {
select: None,
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: false,
}],
r#where: None,
order_by: vec![],
start_at: None,
end_at: None,
offset: 0_i32,
limit: None,
find_nearest: None,
}
);
Sourcepub fn collection_group<S>(collection_id: S) -> Self
pub fn collection_group<S>(collection_id: S) -> Self
Creates a new Query
for a collection group.
The query that internally holds a CollectionSelector
with all_descendants
set to true
.
§Examples
use firestore_structured_query::Query;
use googleapis_tonic_google_firestore_v1::google::firestore::v1::{structured_query, StructuredQuery};
let query1 = Query::collection_group("collection_id1");
assert_eq!(
StructuredQuery::from(query1),
StructuredQuery {
select: None,
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: true,
}],
r#where: None,
order_by: vec![],
start_at: None,
end_at: None,
offset: 0_i32,
limit: None,
find_nearest: None,
}
);
Sourcepub fn end_at<I>(self, values: I) -> Selfwhere
I: IntoIterator<Item = Value>,
pub fn end_at<I>(self, values: I) -> Selfwhere
I: IntoIterator<Item = Value>,
Sets the specified value to end_at and returns the Query.
https://firebase.google.com/docs/firestore/reference/rpc/google.firestore.v1#google.firestore.v1.StructuredQuery.FIELDS.google.firestore.v1.Cursor.google.firestore.v1.StructuredQuery.end_at https://firebase.google.com/docs/firestore/reference/rpc/google.firestore.v1#google.firestore.v1.Cursor
§Examples
use firestore_structured_query::Query;
use googleapis_tonic_google_firestore_v1::google::firestore::v1::{
structured_query, value::ValueType, Cursor, StructuredQuery, Value,
};
let query1 = Query::collection_group("collection_id1").end_at([
Value {
value_type: Some(ValueType::IntegerValue(1)),
},
Value {
value_type: Some(ValueType::IntegerValue(2)),
},
]);
assert_eq!(
StructuredQuery::from(query1),
StructuredQuery {
select: None,
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: true,
}],
r#where: None,
order_by: vec![],
start_at: None,
end_at: Some(Cursor {
values: vec![
Value {
value_type: Some(ValueType::IntegerValue(1)),
},
Value {
value_type: Some(ValueType::IntegerValue(2)),
},
],
before: false,
}),
offset: 0_i32,
limit: None,
find_nearest: None,
}
);
Sourcepub fn end_before<I>(self, values: I) -> Selfwhere
I: IntoIterator<Item = Value>,
pub fn end_before<I>(self, values: I) -> Selfwhere
I: IntoIterator<Item = Value>,
Sets the specified value to end_at and returns the Query.
https://firebase.google.com/docs/firestore/reference/rpc/google.firestore.v1#google.firestore.v1.StructuredQuery.FIELDS.google.firestore.v1.Cursor.google.firestore.v1.StructuredQuery.end_at https://firebase.google.com/docs/firestore/reference/rpc/google.firestore.v1#google.firestore.v1.Cursor
§Examples
use firestore_structured_query::Query;
use googleapis_tonic_google_firestore_v1::google::firestore::v1::{
structured_query, value::ValueType, Cursor, StructuredQuery, Value,
};
let query1 = Query::collection_group("collection_id1").end_before([
Value {
value_type: Some(ValueType::IntegerValue(1)),
},
Value {
value_type: Some(ValueType::IntegerValue(2)),
},
]);
assert_eq!(
StructuredQuery::from(query1),
StructuredQuery {
select: None,
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: true,
}],
r#where: None,
order_by: vec![],
start_at: None,
end_at: Some(Cursor {
values: vec![
Value {
value_type: Some(ValueType::IntegerValue(1)),
},
Value {
value_type: Some(ValueType::IntegerValue(2)),
},
],
before: true,
}),
offset: 0_i32,
limit: None,
find_nearest: None,
}
);
Sourcepub fn limit(self, limit: i32) -> Self
pub fn limit(self, limit: i32) -> Self
Sets the specified value to limit and returns the Query.
§Examples
use firestore_structured_query::Query;
use googleapis_tonic_google_firestore_v1::google::firestore::v1::{structured_query, StructuredQuery};
let query1 = Query::collection_group("collection_id1").limit(1_i32);
assert_eq!(
StructuredQuery::from(query1),
StructuredQuery {
select: None,
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: true,
}],
r#where: None,
order_by: vec![],
start_at: None,
end_at: None,
offset: 0_i32,
limit: Some(1_i32),
find_nearest: None,
}
);
Sourcepub fn offset(self, offset: i32) -> Self
pub fn offset(self, offset: i32) -> Self
Sets the specified value to offset and returns the Query.
§Examples
use firestore_structured_query::Query;
use googleapis_tonic_google_firestore_v1::google::firestore::v1::{structured_query, StructuredQuery};
let query1 = Query::collection_group("collection_id1").offset(1_i32);
assert_eq!(
StructuredQuery::from(query1),
StructuredQuery {
select: None,
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: true,
}],
r#where: None,
order_by: vec![],
start_at: None,
end_at: None,
offset: 1_i32,
limit: None,
find_nearest: None,
}
);
Sourcepub fn order_by<I>(self, order_by: I) -> Self
pub fn order_by<I>(self, order_by: I) -> Self
Sets the specified value to order_by and returns the Query.
§Examples
use firestore_structured_query::{FieldPath, Query};
use googleapis_tonic_google_firestore_v1::google::firestore::v1::{structured_query, StructuredQuery};
let query1 = Query::collection_group("collection_id1").order_by([
FieldPath::raw("field1").ascending(),
FieldPath::raw("field2").descending(),
]);
assert_eq!(
StructuredQuery::from(query1),
StructuredQuery {
select: None,
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: true,
}],
r#where: None,
order_by: vec![
structured_query::Order::from(FieldPath::raw("field1").ascending()),
structured_query::Order::from(FieldPath::raw("field2").descending()),
],
start_at: None,
end_at: None,
offset: 0_i32,
limit: None,
find_nearest: None,
}
);
let order_by1 = vec![
structured_query::Order {
field: Some(structured_query::FieldReference {
field_path: "field1".to_string(),
}),
direction: structured_query::Direction::Ascending as i32,
},
structured_query::Order {
field: Some(structured_query::FieldReference {
field_path: "field2".to_string(),
}),
direction: structured_query::Direction::Descending as i32,
},
];
let query2 = Query::collection_group("collection_id1").order_by(order_by1.clone());
assert_eq!(
StructuredQuery::from(query2),
StructuredQuery {
select: None,
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: true,
}],
r#where: None,
order_by: order_by1,
start_at: None,
end_at: None,
offset: 0_i32,
limit: None,
find_nearest: None,
}
);
Sourcepub fn select<I>(self, fields: I) -> Self
pub fn select<I>(self, fields: I) -> Self
Sets the specified value to select and returns the Query.
§Examples
use firestore_structured_query::{FieldPath, Query};
use googleapis_tonic_google_firestore_v1::google::firestore::v1::{structured_query, StructuredQuery};
let query1 = Query::collection_group("collection_id1")
.select([FieldPath::raw("field1"), FieldPath::raw("field2")]);
assert_eq!(
StructuredQuery::from(query1),
StructuredQuery {
select: Some(structured_query::Projection {
fields: vec![
structured_query::FieldReference {
field_path: "field1".to_string(),
},
structured_query::FieldReference {
field_path: "field2".to_string(),
},
],
}),
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: true,
}],
r#where: None,
order_by: vec![],
start_at: None,
end_at: None,
offset: 0_i32,
limit: None,
find_nearest: None,
}
);
Sourcepub fn start_after<I>(self, values: I) -> Selfwhere
I: IntoIterator<Item = Value>,
pub fn start_after<I>(self, values: I) -> Selfwhere
I: IntoIterator<Item = Value>,
Sets the specified value to start_at and returns the Query.
§Examples
use firestore_structured_query::Query;
use googleapis_tonic_google_firestore_v1::google::firestore::v1::{
structured_query, value::ValueType, Cursor, StructuredQuery, Value,
};
let query1 = Query::collection_group("collection_id1").start_after([
Value {
value_type: Some(ValueType::IntegerValue(1)),
},
Value {
value_type: Some(ValueType::IntegerValue(2)),
},
]);
assert_eq!(
StructuredQuery::from(query1),
StructuredQuery {
select: None,
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: true,
}],
r#where: None,
order_by: vec![],
start_at: Some(Cursor {
values: vec![
Value {
value_type: Some(ValueType::IntegerValue(1)),
},
Value {
value_type: Some(ValueType::IntegerValue(2)),
},
],
before: false,
}),
end_at: None,
offset: 0_i32,
limit: None,
find_nearest: None,
}
);
Sourcepub fn start_at<I>(self, values: I) -> Selfwhere
I: IntoIterator<Item = Value>,
pub fn start_at<I>(self, values: I) -> Selfwhere
I: IntoIterator<Item = Value>,
Sets the specified value to start_at and returns the Query.
§Examples
use firestore_structured_query::Query;
use googleapis_tonic_google_firestore_v1::google::firestore::v1::{
structured_query, value::ValueType, Cursor, StructuredQuery, Value,
};
let query1 = Query::collection_group("collection_id1").start_at([
Value {
value_type: Some(ValueType::IntegerValue(1)),
},
Value {
value_type: Some(ValueType::IntegerValue(2)),
},
]);
assert_eq!(
StructuredQuery::from(query1),
StructuredQuery {
select: None,
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: true,
}],
r#where: None,
order_by: vec![],
start_at: Some(Cursor {
values: vec![
Value {
value_type: Some(ValueType::IntegerValue(1)),
},
Value {
value_type: Some(ValueType::IntegerValue(2)),
},
],
before: true,
}),
end_at: None,
offset: 0_i32,
limit: None,
find_nearest: None,
}
);
Sourcepub fn where<F>(self, filter: F) -> Self
pub fn where<F>(self, filter: F) -> Self
Sets the specified value to where and returns the Query.
§Examples
use firestore_structured_query::{FieldPath, Query};
use googleapis_tonic_google_firestore_v1::google::firestore::v1::{structured_query, StructuredQuery};
let query1 =
Query::collection_group("collection_id1").r#where(FieldPath::raw("field1").is_nan()?);
assert_eq!(
StructuredQuery::from(query1),
StructuredQuery {
select: None,
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: true,
}],
r#where: Some(structured_query::Filter {
filter_type: Some(structured_query::filter::FilterType::UnaryFilter(
structured_query::UnaryFilter {
op: structured_query::unary_filter::Operator::IsNan as i32,
operand_type: Some(structured_query::unary_filter::OperandType::Field(
structured_query::FieldReference {
field_path: "field1".to_string(),
}
))
}
))
}),
order_by: vec![],
start_at: None,
end_at: None,
offset: 0_i32,
limit: None,
find_nearest: None,
}
);
let filter1 = structured_query::Filter {
filter_type: Some(structured_query::filter::FilterType::UnaryFilter(
structured_query::UnaryFilter {
op: structured_query::unary_filter::Operator::IsNan as i32,
operand_type: Some(structured_query::unary_filter::OperandType::Field(
structured_query::FieldReference {
field_path: "field1".to_string(),
},
)),
},
)),
};
let query2 = Query::collection_group("collection_id1").r#where(filter1.clone());
assert_eq!(
StructuredQuery::from(query2),
StructuredQuery {
select: None,
from: vec![structured_query::CollectionSelector {
collection_id: "collection_id1".to_string(),
all_descendants: true,
}],
r#where: Some(filter1),
order_by: vec![],
start_at: None,
end_at: None,
offset: 0_i32,
limit: None,
find_nearest: None,
}
);
Trait Implementations§
Source§impl From<Query> for StructuredQuery
impl From<Query> for StructuredQuery
impl StructuralPartialEq for Query
Auto Trait Implementations§
impl Freeze for Query
impl RefUnwindSafe for Query
impl Send for Query
impl Sync for Query
impl Unpin for Query
impl UnwindSafe for Query
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T
in a tonic::Request