You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/python-api.rst
+20-5Lines changed: 20 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -251,21 +251,36 @@ In this example ``next()`` is used to retrieve the first result in the iterator
251
251
Accessing tables
252
252
================
253
253
254
-
Tables are accessed using the indexing operator, like so:
254
+
Tables are accessed using the ``db.table()`` method, like so:
255
+
256
+
.. code-block:: python
257
+
258
+
table = db.table("my_table")
259
+
260
+
Using this factory function allows you to set :ref:`python_api_table_configuration`. Additional keyword arguments to ``db.table()`` will be used if a further method call causes the table to be created.
261
+
262
+
The ``db.table()`` method will always return a :ref:`reference_db_table` instance, or raise a ``sqlite_utils.db.NoTable`` exception if the table name is actually a SQL view.
263
+
264
+
You can also access tables or views using dictionary-style syntax, like this:
255
265
256
266
.. code-block:: python
257
267
258
268
table = db["my_table"]
259
269
260
-
If the table does not yet exist, it will be created the first time you attempt to insert or upsert data into it.
270
+
If a table accessed using either of these methods does not yet exist, it will be created the first time you attempt to insert or upsert data into it.
271
+
272
+
.. _python_api_view:
261
273
262
-
You can also access tables using the ``.table()`` method like so:
274
+
Accessing views
275
+
===============
276
+
277
+
SQL views can be accessed using the ``db.view()`` method, like so:
263
278
264
279
.. code-block:: python
265
280
266
-
table= db.table("my_table")
281
+
view= db.view("my_view")
267
282
268
-
Using this factory function allows you to set :ref:`python_api_table_configuration`.
283
+
This will return a :ref:`reference_db_view` instance, or raise a ``sqlite_utils.db.NoView`` exception if the view does not exist.
0 commit comments