Skip to content

Commit 5827f29

Browse files
committed
feat(dart): saveObjectsMCM (+ local vars)
1 parent 4ef711a commit 5827f29

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{{> snippets/import}}
2+
3+
List<Map<String, String>> getAllAppIDConfigurations() {
4+
return [/* A list of your MCM AppID/ApiKey pairs */];
5+
}
6+
7+
List<Map> playlists = [/* Your records */];
8+
9+
void saveObjectsMCM() async {
10+
var configurations = getAllAppIDConfigurations();
11+
12+
for (var configuration in configurations) {
13+
var appId = configuration['appID'] ?? "";
14+
var apiKey = configuration['apiKey'] ?? "";
15+
var client = SearchClient(appId: appId, apiKey: apiKey);
16+
17+
try {
18+
var batchParams = BatchWriteParams(
19+
requests: playlists
20+
.map((record) => BatchRequest(
21+
action: Action.addObject,
22+
body: record,
23+
)).toList()
24+
);
25+
await {{#dynamicSnippet}}batchChunks{{/dynamicSnippet}};
26+
} catch (e) {
27+
throw Exception('Error for appID $appId: $e');
28+
}
29+
}
30+
}

templates/kotlin/guides/search/saveObjectsMCM.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
{{> snippets/import}}
22
import com.algolia.client.model.search.*
33

4+
val getAllAppIDConfigurations: () -> Map<String, String> = {
5+
mapOf() // A map of your MCM AppID/ApiKey pairs
6+
}
7+
8+
val playlists: List<JsonObject> = listOf() // Your records
9+
410
suspend fun saveObjectsMCM() {
511
val configurations = getAllAppIDConfigurations()
612

templates/scala/guides/search/saveObjectsMCM.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ import scala.concurrent.ExecutionContext.Implicits.global
44
{{> snippets/import}}
55
import algoliasearch.config.RequestOptions
66

7+
val getAllAppIDConfigurations: () => Map[String, String] = () => {
8+
Map(/* A map of your MCM AppID/ApiKey pairs */)
9+
}
10+
11+
val playlists: List[Any] = List(/* Your records */)
12+
713
def saveObjectsMCM(): Future[Unit] = {
814
val configurations = getAllAppIDConfigurations()
915

templates/swift/guides/search/saveObjectsMCM.mustache

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@ import Foundation
66
import Core
77
{{> snippets/import}}
88

9+
let getAllAppIDConfigurations: () -> [(String, String)] = {
10+
return [/* A list of your MCM AppID/ApiKey pairs */]
11+
}
12+
13+
let playlists: [[String: AnyCodable]] = [/* Your records */]
14+
915
func saveObjectsMCM() async throws {
1016
// Fetch from your own data storage and with your own code
1117
// the list of application IDs and API keys to target each cluster

0 commit comments

Comments
 (0)