From 9fdf2c169caf544d56f6317afbed6879082be8b9 Mon Sep 17 00:00:00 2001 From: Simon Willison Date: Sun, 12 Aug 2018 17:31:02 -0700 Subject: [PATCH] Documented Database(filepath) and in-memory database creation --- docs/python-api.rst | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/python-api.rst b/docs/python-api.rst index 5f487e1..eadc942 100644 --- a/docs/python-api.rst +++ b/docs/python-api.rst @@ -2,15 +2,31 @@ Python API ============ -Database objects are constructed by passing in a SQLite3 database connection: +Connecting to or creating a database +==================================== + +Database objects are constructed by passing in either a path to a file on disk or an existing SQLite3 database connection: .. code-block:: python from sqlite_utils import Database + + db = Database("my_database.py") + +This will create ``my_database.py`` if it does not already exist. You can also pass in an existing SQLite connection: + +.. code-block:: python + import sqlite3 db = Database(sqlite3.connect("my_database.db")) +If you want to create an in-memory database, you con do so like this: + +.. code-block:: python + + db = Database(sqlite3.connect(":memory:")) + Tables are accessed using the indexing operator, like so: .. code-block:: python