Skip to content

Commit

Permalink
Merge pull request #4 from Mansehej/dev
Browse files Browse the repository at this point in the history
feat: Add support for collection group queries
  • Loading branch information
Mansehej committed Oct 18, 2021
2 parents 136daf9 + 1ad7b35 commit 4a4b4db
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
12 changes: 7 additions & 5 deletions index.js
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ async function run() {
var queryDetails = await askQueryDetails()
var filePath = await askIndexFilePath()
for (var detail in queryDetails) {
const detailList = queryDetails[detail].split(',')
const whiteSpaceTrimmedList = detailList.map(element => element.trim())
const nonEmptyValueList = whiteSpaceTrimmedList.filter(element => element.length > 0)
const multipleWordParsedList = nonEmptyValueList.map(element => element.split(' ').length > 1 ? addBackticksToString(element) : element)
queryDetails[detail] = multipleWordParsedList
if (typeof queryDetails[detail] === "string") {
const detailList = queryDetails[detail].split(',')
const whiteSpaceTrimmedList = detailList.map(element => element.trim())
const nonEmptyValueList = whiteSpaceTrimmedList.filter(element => element.length > 0)
const multipleWordParsedList = nonEmptyValueList.map(element => element.split(' ').length > 1 ? addBackticksToString(element) : element)
queryDetails[detail] = multipleWordParsedList
}
}
const compositeIndexes = getCompositeIndexes(queryDetails)
if (!indexFileExists(filePath.path)) {
Expand Down
5 changes: 3 additions & 2 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {

const sortFields = queryDetails.sortFields
const filterFields = queryDetails.filterFields
const isCollectionGroup = queryDetails.isCollectionGroup
const collections = queryDetails.collections

var ascDscCombos = [];
Expand Down Expand Up @@ -63,8 +64,8 @@ module.exports = {

for (let collection of collections) {
outputObject = {
"collectionGroup": collection,
"queryScope": "COLLECTION",
"collection": collection,
"queryScope": isCollectionGroup ? "COLLECTION_GROUP" : "COLLECTION",
"fields": fields
}
finalOutput.push(outputObject)
Expand Down
8 changes: 7 additions & 1 deletion lib/questions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,16 @@ module.exports = {
type: 'input',
message: 'Enter the fields you want to filter or search by (seperated by commas)',
},
{
name: 'isCollectionGroup',
type: 'confirm',
default: false,
message: 'Is this a collectionGroup query? (N for collection query)',
},
{
name: 'collections',
type: 'input',
message: 'Enter the collections you want to generate indexes for (seperated by commas)',
message: 'Enter the collection groups/collections you want to generate indexes for (seperated by commas)',
validate(collectionName) {
if(collectionName.length == 0) {
return 'Atleast one collection must be entered.'
Expand Down
2 changes: 1 addition & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "firestore-cig",
"version": "2.0.0",
"version": "2.1.0",
"description": "A utility to create composite indexes for firestore.",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 4a4b4db

Please sign in to comment.