Skip to content

Commit

Permalink
Feature: Where conditions for firestore queries
Browse files Browse the repository at this point in the history
  • Loading branch information
Navaneeth-pk committed Apr 28, 2021
1 parent 5ef1e4a commit e5a0a80
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
7 changes: 7 additions & 0 deletions app/services/firestore_query_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,13 @@ def process
if operation == 'query_collection'
path = options["path"]
doc_ref = firestore.col path

# execute where condition

if options["where_field"]
doc_ref = doc_ref.where options["where_field"], options["where_operation"], options["where_value"]
end

data = []
doc_ref.get do |doc|
data << { data: doc.data, document_id: doc.document_id}
Expand Down
8 changes: 6 additions & 2 deletions frontend/src/Editor/QueryManager/Firestore.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ class Firestore extends React.Component {
className="form-control"
/>
</div>
<div className="row">
<hr/>
<div className="row">
<h3 className="text-muted">Where condition</h3>
<div class="col">
<label className="form-label">Field</label>
<input
Expand All @@ -180,11 +182,13 @@ class Firestore extends React.Component {
<div className="col">
<label className="form-label">Operator</label>
<select
onChange={(e) => { e.stopPropagation(); this.changeOption('where_operation')}}
onChange={(e) => { e.stopPropagation(); this.changeOption('where_operation', e.target.value)}}
placeholder="Select a value"
value={this.state.options.where_operation}
class="form-select">
<option value="==">==</option>
<option value="<">{'<'}</option>
<option value="<">{'>'}</option>
<option value="<=">{'<='}</option>
<option value=">=">{'>='}</option>
<option value="array-contains">{'array-contains'}</option>
Expand Down

0 comments on commit e5a0a80

Please sign in to comment.