mirror of
https://github.com/simonw/sqlite-utils.git
synced 2026-07-23 01:14:31 +02:00
Documented Database(filepath) and in-memory database creation
This commit is contained in:
parent
fcc38b9ff2
commit
9fdf2c169c
1 changed files with 17 additions and 1 deletions
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue