From 26b2cf3418f1e19b5436a7385c3945384838e594 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Tue, 28 May 2019 22:06:22 -0700 Subject: [PATCH] Changelog for 1.1 + docs for --ignore/ignore=True --- docs/changelog.rst | 7 +++++++ docs/cli.rst | 4 ++++ docs/python-api.rst | 4 ++++ 3 files changed, 15 insertions(+) diff --git a/docs/changelog.rst b/docs/changelog.rst index c8ae8ab9e..0e5322456 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -2,6 +2,13 @@ Changelog =========== +.. _v1_1: + +1.1 (2019-05-28) +---------------- + +- Support for ``ignore=True`` / ``--ignore`` for ignoring inserted records if the primary key alread exists (`#21 `__) - documentation: :ref:`Inserting data (Python API) `, :ref:`Inserting data (CLI) ` +- Ability to add a column that is a foreign key reference using ``fk=...`` / ``--fk`` (`#16 `__) - documentation: :ref:`Adding columns (Python API) `, :ref:`Adding columns (CLI) ` .. _v1_0_1: diff --git a/docs/cli.rst b/docs/cli.rst index 89459203b..4ef658438 100644 --- a/docs/cli.rst +++ b/docs/cli.rst @@ -224,6 +224,10 @@ You can import all three records into an automatically created ``dogs`` table an $ sqlite-utils insert dogs.db dogs dogs.json --pk=id +You can skip inserting any records that have a primary key that already exists using ``--ignore``:: + + $ sqlite-utils insert dogs.db dogs dogs.json --ignore + You can also import newline-delimited JSON using the ``--nl`` option. Since `Datasette `__ can export newline-delimited JSON, you can combine the two tools like so:: $ curl -L "https://latest.datasette.io/fixtures/facetable.json?_shape=array&_nl=on" \ diff --git a/docs/python-api.rst b/docs/python-api.rst index 90cc15994..331a84e38 100644 --- a/docs/python-api.rst +++ b/docs/python-api.rst @@ -164,6 +164,8 @@ The ``foreign_keys`` argument takes a sequence of three-tuples, each one specify ("author_id", "authors", "id") ]) +.. _python_api_bulk_inserts: + Bulk inserts ============ @@ -198,6 +200,8 @@ The function can accept an iterator or generator of rows and will commit them ac "name": "Name {}".format(i), } for i in range(10000)), batch_size=1000) +You can skip inserting any records that have a primary key that already exists using ``ignore=True``. This works with both ``.insert({...}, ignore=True)`` and ``.insert_all([...], ignore=True)``. + Upserting data ==============