Skip to content

Commit ecabd9e

Browse files
committed
Documentation for new list/tuple mode
Refs #672
1 parent 7399ae4 commit ecabd9e

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

docs/python-api.rst

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,35 @@ You can delete all the existing rows in the table before inserting the new recor
810810

811811
Pass ``analyze=True`` to run ``ANALYZE`` against the table after inserting the new records.
812812

813+
.. _python_api_insert_lists:
814+
815+
Inserting data from a list or tuple iterator
816+
--------------------------------------------
817+
818+
As an alternative to passing an iterator of dictionaries, you can pass an iterator of lists or tuples. The first item yielded by the iterator must be a list or tuple of string column names, and subsequent items should be lists or tuples of values:
819+
820+
.. code-block:: python
821+
822+
db["creatures"].insert_all([
823+
["name", "species"],
824+
["Cleo", "dog"],
825+
["Lila", "chicken"],
826+
["Bants", "chicken"],
827+
])
828+
829+
This also works with generators:
830+
831+
.. code-block:: python
832+
833+
def creatures():
834+
yield "id", "name", "city"
835+
yield 1, "Cleo", "San Francisco"
836+
yield 2, "Lila", "Los Angeles"
837+
838+
db["creatures"].insert_all(creatures())
839+
840+
Tuples and lists are both supported.
841+
813842
.. _python_api_insert_replace:
814843

815844
Insert-replacing data

0 commit comments

Comments
 (0)