Skip to content

Commit

Permalink
feat: setIndexConfigurationFromJSON() API. Allow users to pass JSON…
Browse files Browse the repository at this point in the history
… string (#10029)

* feat: `setIndexConfigurationFromJSON()` API

* analyse issue
  • Loading branch information
russellwheatley committed Dec 7, 2022
1 parent 3f5ca80 commit be4b42b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:convert';

import 'package:flutter/foundation.dart';
import 'package:flutter_test/flutter_test.dart';
Expand Down Expand Up @@ -229,6 +230,30 @@ void runInstanceTests() {
fieldOverrides: [fieldOverride1, fieldOverride2],
);
});

test('setIndexConfigurationFromJSON()', () async {
final json = jsonEncode({
'indexes': [
{
'collectionGroup': 'posts',
'queryScope': 'COLLECTION',
'fields': [
{'fieldPath': 'author', 'arrayConfig': 'CONTAINS'},
{'fieldPath': 'timestamp', 'order': 'DESCENDING'}
]
}
],
'fieldOverrides': [
{
'collectionGroup': 'posts',
'fieldPath': 'myBigMapField',
'indexes': []
}
]
});

await firestore.setIndexConfigurationFromJSON(json);
});
},
);
}
14 changes: 14 additions & 0 deletions packages/cloud_firestore/cloud_firestore/lib/src/firestore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,20 @@ class FirebaseFirestore extends FirebasePluginPlatform {
return _delegate.setIndexConfiguration(json);
}

/// Configures indexing for local query execution. Any previous index configuration is overridden.
///
/// The index entries themselves are created asynchronously. You can continue to use queries that
/// require indexing even if the indices are not yet available. Query execution will automatically
/// start using the index once the index entries have been written.
/// See Firebase documentation to learn how to configure your index configuration JSON file:
/// https://firebase.google.com/docs/reference/firestore/indexes
///
/// This API is in preview mode and is subject to change.
@experimental
Future<void> setIndexConfigurationFromJSON(String json) async {
return _delegate.setIndexConfiguration(json);
}

@override
// ignore: avoid_equals_and_hash_code_on_mutable_classes
bool operator ==(Object other) =>
Expand Down

0 comments on commit be4b42b

Please sign in to comment.