File tree Expand file tree Collapse file tree 6 files changed +39
-2
lines changed Expand file tree Collapse file tree 6 files changed +39
-2
lines changed Original file line number Diff line number Diff line change 1+ { {> snippets/import} }
2+
3+ final playlists = []; // Your records
4+
5+ void setHeaderUserIDThenSaveObjects() async {
6+ {{> snippets/init} }
7+
8+ for (final playlist in playlists) {
9+ final playlistUserID = playlist[" userID" ];
10+ final batchParams = BatchWriteParams(
11+ requests: playlists
12+ .map((record) => BatchRequest(
13+ action: Action.addObject,
14+ body: record,
15+ ))
16+ .toList());
17+ await {{#dynamicSnippet} }batchChunksWithRequestOptions{ {/dynamicSnippet} };
18+ }
19+ }
Original file line number Diff line number Diff line change @@ -7,7 +7,7 @@ client.{{method}}(
77 { {#requestOptions.headers} }
88 headers: {
99 {{#parametersWithDataType} }
10- '{ {{key} }}' : ' { {value } }' ,
10+ '{ {{key} }}' : { { > tests/param_value } } ,
1111 { {/parametersWithDataType} }
1212 },
1313 { {/requestOptions.headers} }
Original file line number Diff line number Diff line change 11{ {> snippets/import} }
22import com.algolia.client.model.search.*
33
4+ val playlists: List<Map <String, Any >> = listOf() // Your records
5+
46suspend fun setHeaderUserIDThenSaveObjects() {
57 {{> snippets/init} }
68
Original file line number Diff line number Diff line change @@ -5,6 +5,8 @@ import scala.concurrent.duration.Duration
55
66{ {> snippets/import} }
77
8+ val playlists: Seq[Any] = Seq() // Your records
9+
810def setHeaderUserIDThenSaveObjects(): Future[Unit] = {
911 {{> snippets/init} }
1012
Original file line number Diff line number Diff line change @@ -6,12 +6,14 @@ import Foundation
66import Core
77{ {> snippets/import} }
88
9+ let playlists: [[String: AnyCodable]] = [/* Your records */]
10+
911func setHeaderUserIDThenSaveObjects() async throws {
1012 do {
1113 {{> snippets/init} }
1214
1315 for playlist in playlists {
14- let playlistUserID = playlist. userID
16+ let playlistUserID = playlist[ " userID" ]?.value as ! String
1517 {{#dynamicSnippet} }saveObjectsPlaylistsWithRequestOptions{ {/dynamicSnippet} }
1618 }
1719 } catch {
Original file line number Diff line number Diff line change 9292 }
9393 }
9494 },
95+ "batchChunksWithRequestOptions" : {
96+ "method" : " batch" ,
97+ "parameters" : {
98+ "indexName" : " indexName" ,
99+ "batchWriteParams" : " $var: batchParams"
100+ },
101+ "requestOptions" : {
102+ "headers" : {
103+ "X-Algolia-User-ID" : " $var: playlistUserID"
104+ }
105+ }
106+ },
95107 "setSettings" : {
96108 "method" : " setSettings" ,
97109 "parameters" : {
You can’t perform that action at this time.
0 commit comments