@@ -247,6 +247,70 @@ class {{ model.name }}Actions(Generic[{{ ModelType }}]):
247
247
)
248
248
return int(resp['data']['result']['count'])
249
249
250
+ {{ maybe_async_def }}create_many_and_return(
251
+ self,
252
+ data: List[types.{{ model.name }}CreateWithoutRelationsInput],
253
+ *,
254
+ skip_duplicates: Optional[bool] = None,
255
+ ) -> List[{{ ModelType }}]:
256
+ """Create multiple {{ model.name }} records at once.
257
+
258
+ The `skip_duplicates` argument is not supported when using SQLite, MongoDB or SQLServer
259
+
260
+ Parameters
261
+ ----------
262
+ data
263
+ List of {{ model.name }} record data
264
+ skip_duplicates
265
+ Boolean flag for ignoring unique constraint errors
266
+
267
+ Returns
268
+ -------
269
+ List[{{ RawModelType }}]
270
+ The list of all {{ model.name }} records that could be found
271
+
272
+ Raises
273
+ ------
274
+ prisma.errors.UnsupportedDatabaseError
275
+ Attempting to query when using SQLite
276
+ prisma.errors.UniqueViolationError
277
+ A unique constraint check has failed, these can be ignored with the `skip_duplicates` argument
278
+ {{ query_error_doc }}
279
+ {{ base_error_doc }}
280
+
281
+ Example
282
+ -------
283
+ ```py
284
+ records = {{ maybe_await }}{{ model.name }}.prisma().create_many_and_return(
285
+ data=[
286
+ {% for _ in range (2) %}
287
+ {
288
+ # data to create a {{ model.name }} record
289
+ {% for field in model .scalar_fields %}
290
+ {% if field .required_on_create %}
291
+ '{{ field.name }}': {{ field.get_sample_data() }},
292
+ {% endif %}
293
+ {% endfor %}
294
+ },
295
+ {% endfor %}
296
+ ],
297
+ skip_duplicates=True,
298
+ )
299
+ ```
300
+ """
301
+ if skip_duplicates and self._client._active_provider in CREATE_MANY_SKIP_DUPLICATES_UNSUPPORTED:
302
+ raise errors.UnsupportedDatabaseError(self._client._active_provider, 'create_many_skip_duplicates')
303
+
304
+ resp = {{ maybe_await }}self._client._execute(
305
+ method='create_many_and_return',
306
+ model=self._model,
307
+ arguments={
308
+ 'data': data,
309
+ 'skipDuplicates': skip_duplicates,
310
+ },
311
+ )
312
+ return [model_parse(self._model, r) for r in resp['data']['result']]
313
+
250
314
{{ maybe_async_def }}delete(
251
315
self,
252
316
where: types.{{ model.name }}WhereUniqueInput,
0 commit comments