File tree Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Expand file tree Collapse file tree 1 file changed +20
-3
lines changed Original file line number Diff line number Diff line change @@ -236,11 +236,28 @@ same time, using a :class:`~gino.loader.TupleLoader` with two sub-loaders -
236236Be ware of the :class: `tuple ` in ``.gino.load((...)) ``.
237237
238238
239- How to do bulk insert / update?
240- -------------------------------
241239
242- TBD #314
240+ How to do bulk or batch insert / update?
241+ -----------------------------------------
242+
243+ For a simple example, take a model that has one field, "name." In your application you have a list of names you would like to add to the database:
244+
245+ ::
246+
247+ new_names = ["Austin", "Ali", "Jeff", "Marissa"]
248+
249+ To quickly insert the names in one query, first construct a dict with the ``{"model_key": "value"} `` format.
250+
251+ ::
252+
253+ new_names_dict = [dict(name=new_name) for new_name in new_names]
254+ >> [{'name': 'Austin'}, {'name': 'Ali'}, {'name': 'Jeff'}, {'name': 'Marissa'}]
255+
256+ Finally, run an insert statement on the model.
257+
258+ ::
243259
260+ await User.insert().gino.all(new_names_dict)
244261
245262How to print the executed SQL?
246263------------------------------
You can’t perform that action at this time.
0 commit comments