Skip to content

Commit

Permalink
Documented Database(filepath) and in-memory database creation
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Willison committed Aug 13, 2018
1 parent fcc38b9 commit 9fdf2c1
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion docs/python-api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 9fdf2c1

Please sign in to comment.